forked from lancachenet/monolithic
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
127 lines (114 loc) · 4.82 KB
/
Copy pathDockerfile
File metadata and controls
127 lines (114 loc) · 4.82 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
118
119
120
121
122
123
124
125
126
127
# ── Stage 1: Build admin frontend ──────────────────────────────────────────────
FROM node:20-alpine AS frontend-build
WORKDIR /app
ARG CACHE_BUST
COPY admin/frontend/package*.json ./
RUN npm ci
COPY admin/frontend/ ./
RUN npm run build
# ── Stage 2: Build admin backend ──────────────────────────────────────────────
FROM golang:1.22-alpine AS backend-build
WORKDIR /app
COPY admin/backend/go.mod ./
RUN go mod download
COPY admin/backend/ ./
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o lancache-admin .
# ── Stage 3: Final image ──────────────────────────────────────────────────────
FROM nginx:alpine
LABEL version=3
LABEL description="Single caching container for caching game content at LAN parties."
LABEL maintainer="LanCache.Net Team <team@lancache.net>"
# Install required packages
# nginx-module-njs ships the ngx_http_js_module.so used by the noslice/heartbeat
# njs runtime under /etc/nginx/njs/. Build fails loudly if the module .so is
# absent (acceptance criterion 1 — "the njs module is installed and loaded").
RUN apk add --no-cache \
bash \
supervisor \
inotify-tools \
jq \
git \
ca-certificates \
curl \
findutils \
coreutils \
shadow \
openssl \
bind-tools \
nginx-module-njs \
&& test -f /etc/nginx/modules/ngx_http_js_module.so \
|| (echo "FATAL: nginx-module-njs installed but ngx_http_js_module.so missing" >&2; exit 1)
ENV GENERICCACHE_VERSION=2 \
CACHE_MODE=monolithic \
WEBUSER=nginx \
PUID=33 \
PGID=33 \
CACHE_INDEX_SIZE=500m \
CACHE_DISK_SIZE=1000g \
MIN_FREE_DISK=10g \
CACHE_MAX_AGE=3560d \
CACHE_SLICE_SIZE=1m \
UPSTREAM_DNS="8.8.8.8 8.8.4.4" \
BEAT_TIME=1h \
LOGFILE_RETENTION=3560 \
CACHE_DOMAINS_REPO="https://github.com/uklans/cache-domains.git" \
CACHE_DOMAINS_BRANCH=master \
NGINX_WORKER_PROCESSES=auto \
NGINX_LOG_FORMAT=cachelog \
NGINX_PROXY_CONNECT_TIMEOUT=300s \
NGINX_PROXY_SEND_TIMEOUT=300s \
NGINX_PROXY_READ_TIMEOUT=300s \
NGINX_SEND_TIMEOUT=300s \
NGINX_LOG_TO_STDOUT=false \
NGINX_SENDFILE=on \
NOSLICE_FALLBACK=false \
NOSLICE_THRESHOLD=3 \
NOSLICE_DETECT_MODE=log \
NOSLICE_SCAN_INTERVAL=10s \
NOSLICE_STATIC_HOSTS="" \
DECAY_INTERVAL=86400 \
EPIC_FORCE_NOSLICE=false \
ENABLE_UPSTREAM_KEEPALIVE=false \
UPSTREAM_KEEPALIVE_CONNECTIONS=16 \
UPSTREAM_KEEPALIVE_REQUESTS=10000 \
UPSTREAM_KEEPALIVE_TIMEOUT=4s \
UPSTREAM_KEEPALIVE_TIME=60s \
ADMIN_PORT=8181 \
ENABLE_ADMIN_UI=false
# Setup directories
RUN mkdir -p /etc/nginx/sites-available /etc/nginx/sites-enabled \
/etc/nginx/stream-available /etc/nginx/stream-enabled /etc/nginx/stream.d \
/etc/nginx/conf.d /var/log/nginx /var/www /var/log/supervisor \
&& rm -f /etc/nginx/conf.d/default.conf \
&& chown -R nginx:nginx /var/log/nginx /var/www
COPY overlay/ /
# Copy built admin frontend
COPY --from=frontend-build /app/dist /var/www/admin
COPY --from=backend-build /app/lancache-admin /usr/local/bin/lancache-admin
RUN rm -f /etc/nginx/sites-enabled/* /etc/nginx/stream-enabled/* 2>/dev/null || true; \
rm -f /etc/nginx/conf.d/gzip.conf 2>/dev/null || true; \
chmod 755 /scripts/* 2>/dev/null || true; \
chmod 755 /hooks/entrypoint-pre.d/*.sh 2>/dev/null || true; \
chmod -R 755 /init /hooks 2>/dev/null || true; \
mkdir -m 755 -p /data/cache; \
mkdir -m 755 -p /data/config; \
mkdir -m 755 -p /data/info; \
mkdir -m 755 -p /data/logs; \
mkdir -m 755 -p /tmp/nginx/; \
chown -R nginx:nginx /data/; \
mkdir -p /etc/nginx/sites-enabled; \
ln -sf /etc/nginx/sites-available/10_cache.conf /etc/nginx/sites-enabled/10_generic.conf; \
ln -sf /etc/nginx/sites-available/20_upstream.conf /etc/nginx/sites-enabled/20_upstream.conf; \
ln -sf /etc/nginx/sites-available/30_metrics.conf /etc/nginx/sites-enabled/30_metrics.conf; \
ln -sf /etc/nginx/sites-available/50_njs_periodics.conf /etc/nginx/sites-enabled/50_njs_periodics.conf; \
ln -sf /etc/nginx/stream-available/10_sni.conf /etc/nginx/stream-enabled/10_sni.conf; \
mkdir -m 755 -p /data/cachedomains; \
mkdir -m 755 -p /tmp/nginx
RUN git clone --depth=1 --no-single-branch https://github.com/uklans/cache-domains/ /data/cachedomains
VOLUME ["/data/logs", "/data/cache", "/data/cachedomains", "/data/config"]
EXPOSE 80 443 8080 8181
WORKDIR /scripts
HEALTHCHECK --interval=1m --timeout=10s --start-period=120s --retries=3 \
CMD curl --fail http://127.0.0.1/lancache-heartbeat || exit 1
ENTRYPOINT ["/bin/bash", "-e", "/init/entrypoint"]
CMD ["run"]