|
| 1 | +# ============================================================================= |
| 2 | +# Google Authenticator Export Decoder - Production Dockerfile |
| 3 | +# ============================================================================= |
| 4 | +# Multi-stage build optimized for minimal image size and security |
| 5 | +# |
| 6 | +# Final image: ~25MB (nginx:alpine-slim + static assets) |
| 7 | +# Build: docker build -t ga-export-decoder . |
| 8 | +# Run: docker run -p 8080:80 ga-export-decoder |
| 9 | +# ============================================================================= |
| 10 | + |
| 11 | +# ----------------------------------------------------------------------------- |
| 12 | +# Stage 1: Dependencies |
| 13 | +# ----------------------------------------------------------------------------- |
| 14 | +# Separate stage for npm install to maximize layer caching |
| 15 | +# Only invalidated when package*.json changes |
| 16 | +# ----------------------------------------------------------------------------- |
| 17 | +FROM node:24-alpine AS deps |
| 18 | + |
| 19 | +WORKDIR /app |
| 20 | + |
| 21 | +# Copy only package files for dependency installation |
| 22 | +COPY package.json package-lock.json* ./ |
| 23 | + |
| 24 | +# Install dependencies with clean install for reproducible builds |
| 25 | +# --ignore-scripts: Skip postinstall scripts for security |
| 26 | +# --no-audit: Skip audit during build (run separately in CI) |
| 27 | +RUN npm ci --ignore-scripts |
| 28 | + |
| 29 | +# ----------------------------------------------------------------------------- |
| 30 | +# Stage 2: Build |
| 31 | +# ----------------------------------------------------------------------------- |
| 32 | +# Build the production bundle |
| 33 | +# ----------------------------------------------------------------------------- |
| 34 | +FROM node:24-alpine AS build |
| 35 | + |
| 36 | +WORKDIR /app |
| 37 | + |
| 38 | +# Copy dependencies from deps stage |
| 39 | +COPY --from=deps /app/node_modules ./node_modules |
| 40 | + |
| 41 | +# Copy source code |
| 42 | +COPY . . |
| 43 | + |
| 44 | +# Build the production bundle |
| 45 | +# Output: /app/dist |
| 46 | +RUN npm run build |
| 47 | + |
| 48 | +# ----------------------------------------------------------------------------- |
| 49 | +# Stage 3: Production |
| 50 | +# ----------------------------------------------------------------------------- |
| 51 | +# Minimal nginx image serving static files |
| 52 | +# ----------------------------------------------------------------------------- |
| 53 | +FROM nginx:1.27-alpine-slim AS production |
| 54 | + |
| 55 | +# ─────────────────────────────────────────────────────────────────────────────── |
| 56 | +# Metadata |
| 57 | +# ─────────────────────────────────────────────────────────────────────────────── |
| 58 | + |
| 59 | +LABEL vendor="BAUER GROUP" |
| 60 | +LABEL maintainer="Karl Bauer <karl.bauer@bauer-group.com>" |
| 61 | + |
| 62 | +# Opencontainers Metadata |
| 63 | +LABEL org.opencontainers.image.title="Google Authenticator Export Decoder" |
| 64 | +LABEL org.opencontainers.image.description="PWA for scanning Google Authenticator export QR codes and exporting TOTP secrets" |
| 65 | +LABEL org.opencontainers.image.version="0.1.0" |
| 66 | +LABEL org.opencontainers.image.licenses="MIT" |
| 67 | +LABEL org.opencontainers.image.vendor="BAUER GROUP" |
| 68 | +LABEL org.opencontainers.image.authors="Karl Bauer <karl.bauer@bauer-group.com>" |
| 69 | +LABEL org.opencontainers.image.source="https://github.com/bauer-group/SEC-GoogleAuthenticatorExportDecoder" |
| 70 | +LABEL org.opencontainers.image.url="https://github.com/bauer-group/SEC-GoogleAuthenticatorExportDecoder" |
| 71 | +LABEL org.opencontainers.image.documentation="https://github.com/bauer-group/SEC-GoogleAuthenticatorExportDecoder#readme" |
| 72 | + |
| 73 | +# Remove default nginx content |
| 74 | +RUN rm -rf /usr/share/nginx/html/* |
| 75 | + |
| 76 | +# Copy nginx configuration |
| 77 | +COPY nginx.conf /etc/nginx/conf.d/default.conf |
| 78 | + |
| 79 | +# Copy built static assets from build stage |
| 80 | +COPY --from=build /app/dist /usr/share/nginx/html |
| 81 | + |
| 82 | +# Set correct permissions |
| 83 | +RUN chown -R nginx:nginx /usr/share/nginx/html && \ |
| 84 | + chmod -R 755 /usr/share/nginx/html |
| 85 | + |
| 86 | +# Use non-root user where possible |
| 87 | +# Note: nginx master process needs root to bind to port 80 |
| 88 | +# Worker processes run as 'nginx' user |
| 89 | + |
| 90 | +# Expose HTTP port |
| 91 | +EXPOSE 80 |
| 92 | + |
| 93 | +# Health check |
| 94 | +HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ |
| 95 | + CMD wget --no-verbose --tries=1 --spider http://localhost/health || exit 1 |
| 96 | + |
| 97 | +# Start nginx in foreground |
| 98 | +CMD ["nginx", "-g", "daemon off;"] |
0 commit comments