-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
70 lines (50 loc) · 1.65 KB
/
Dockerfile
File metadata and controls
70 lines (50 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Production-ready Dockerfile for Rust Forward Proxy
# Build stage
FROM rust:1.85-slim as builder
# Install required packages for building
RUN apt-get update && apt-get install -y \
pkg-config \
libssl-dev \
&& rm -rf /var/lib/apt/lists/*
# Create app directory
WORKDIR /app
# Copy dependency files first for better 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 (this layer will be cached unless dependencies change)
RUN cargo build --release
RUN rm src/main.rs
# Copy source code
COPY src ./src
# Build application
RUN cargo build --release
# Runtime stage
FROM debian:bookworm-slim
# Install runtime dependencies
RUN apt-get update && apt-get install -y \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# Create non-root user for security
RUN groupadd -r appuser && useradd -r -g appuser appuser
# Create app directory and set ownership
WORKDIR /app
RUN chown appuser:appuser /app
# Copy binary from builder stage
COPY --from=builder /app/target/release/rust-forward-proxy /app/rust-forward-proxy
# Copy any required files (if any)
# COPY scripts/ ./scripts/
# Create logs directory
RUN mkdir -p /app/logs && chown appuser:appuser /app/logs
# Switch to non-root user
USER appuser
# Expose port (configurable via environment)
EXPOSE 8080
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8080/health || exit 1
# Default environment variables (can be overridden)
ENV RUST_LOG=info
ENV PROXY_LISTEN_ADDR=0.0.0.0:8080
# Run the application
CMD ["./rust-forward-proxy"]