mirror of
https://github.com/lukaszraczylo/gohoarder.git
synced 2026-11-25 06:35:21 +00:00
Docker Hub rate-limited the v0.1.328 release build, so goreleaser kept retrying the base image pulls. The Dockerfiles now pull alpine 3.24.4 and nginx 1.31.9-alpine from mirror.gcr.io, pinned by digest. Those digests are what alpine:latest and nginx:alpine resolved to, so the images are unchanged, and a release no longer moves silently with a floating tag.
176 lines
5.5 KiB
Docker
176 lines
5.5 KiB
Docker
# Website - Frontend Dashboard with integrated reverse proxy
|
|
# Combines frontend serving and backend proxy (previously separate gateway)
|
|
# EXPECTS: Pre-built frontend files in frontend/dist/ directory
|
|
|
|
FROM mirror.gcr.io/library/nginx:1.31.9-alpine@sha256:fb4658584bd9a916ffb6f6e365f97c25cfdb2923801f551ea08356e695f14ff7
|
|
|
|
# Install envsubst for runtime configuration
|
|
RUN apk add --no-cache gettext
|
|
|
|
# Copy pre-built frontend files
|
|
# These are built on the CI runner and injected via extra_files
|
|
COPY frontend/dist /usr/share/nginx/html
|
|
|
|
# Create runtime config injection script
|
|
RUN cat > /docker-entrypoint.d/40-inject-config.sh <<'EOF'
|
|
#!/bin/sh
|
|
set -e
|
|
|
|
# Create runtime configuration file
|
|
cat > /usr/share/nginx/html/config.js <<JSEOF
|
|
window.__RUNTIME_CONFIG__ = {
|
|
API_BASE_URL: "${API_BASE_URL:-/api}",
|
|
APP_VERSION: "${APP_VERSION:-unknown}",
|
|
APP_NAME: "${APP_NAME:-GoHoarder}"
|
|
};
|
|
JSEOF
|
|
|
|
# Substitute environment variables
|
|
envsubst < /usr/share/nginx/html/config.js > /usr/share/nginx/html/config.tmp.js
|
|
mv /usr/share/nginx/html/config.tmp.js /usr/share/nginx/html/config.js
|
|
|
|
echo "Runtime configuration injected:"
|
|
cat /usr/share/nginx/html/config.js
|
|
EOF
|
|
|
|
RUN chmod +x /docker-entrypoint.d/40-inject-config.sh
|
|
|
|
# Create nginx templates directory and configuration template with backend proxy support
|
|
RUN mkdir -p /etc/nginx/templates && \
|
|
cat > /etc/nginx/templates/default.conf.template <<'EOF'
|
|
# Upstream backend server
|
|
upstream backend {
|
|
server ${BACKEND_HOST}:${BACKEND_PORT};
|
|
keepalive 32;
|
|
}
|
|
|
|
# Cache configuration
|
|
proxy_cache_path /var/cache/nginx/static levels=1:2 keys_zone=static_cache:10m max_size=100m inactive=60m use_temp_path=off;
|
|
|
|
server {
|
|
listen 80;
|
|
server_name ${SERVER_NAME};
|
|
root /usr/share/nginx/html;
|
|
index index.html;
|
|
|
|
# Security headers
|
|
add_header X-Frame-Options "SAMEORIGIN" always;
|
|
add_header X-Content-Type-Options "nosniff" always;
|
|
add_header X-XSS-Protection "1; mode=block" always;
|
|
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
|
|
|
# Client body size for package uploads
|
|
client_max_body_size 500M;
|
|
client_body_timeout 300s;
|
|
|
|
# Logging
|
|
access_log /var/log/nginx/access.log combined;
|
|
error_log /var/log/nginx/error.log warn;
|
|
|
|
# Compression
|
|
gzip on;
|
|
gzip_types text/plain text/css application/json application/javascript text/xml application/xml text/javascript;
|
|
|
|
# API endpoints - proxy to backend
|
|
location /api/ {
|
|
# Proxy settings
|
|
proxy_pass http://backend;
|
|
proxy_http_version 1.1;
|
|
|
|
# Headers
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
proxy_set_header X-Forwarded-Host $host;
|
|
proxy_set_header X-Forwarded-Port $server_port;
|
|
proxy_set_header Connection "";
|
|
# The backend authenticates by API-key header; browser session cookies only bloat the request.
|
|
proxy_set_header Cookie "";
|
|
|
|
# Timeouts for long-running operations
|
|
proxy_connect_timeout 60s;
|
|
proxy_send_timeout 300s;
|
|
proxy_read_timeout 300s;
|
|
|
|
# Buffer settings
|
|
proxy_buffering on;
|
|
proxy_buffer_size 4k;
|
|
proxy_buffers 8 4k;
|
|
proxy_busy_buffers_size 8k;
|
|
}
|
|
|
|
# Health check endpoint
|
|
location /health {
|
|
proxy_pass http://backend/health;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Connection "";
|
|
access_log off;
|
|
}
|
|
|
|
# The package endpoints are not part of the dashboard and stay on the
|
|
# backend Service. A catch-all 404 keeps them off the SPA fallback below.
|
|
location ~ ^/(npm|pypi|go|metrics)(/|$) {
|
|
return 404;
|
|
}
|
|
|
|
# WebSocket support
|
|
location /ws {
|
|
proxy_pass http://backend;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection "upgrade";
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
proxy_set_header Cookie "";
|
|
|
|
# WebSocket timeouts
|
|
proxy_connect_timeout 7d;
|
|
proxy_send_timeout 7d;
|
|
proxy_read_timeout 7d;
|
|
}
|
|
|
|
# Runtime configuration endpoint
|
|
location = /config.js {
|
|
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
|
add_header Pragma "no-cache";
|
|
add_header Expires "0";
|
|
}
|
|
|
|
# Cache static assets
|
|
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
|
expires 1y;
|
|
add_header Cache-Control "public, immutable";
|
|
}
|
|
|
|
# Frontend SPA - serve index.html for all other routes
|
|
location / {
|
|
try_files $uri $uri/ /index.html;
|
|
}
|
|
}
|
|
EOF
|
|
|
|
# Create cache directory
|
|
RUN mkdir -p /var/cache/nginx/static && \
|
|
chown -R nginx:nginx /var/cache/nginx
|
|
|
|
# Expose port
|
|
EXPOSE 80
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
|
CMD wget --quiet --tries=1 --spider http://localhost/ || exit 1
|
|
|
|
# Environment variables with defaults
|
|
ENV API_BASE_URL=/api \
|
|
APP_VERSION=unknown \
|
|
APP_NAME=GoHoarder \
|
|
BACKEND_HOST=gohoarder-server \
|
|
BACKEND_PORT=8080 \
|
|
SERVER_NAME=_
|
|
|
|
# Use nginx template substitution and start nginx
|
|
CMD ["/bin/sh", "-c", "envsubst '$$BACKEND_HOST $$BACKEND_PORT $$SERVER_NAME' < /etc/nginx/templates/default.conf.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"]
|