From f3a1f6058ea8042af61ffc1b111a287fada0bf36 Mon Sep 17 00:00:00 2001 From: Joey Kraut Date: Mon, 21 Oct 2024 12:54:03 -0700 Subject: [PATCH] auth-server: Dockerfile: Add dockerfile --- auth-server/Dockerfile | 56 +++++++++++++++++++++++++++++++++++++++++ auth-server/src/main.rs | 5 ++++ 2 files changed, 61 insertions(+) create mode 100644 auth-server/Dockerfile 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"] diff --git a/auth-server/src/main.rs b/auth-server/src/main.rs index 8346b68..6db2865 100644 --- a/auth-server/src/main.rs +++ b/auth-server/src/main.rs @@ -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, } // ------------- @@ -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