diff --git a/auth-server/Dockerfile b/auth-server/Dockerfile new file mode 100644 index 0000000..a0f0097 --- /dev/null +++ b/auth-server/Dockerfile @@ -0,0 +1,56 @@ +# === Chef === # +FROM --platform=arm64 rust:latest AS chef + +# Create a build dir and add local dependencies +WORKDIR /build + +COPY ./rust-toolchain ./rust-toolchain +RUN cat rust-toolchain | xargs rustup toolchain install + +# Install cargo-chef +RUN cargo install cargo-chef + +# === Sources === # +FROM chef AS sources +WORKDIR /build +COPY ./Cargo.toml ./Cargo.lock ./ +COPY ./auth-server ./auth-server + +# === Builder === # +# Pull the sources into their own layer +FROM chef AS builder + +# Disable compiler warnings and enable backtraces for panic debugging +ENV RUSTFLAGS=-Awarnings +ENV RUST_BACKTRACE=1 +ENV CARGO_HTTP_CHECK_REVOKE=false + +COPY --from=sources /build /build +WORKDIR /build + +# Install protoc, openssl, and pkg-config +RUN apt-get update && \ + apt-get install -y pkg-config libssl-dev libclang-dev libpq-dev ca-certificates + +# Update Cargo.toml to include only "auth-server" in workspace members +RUN sed -i '/members[[:space:]]*=[[:space:]]*\[/,/\]/c\members = ["auth-server"]' Cargo.toml +RUN cargo chef prepare --recipe-path recipe.json --bin auth-server + +# Build only the dependencies to cache them in this layer +RUN cargo chef cook --release --recipe-path recipe.json + +COPY --from=sources /build/auth-server /build/auth-server +WORKDIR /build + +RUN cargo build --release -p auth-server + +# === Release stage === # +FROM --platform=arm64 debian:bookworm-slim +RUN apt-get update && \ + apt-get install -y libssl-dev ca-certificates libpq-dev + +# Copy the binary from the build stage +COPY --from=builder /build/target/release/auth-server /bin/auth-server + +ENTRYPOINT ["/bin/auth-server"] +CMD ["--datadog-logging"]