52 lines
1.5 KiB
Docker
52 lines
1.5 KiB
Docker
# Use the official Rust image as a base
|
|
FROM rust:bookworm as builder
|
|
|
|
# Set the working directory
|
|
WORKDIR /app
|
|
|
|
# Install system dependencies
|
|
RUN apt-get update && apt-get install -y \
|
|
pkg-config \
|
|
libssl-dev \
|
|
# Add any other dependencies required by your project
|
|
# For example, if you use postgres/mysql/sqlite, you might need libpq-dev, libmysqlclient-dev, libsqlite3-dev
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Copy the Cargo.toml and Cargo.lock first to leverage Docker cache
|
|
# This layer only rebuilds if dependencies change
|
|
COPY Cargo.toml Cargo.lock ./
|
|
|
|
# Create a dummy src directory and main.rs to build dependencies
|
|
# This caches the dependency build
|
|
RUN mkdir -p src && echo "fn main() {println!(\"hello world\");}" > src/main.rs
|
|
# Build dependencies
|
|
RUN cargo build --release && rm -rf src
|
|
|
|
# Copy the actual source code
|
|
COPY . .
|
|
|
|
# Build the release binary
|
|
RUN cargo build --release
|
|
|
|
# --- Start a new stage for a smaller final image ---
|
|
FROM debian:bookworm-slim
|
|
|
|
# Set the working directory
|
|
WORKDIR /app
|
|
|
|
# Install runtime dependencies if any
|
|
# For example, if your Rust application dynamically links to OpenSSL, you might need libssl3
|
|
RUN apt-get update && apt-get install -y \
|
|
libssl3 \
|
|
# Add any other runtime dependencies here
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Copy the built binary from the builder stage
|
|
COPY --from=builder /app/target/release/employee-tracking-backend .
|
|
|
|
# Expose the port your application listens on
|
|
EXPOSE 3000
|
|
|
|
# Set the entrypoint command to run your application
|
|
CMD ["./employee-tracking-backend"]
|