From 0a46fdf7b548c4ebd98ddd2531166842e9b3b939 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Thu, 10 Apr 2025 14:00:58 +1000 Subject: [PATCH] chore(rust): remove `dev` stage in Dockerfile (#8688) We don't ever use the `dev` stage within our Rust Dockerfile that actually builds the binaries within the container. In CI, we build the binaries on the host and then copy them in. During local development, I always do the same because it is much faster to iterate that way. Long story short: We don't need this stage within our Dockerfile and it causes confusion when people try to use `docker compose build`. If somebody really wanted to do that, they need to follow the instructions in the Dockerfile and build the binary first. Related: #8687 --------- Signed-off-by: Thomas Eizinger Co-authored-by: Jamil --- docker-compose.yml | 8 ++--- rust/Dockerfile | 59 +++---------------------------------- rust/docker-compose-dev.yml | 31 ------------------- rust/rust-toolchain.toml | 1 - 4 files changed, 8 insertions(+), 91 deletions(-) delete mode 100644 rust/docker-compose-dev.yml diff --git a/docker-compose.yml b/docker-compose.yml index 01379da1e..ff10d0a2a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -327,7 +327,7 @@ services: FIREZONE_API_URL: ws://api:8081 init: true build: - target: dev + target: debug context: rust dockerfile: Dockerfile cache_from: @@ -359,7 +359,7 @@ services: FIREZONE_ID: 4694E56C-7643-4A15-9DF3-638E5B05F570 init: true build: - target: dev + target: debug context: rust dockerfile: Dockerfile cache_from: @@ -446,7 +446,7 @@ services: FIREZONE_API_URL: ws://api:8081 OTLP_GRPC_ENDPOINT: otel:4317 build: - target: dev + target: debug context: rust dockerfile: Dockerfile cache_from: @@ -487,7 +487,7 @@ services: FIREZONE_API_URL: ws://api:8081 OTLP_GRPC_ENDPOINT: otel:4317 build: - target: dev + target: debug context: rust dockerfile: Dockerfile cache_from: diff --git a/rust/Dockerfile b/rust/Dockerfile index e8cbb7389..ee6d46276 100644 --- a/rust/Dockerfile +++ b/rust/Dockerfile @@ -1,49 +1,7 @@ -# Keep synced with `rust-toolchain.toml` -ARG RUST_VERSION="1.86.0" ARG ALPINE_VERSION="3.20" -ARG CARGO_CHEF_VERSION="0.1.67" ARG PACKAGE -# This image is used to prepare Cargo Chef which is used to cache dependencies -# Keep the Rust version synced with `rust-toolchain.toml` -FROM rust:${RUST_VERSION}-alpine${ALPINE_VERSION} AS chef - -ARG CARGO_CHEF_VERSION -RUN set -xe \ - && apk add --no-cache musl-dev \ - && cargo install cargo-chef --locked --version=${CARGO_CHEF_VERSION} \ - && rm -rf $CARGO_HOME/registry/ - -## See https://github.com/LukeMathWalker/cargo-chef/issues/231. -COPY rust-toolchain.toml rust-toolchain.toml - -RUN rustup show - -WORKDIR /build - -# Create a cache recipe for dependencies, which allows -# to leverage Docker layer caching in a later build stage -FROM chef AS planner - -COPY . . - -RUN cargo chef prepare --recipe-path recipe.json - -# Build dependencies and application application -FROM chef AS builder - -COPY --from=planner /build/recipe.json . - -ARG PACKAGE -RUN set -xe \ - && cargo chef cook --recipe-path recipe.json --bin ${PACKAGE} - -COPY . . - -ARG TARGET -RUN cargo build -p ${PACKAGE} $([ -n "${TARGET}" ] && "--target ${TARGET}") - # Base image which is used to run the application binary FROM alpine:${ALPINE_VERSION} AS runtime_base @@ -85,27 +43,18 @@ ENV PACKAGE=${PACKAGE} CMD ${PACKAGE} -# used as a base for dev and test -FROM runtime AS test +# Build an image for GitHub Actions which includes debug asserts and more test utilities +FROM runtime AS debug RUN apk add --no-cache iperf3 bind-tools iproute2 jq procps -# used for local development -FROM test AS dev -ARG TARGET -ARG PACKAGE -COPY --from=builder /build/target/${TARGET}/debug/${PACKAGE} . - -# Build an image for GitHub Actions which includes debug asserts and more test utilities -FROM test AS debug - -## Build first with `cross build --target ${TARGET} -p ${PACKAGE} && mv /target/${TARGET}/release/${PACKAGE} .` +## Build first with `cargo build --target ${TARGET} -p ${PACKAGE} && mv /target/${TARGET}/debug/${PACKAGE} .` ARG PACKAGE COPY ${PACKAGE} . # Build a production image from including a binary compiled on the host FROM runtime AS release -## Build first with `cross build --target ${TARGET} -p ${PACKAGE} --release && mv /target/${TARGET}/release/${PACKAGE} .` +## Build first with `cargo build --target ${TARGET} -p ${PACKAGE} --release && mv /target/${TARGET}/release/${PACKAGE} .` ARG PACKAGE COPY ${PACKAGE} . diff --git a/rust/docker-compose-dev.yml b/rust/docker-compose-dev.yml deleted file mode 100644 index c46bce5b5..000000000 --- a/rust/docker-compose-dev.yml +++ /dev/null @@ -1,31 +0,0 @@ -# Meant to be used with docker-compose.yml -services: - client: - build: - target: test - volumes: - - ./rust/target/x86_64-unknown-linux-musl/debug/firezone-headless-client:/bin/firezone-headless-client - - download.httpbin: - build: - target: test - volumes: - - ./rust/target/x86_64-unknown-linux-musl/debug/http-test-server:/bin/http-test-server - - gateway: - build: - target: test - volumes: - - ./rust/target/x86_64-unknown-linux-musl/debug/firezone-gateway:/bin/firezone-gateway - - relay-1: - build: - target: test - volumes: - - ./rust/target/x86_64-unknown-linux-musl/debug/firezone-relay:/bin/firezone-relay - - relay-2: - build: - target: test - volumes: - - ./rust/target/x86_64-unknown-linux-musl/debug/firezone-relay:/bin/firezone-relay diff --git a/rust/rust-toolchain.toml b/rust/rust-toolchain.toml index 7c097685e..8009387dc 100644 --- a/rust/rust-toolchain.toml +++ b/rust/rust-toolchain.toml @@ -1,5 +1,4 @@ [toolchain] -# Keep synced with `Dockerfile` channel = "1.86.0" components = ["rust-src", "rust-analyzer", "clippy"] targets = ["x86_64-unknown-linux-musl"]