email-microservice/Dockerfile
2026-01-26 01:36:06 -05:00

49 lines
1.0 KiB
Docker

# Multi-stage build for optimized production image
FROM rust:1.83 as builder
WORKDIR /app
# Copy manifests for dependency caching
COPY Cargo.toml Cargo.lock* ./
# Copy source code
COPY src ./src
# Build for release
RUN cargo build --release
# Runtime stage
FROM debian:bookworm-slim
# Install CA certificates and curl for HTTPS requests and health checks
RUN apt-get update && \
apt-get install -y ca-certificates curl && \
rm -rf /var/lib/apt/lists/*
# Create app user
RUN useradd -r -s /bin/false appuser
# Copy the binary from builder stage
COPY --from=builder /app/target/release/emailer-microservice /usr/local/bin/emailer-microservice
# Set ownership
RUN chown appuser:appuser /usr/local/bin/emailer-microservice
# Switch to non-root user
USER appuser
# Environment defaults
ENV HOST=0.0.0.0
ENV PORT=4000
ENV RUST_LOG=info
# Expose port
EXPOSE 4000
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:4000/health || exit 1
# Run the binary
CMD ["emailer-microservice"]