sharenet/backend/Dockerfile
continuist 69ebda5e3d
All checks were successful
Podman Rootless Demo / test-backend (push) Has been skipped
Podman Rootless Demo / test-frontend (push) Has been skipped
Podman Rootless Demo / build-backend (push) Successful in 5m16s
Podman Rootless Demo / build-frontend (push) Has been skipped
Podman Rootless Demo / deploy-prod (push) Successful in 58s
Change where backend is looking for the migrations
2025-09-21 21:16:08 -04:00

63 lines
No EOL
1.4 KiB
Docker

# Multi-stage build for Rust backend
FROM docker.io/rust:1.89-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 and migrations
COPY Cargo.toml Cargo.lock ./
COPY migrations/ ./migrations/
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 docker.io/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"]