This commit is contained in:
Bastian Wagner
2026-06-17 11:01:05 +02:00
parent c94a02e6d0
commit 8151a0f7cd
3 changed files with 72 additions and 79 deletions

View File

@@ -1,10 +1,8 @@
# syntax=docker/dockerfile:1.7
FROM node:24-alpine AS api-deps FROM node:24-alpine AS api-deps
WORKDIR /build/api WORKDIR /build/api
COPY api/package*.json ./ COPY api/package*.json ./
RUN --mount=type=cache,target=/root/.npm npm ci RUN npm ci
FROM node:24-alpine AS api-build FROM node:24-alpine AS api-build
WORKDIR /build/api WORKDIR /build/api
@@ -21,13 +19,13 @@ WORKDIR /build/api
ENV NODE_ENV=production ENV NODE_ENV=production
COPY api/package*.json ./ COPY api/package*.json ./
RUN --mount=type=cache,target=/root/.npm npm ci --omit=dev --ignore-scripts RUN npm ci --omit=dev --ignore-scripts
FROM node:24-alpine AS client-deps FROM node:24-alpine AS client-deps
WORKDIR /build/client WORKDIR /build/client
COPY client/package*.json ./ COPY client/package*.json ./
RUN --mount=type=cache,target=/root/.npm npm ci RUN npm ci
FROM node:24-alpine AS client-build FROM node:24-alpine AS client-build
WORKDIR /build/client WORKDIR /build/client
@@ -54,80 +52,8 @@ COPY --from=api-build /build/api/dist ./api/dist
COPY api/package*.json ./api/ COPY api/package*.json ./api/
COPY --from=client-build /build/client/dist/client/browser /usr/share/nginx/html COPY --from=client-build /build/client/dist/client/browser /usr/share/nginx/html
RUN <<'EOF' COPY docker/nginx.conf /etc/nginx/http.d/default.conf
cat > /etc/nginx/http.d/default.conf <<'NGINX' COPY docker/supervisord.conf /etc/supervisord.conf
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
index index.html;
access_log /dev/stdout;
error_log /dev/stderr warn;
gzip on;
gzip_comp_level 5;
gzip_min_length 1024;
gzip_types
application/javascript
application/json
image/svg+xml
text/css
text/plain;
location ~* \.(?:css|js|mjs|png|jpg|jpeg|gif|ico|svg|webp|woff2?)$ {
access_log off;
add_header Cache-Control "public, max-age=31536000, immutable";
try_files $uri =404;
}
location ~ ^/(analytics|auth|strava)(/|$) {
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://127.0.0.1:3000;
}
location / {
add_header Cache-Control "no-store";
try_files $uri $uri/ /index.html;
}
}
NGINX
cat > /etc/supervisord.conf <<'SUPERVISOR'
[supervisord]
nodaemon=true
logfile=/dev/null
logfile_maxbytes=0
pidfile=/tmp/supervisord.pid
[program:api]
directory=/app/api
command=node dist/main.js
user=node
autorestart=true
stopasgroup=true
killasgroup=true
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
stderr_logfile=/dev/fd/2
stderr_logfile_maxbytes=0
[program:nginx]
command=nginx -g "daemon off;"
autorestart=true
stopasgroup=true
killasgroup=true
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
stderr_logfile=/dev/fd/2
stderr_logfile_maxbytes=0
SUPERVISOR
EOF
HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 \ HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 \
CMD wget -qO- http://127.0.0.1/ >/dev/null || exit 1 CMD wget -qO- http://127.0.0.1/ >/dev/null || exit 1

40
docker/nginx.conf Normal file
View File

@@ -0,0 +1,40 @@
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
index index.html;
access_log /dev/stdout;
error_log /dev/stderr warn;
gzip on;
gzip_comp_level 5;
gzip_min_length 1024;
gzip_types
application/javascript
application/json
image/svg+xml
text/css
text/plain;
location ~* \.(?:css|js|mjs|png|jpg|jpeg|gif|ico|svg|webp|woff2?)$ {
access_log off;
add_header Cache-Control "public, max-age=31536000, immutable";
try_files $uri =404;
}
location ~ ^/(analytics|auth|strava)(/|$) {
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://127.0.0.1:3000;
}
location / {
add_header Cache-Control "no-store";
try_files $uri $uri/ /index.html;
}
}

27
docker/supervisord.conf Normal file
View File

@@ -0,0 +1,27 @@
[supervisord]
nodaemon=true
logfile=/dev/null
logfile_maxbytes=0
pidfile=/tmp/supervisord.pid
[program:api]
directory=/app/api
command=node dist/main.js
user=node
autorestart=true
stopasgroup=true
killasgroup=true
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
stderr_logfile=/dev/fd/2
stderr_logfile_maxbytes=0
[program:nginx]
command=nginx -g "daemon off;"
autorestart=true
stopasgroup=true
killasgroup=true
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
stderr_logfile=/dev/fd/2
stderr_logfile_maxbytes=0