From c791203d1cee42963e0165a4c0e4d0667719a5d0 Mon Sep 17 00:00:00 2001 From: Dylan Knutson Date: Sat, 28 Dec 2024 05:01:10 +0000 Subject: [PATCH] dockerfile for building release app --- .dockerignore | 37 ++++++++++++++++++++++++++++++++ .env.example | 9 ++++++++ Dockerfile | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 .dockerignore create mode 100644 .env.example create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..933e692 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,37 @@ +# Rust build artifacts +/target +**/*.rs.bk + +# Development environment +.env +.devcontainer +.vscode +.idea +*.swp +*.swo + +# Git +.git +.gitignore +.github + +# Documentation and misc +README.md +LICENSE +*.md + +# Generated files +embeddings_visualization.html + +# Debug files +core +*.log + +# Docker files (except Dockerfile which we need) +.dockerignore +docker-compose*.yml + +# Temporary files +*.tmp +*.temp +*~ \ No newline at end of file diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..8ff061b --- /dev/null +++ b/.env.example @@ -0,0 +1,9 @@ +# PostgreSQL connection settings +POSTGRES_HOST=postgres +POSTGRES_PORT=5432 +POSTGRES_DB=postgres +POSTGRES_USER=postgres +POSTGRES_PASSWORD=changeme + +# Logging level (debug, info, warn, error) +RUST_LOG=info \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..de34cc6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,59 @@ +FROM rust:1.75-slim-bullseye as builder + +# Install build dependencies +RUN apt-get update && \ + apt-get install -y \ + pkg-config \ + libssl-dev \ + libpq-dev \ + gcc \ + g++ \ + make \ + clang \ + lld \ + libomp-dev \ + libopenblas-dev \ + && rm -rf /var/lib/apt/lists/* + +# Create a new empty project +WORKDIR /app + +# Create a dummy project to cache dependencies +COPY Cargo.toml Cargo.lock ./ +RUN mkdir src && \ + echo "fn main() {println!(\"dummy\")}" > src/main.rs && \ + cargo build --release && \ + rm -rf src + +# Now copy the real source code +COPY . . + +# Build the application in release mode with cargo cache +RUN --mount=type=cache,target=/usr/local/cargo/registry \ + --mount=type=cache,target=/app/target \ + cargo build --release && \ + cp target/release/mf-fitter /app/mf-fitter + +# Create the runtime image +FROM debian:bullseye-slim + +# Install runtime dependencies +RUN apt-get update && \ + apt-get install -y \ + libpq5 \ + ca-certificates \ + libomp5 \ + libopenblas0 \ + libgomp1 \ + && rm -rf /var/lib/apt/lists/* + +# Copy the binary from builder +COPY --from=builder /app/mf-fitter /usr/local/bin/ +COPY --from=builder /app/.env.example /app/.env + +WORKDIR /app + +# Set environment variables +ENV RUST_LOG=info + +ENTRYPOINT ["/usr/local/bin/mf-fitter"] \ No newline at end of file