From 33daae6f4c20e020c72afef81b6bc1d38ebab66d Mon Sep 17 00:00:00 2001 From: Vukasin Gostovic Date: Wed, 31 Jan 2024 20:35:53 +0100 Subject: [PATCH] update dockerfile --- Dockerfile | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8faa57d2..cff6b147 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,34 @@ -# Use an official Rust image as the base image -FROM rust:latest +# Use Rust official image for the build stage +FROM rust:latest AS build -# Set the working directory -WORKDIR /app +# Create and set the working directory +WORKDIR /usr/src/app + +# Copy the Rust project to the working directory +COPY . . + +# Install necessary dependencies for building the Rust project +RUN apt-get update && apt-get install -y libssl-dev pkg-config && \ + # Clean up the apt cache to reduce image size + apt-get clean && rm -rf /var/lib/apt/lists/* + +# Build the Rust project +# If your project uses a custom profile, replace `--release` with `--profile ` +RUN RUSTFLAGS='-C target-cpu=native' cargo build --release -# Copy the project files into the container -COPY / /app +# Start a new stage to create a smaller final image +FROM debian:bookworm + +# Install runtime dependencies +RUN apt-get update && apt-get install -y openssl ca-certificates && \ + # Clean up the apt cache to reduce image size + apt-get clean && rm -rf /var/lib/apt/lists/* + +# Create a directory for the application +WORKDIR /app -# Install libssl-dev -RUN apt-get update && apt-get install -y libssl-dev +# Copy the built binary from the build stage to the application directory +COPY --from=build /usr/src/app/target/release/blutgang /app/blutgang -# Build and run the Rust project -CMD ["cargo", "run", "--profile", "maxperf", "--", "-c", "config.toml"] +# Set the command to run the application +CMD ["./blutgang", "-c", "config.toml"]