Skip to content

Commit

Permalink
auth-server: Dockerfile: Add dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
joeykraut committed Oct 21, 2024
1 parent dd8cbce commit 1e9812f
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions auth-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit 1e9812f

Please sign in to comment.