-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
68 lines (50 loc) · 2.23 KB
/
Dockerfile
File metadata and controls
68 lines (50 loc) · 2.23 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
# Multi-stage Docker build for SDC Web React application.
# Stage 1: Build Caddy with transform-encoder module.
# Stage 2: Build the React application.
# Stage 3: Serve with Caddy web server.
# Build arguments for version control.
ARG NODE_VERSION=20
ARG CADDY_VERSION=2-alpine
# --------------------------------------------------------------------------------
# Stage 1: Caddy Builder - Build Caddy with transform-encoder module.
# This module is required for transforming logs to a more readable format.
# To optimise logs for machine parsing, just use the normal caddy image
# with the json logger.
FROM caddy:builder AS caddy-builder
RUN xcaddy build \
--with github.com/caddyserver/transform-encoder
# --------------------------------------------------------------------------------
# Stage 2: React Builder - Build the React app.
FROM node:${NODE_VERSION}-alpine AS builder
WORKDIR /app
# Copy package files for dependency installation.
COPY package*.json ./
# Install dependencies. Use clean install for reproducible builds.
RUN npm ci
# Copy source code.
COPY . .
# Build the application.
RUN npm run build
# --------------------------------------------------------------------------------
# Stage 3: Production - Serve with Caddy.
FROM caddy:${CADDY_VERSION}
# Copy custom-built Caddy binary with transform-encoder module.
COPY --from=caddy-builder /usr/bin/caddy /usr/bin/caddy
# Copy built static files from builder stage.
COPY --from=builder /app/dist /usr/share/caddy
# Copy Caddyfile for server configuration.
COPY configs/Caddyfile /etc/caddy/Caddyfile
# Extract version from package.json for labeling.
COPY --from=builder /app/package.json /tmp/package.json
# Add labels for container metadata.
LABEL org.opencontainers.image.title="SDC Web"
LABEL org.opencontainers.image.description="Supermarket Data Collector Web Application"
LABEL org.opencontainers.image.source="https://github.com/dfmoller/sdc-web"
# Expose HTTP and HTTPS ports.
EXPOSE 80
EXPOSE 443
# Health check endpoint.
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:80/ || exit 1
# Caddy runs as non-root by default and serves from /usr/share/caddy.
# No CMD needed, the base caddy image handles it.