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 f3a1f60
Show file tree
Hide file tree
Showing 2 changed files with 61 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"]
5 changes: 5 additions & 0 deletions auth-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ struct Args {
/// The port to run the server on
#[arg(long, env = "PORT", default_value = "3030")]
port: u16,
/// Whether to enable datadog logging
#[arg(long)]
datadog_logging: bool,
}

// -------------
Expand Down Expand Up @@ -67,6 +70,8 @@ async fn main() {
let args = Args::parse();
let listen_addr: SocketAddr = ([0, 0, 0, 0], args.port).into();

// TODO: Setup logging

// --- Routes --- //

// Ping route
Expand Down

0 comments on commit f3a1f60

Please sign in to comment.