Skip to content

Commit

Permalink
Use multistage to reduce test image size (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
hmzakhalid authored Nov 28, 2024
1 parent cd5e349 commit 7258206
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
22 changes: 18 additions & 4 deletions packages/ciphernode/net/tests/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
FROM rust:1.81
RUN apt-get update && apt-get install -y iptables
# Stage 1: Build
FROM rust:1.81 AS builder

WORKDIR /app
COPY ./net/tests/entrypoint.sh entrypoint.sh
COPY . .
RUN cargo build --bin p2p_test
RUN cargo build --release --bin p2p_test

# Stage 2: Runtime
FROM debian:bookworm-slim

WORKDIR /app

RUN apt-get update && apt-get install -y --no-install-recommends iptables ca-certificates && \
apt-get clean && rm -rf /var/lib/apt/lists/*

COPY --from=builder /app/target/release/p2p_test /app/
COPY net/tests/entrypoint.sh /app/
RUN chmod +x /app/entrypoint.sh

ENTRYPOINT ["/app/entrypoint.sh"]
25 changes: 10 additions & 15 deletions packages/ciphernode/net/tests/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,56 +1,51 @@
services:
alice:
build:
build:
dockerfile: net/tests/Dockerfile
context: ../..
image: p2p-test-image
networks:
app_net:
ipv4_address: 172.16.238.10
command: cargo run --bin p2p_test alice
command: ["/app/p2p_test", "alice"]
environment:
QUIC_PORT: 9091
DIAL_TO: "/ip4/172.16.238.12/udp/9091/quic-v1"
BLOCK_MDNS: ${BLOCK_MDNS:-false}
BLOCK_MDNS: "${BLOCK_MDNS:-false}"
entrypoint: ["/app/entrypoint.sh"]
cap_add:
- NET_ADMIN
- NET_RAW

bob:
build:
dockerfile: net/tests/Dockerfile
context: ../..
image: p2p-test-image
networks:
app_net:
ipv4_address: 172.16.238.11
command: cargo run --bin p2p_test bob
command: ["/app/p2p_test", "bob"]
environment:
QUIC_PORT: 9091
DIAL_TO: "/ip4/172.16.238.12/udp/9091/quic-v1"
BLOCK_MDNS: ${BLOCK_MDNS:-false}
BLOCK_MDNS: "${BLOCK_MDNS:-false}"
entrypoint: ["/app/entrypoint.sh"]
cap_add:
- NET_ADMIN
- NET_RAW


charlie:
build:
dockerfile: net/tests/Dockerfile
context: ../..
image: p2p-test-image
networks:
app_net:
ipv4_address: 172.16.238.12
command: cargo run --bin p2p_test charlie
command: ["/app/p2p_test", "charlie"]
environment:
QUIC_PORT: 9091
BLOCK_MDNS: ${BLOCK_MDNS:-false}
BLOCK_MDNS: "${BLOCK_MDNS:-false}"
entrypoint: ["/app/entrypoint.sh"]
cap_add:
- NET_ADMIN
- NET_RAW


networks:
app_net:
driver: bridge
Expand Down
5 changes: 5 additions & 0 deletions packages/ciphernode/net/tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

set -e

echo ""
echo "Building docker image"
echo ""
docker compose build

echo ""
echo "TEST 1: Using MDNS with separate IP addresses"
echo ""
Expand Down

0 comments on commit 7258206

Please sign in to comment.