-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
61 lines (44 loc) · 1.58 KB
/
Dockerfile
File metadata and controls
61 lines (44 loc) · 1.58 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
# Multi-stage build for Rust application
FROM rust:1.82 as builder
# Update CA certificates for HTTPS
RUN apt-get update && \
apt-get install -y ca-certificates && \
rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Copy dependency files first for better caching
COPY Cargo.toml Cargo.lock ./
# Copy benches directory for Cargo.toml manifest validation
COPY benches ./benches
# Create a dummy main.rs to build dependencies
RUN mkdir src && echo "fn main() {}" > src/main.rs
RUN cargo build --release
RUN rm src/main.rs
# Copy source code and build the application
COPY src ./src
COPY config.json.example ./config.json
# Build the application with release optimizations
RUN cargo build --release
# Runtime stage with minimal image
FROM debian:bookworm-slim
# Install CA certificates for HTTPS requests
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 keycycle && useradd -r -g keycycle keycycle
# Copy the compiled binary from builder stage
COPY --from=builder /app/target/release/key-cycle-proxy /usr/local/bin/key-cycle-proxy
# Set ownership and permissions
RUN chown keycycle:keycycle /usr/local/bin/key-cycle-proxy && \
chmod +x /usr/local/bin/key-cycle-proxy
# Switch to non-root user
USER keycycle
# Expose port (default Rust server port)
EXPOSE 8080
# Set environment variables
ENV RUST_LOG=info
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8080/health || exit 1
# Run the application
CMD ["key-cycle-proxy"]