sharenet/backend/Dockerfile
continuist 4988a397f1
Some checks are pending
CI/CD Pipeline / Test Backend (push) Waiting to run
CI/CD Pipeline / Test Frontend (push) Waiting to run
CI/CD Pipeline / Build and Push Docker Images (push) Blocked by required conditions
CI/CD Pipeline / Deploy to Production (push) Blocked by required conditions
Added deploy and migrate scripts and made sure they were consistent
2025-06-28 01:26:38 -04:00

62 lines
No EOL
1.3 KiB
Docker

# Multi-stage build for Rust backend
FROM rust:1.75-slim as builder
# Install build dependencies
RUN apt-get update && apt-get install -y \
pkg-config \
libssl-dev \
&& rm -rf /var/lib/apt/lists/*
# Set working directory
WORKDIR /app
# Copy Cargo files
COPY Cargo.toml Cargo.lock ./
COPY crates/ ./crates/
# Build dependencies first (for better caching)
RUN cargo build --release --bin sharenet-api-postgres
# Copy source code
COPY . .
# Build the application
RUN cargo build --release --bin sharenet-api-postgres
# Runtime stage
FROM debian:bookworm-slim
# Install runtime dependencies
RUN apt-get update && apt-get install -y \
ca-certificates \
libssl3 \
wget \
&& rm -rf /var/lib/apt/lists/*
# Create non-root user
RUN useradd -r -s /bin/false sharenet
# Set working directory
WORKDIR /app
# Copy binary from builder
COPY --from=builder /app/target/release/sharenet-api-postgres /app/sharenet-api
# Copy configuration files
COPY --from=builder /app/config/ ./config/
# Change ownership
RUN chown -R sharenet:sharenet /app
# Switch to non-root user
USER sharenet
# Expose port
EXPOSE 3001
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:3001/health || exit 1
# Run the application
CMD ["./sharenet-api"]