-
-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathDockerfile
More file actions
117 lines (89 loc) · 3.15 KB
/
Copy pathDockerfile
File metadata and controls
117 lines (89 loc) · 3.15 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# Multi-stage Dockerfile for RequestRepo Rust backend
# Uses cargo-chef for optimized dependency caching
# Stage 1: Chef - install cargo-chef
FROM rust:1.88-slim-bookworm AS chef
RUN apt-get update && apt-get install -y --no-install-recommends \
libssl-dev \
pkg-config \
&& rm -rf /var/lib/apt/lists/*
RUN cargo install cargo-chef --locked
WORKDIR /app
# Stage 2: Planner - analyze dependencies
FROM chef AS planner
COPY src/Cargo.toml src/Cargo.lock ./
COPY src/src ./src
RUN cargo chef prepare --recipe-path recipe.json
# Stage 3: Builder - build dependencies then source
FROM chef AS rust-builder
COPY --from=planner /app/recipe.json recipe.json
# Build dependencies - this layer is cached unless dependencies change
RUN cargo chef cook --release --recipe-path recipe.json
# Copy source and build application
COPY src/Cargo.toml src/Cargo.lock ./
COPY src/src ./src
RUN cargo build --release
# Stage 4: Build frontend
FROM oven/bun:1.2-slim AS frontend-builder
WORKDIR /app
# Copy package files
COPY frontend/package.json frontend/bun.lock* ./
# Install dependencies
RUN bun install
# Copy frontend source
COPY frontend/ ./
# Build frontend
RUN bun run build
# Stage 5: Download IP geolocation database
FROM alpine:3.21 AS ip2country-downloader
RUN apk add --no-cache curl
WORKDIR /data
# Download DB-IP country database (free, updated monthly)
# Using current year-month to get the latest version
# Falls back gracefully if download fails
RUN mkdir -p vendor && \
YEAR_MONTH=$(date +%Y-%m) && \
curl -fsSL "https://download.db-ip.com/free/dbip-country-lite-${YEAR_MONTH}.csv.gz" \
-o vendor/dbip-country-lite.csv.gz || \
echo "Warning: Could not download DB-IP database, IP geolocation will be disabled"
# Stage 6: Final runtime image
FROM debian:bookworm-slim
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
tzdata \
wget \
&& rm -rf /var/lib/apt/lists/*
# Create non-root user
RUN groupadd -g 1000 requestrepo && \
useradd -u 1000 -g requestrepo -s /bin/sh -m requestrepo
WORKDIR /app
# Create certificate directory for Let's Encrypt certs
RUN mkdir -p /app/certs && chown requestrepo:requestrepo /app/certs
# Copy Rust binary
COPY --from=rust-builder /app/target/release/requestrepo /app/requestrepo
# Copy frontend build (Vite outputs to dist/)
COPY --from=frontend-builder /app/dist /app/public
# Copy IP2Country database (downloaded in previous stage)
COPY --from=ip2country-downloader --chown=requestrepo:requestrepo /data/ /app/ip2country/
# Set ownership
RUN chown -R requestrepo:requestrepo /app
USER requestrepo
# Environment variables with defaults
ENV RUST_LOG=info
ENV HTTP_PORT=80
ENV HTTPS_PORT=443
ENV DNS_PORT=53
ENV SMTP_PORT=25
ENV DOMAIN=requestrepo.com
ENV TLS_ENABLED=false
ENV CERT_DIR=/app/certs
ENV CERT_RENEWAL_DAYS=7
ENV CERT_CHECK_HOURS=12
# Expose ports
EXPOSE 80 443 53/udp 53/tcp 25
# Define volume for persistent certificate storage
VOLUME /app/certs
# Health check
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:${HTTP_PORT}/health || exit 1
# Run the application
CMD ["/app/requestrepo"]