captains-log/backend/Dockerfile
Drew Galbraith 050706674a
Some checks failed
Docker Build / Build and Push Backend Image (push) Failing after 0s
Docker Build / Build and Push Frontend Image (push) Failing after 0s
Check / Backend (pull_request) Successful in 6m14s
Check / Frontend (pull_request) Successful in 2m5s
Add a docker build step.
2025-09-28 20:51:17 -07:00

47 lines
1,014 B
Docker

# Multi-stage Dockerfile for Rust backend
FROM rust:1.90-alpine as builder
# Install build dependencies
RUN apk add --no-cache \
musl-dev \
pkgconfig \
openssl-dev \
clang
# Set working directory
WORKDIR /app
# Copy Cargo files for dependency caching
COPY Cargo.toml Cargo.lock ./
# Create a dummy main.rs to build dependencies
RUN mkdir src && echo "fn main() {}" > src/main.rs
# Build dependencies (cached layer)
RUN cargo build --release && rm -rf src/
# Copy source code
COPY src/ src/
COPY migrations/ migrations/
# Build the application
RUN cargo build --release
# Runtime stage
FROM alpine:latest
# Install runtime dependencies
RUN apk add --no-cache ca-certificates curl
# Copy the binary from builder stage
COPY --from=builder /app/target/release/backend /usr/local/bin/app
# Expose port
EXPOSE 3000
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD curl -f http://localhost:3000/health || exit 1
# Run the application
CMD ["app"]