46 lines
1.5 KiB
Docker
46 lines
1.5 KiB
Docker
# Stage 1: Build Hugo site
|
|
FROM alpine:latest AS hugo-builder
|
|
|
|
# Install necessary dependencies (Hugo, Git, Node.js, and npm)
|
|
RUN apk add --no-cache hugo git nodejs npm
|
|
|
|
# Copy our enhanced Caddyfile
|
|
COPY Caddyfile.default.template /etc/caddy/Caddyfile.override
|
|
|
|
# Set working directory
|
|
WORKDIR /site
|
|
|
|
# Copy the Hugo source files
|
|
COPY public/ /site
|
|
|
|
# Install PostCSS and its dependencies locally and update browserslist with legacy-peer-deps
|
|
RUN cd /site && npm init -y || true && \
|
|
npm install --legacy-peer-deps && \
|
|
npm update caniuse-lite browserslist --legacy-peer-deps
|
|
|
|
# Build the Hugo site for production with optimizations
|
|
# Disable GitInfo, enable minification, and set production environment
|
|
RUN mkdir -p /public && \
|
|
cd /site && \
|
|
HUGO_ENABLEGITINFO=false \
|
|
HUGO_ENV=production \
|
|
npm run build || hugo --minify -d /public && \
|
|
cp -r /site/public/* /public/ || true
|
|
|
|
# Stage 2: Production image with prebuilt static files
|
|
FROM git.nixc.us/colin/container-base:production-nixiusstatic
|
|
|
|
# Copy the built site from the first stage
|
|
COPY --from=hugo-builder /public /srv
|
|
|
|
# Ensure images and static files are properly available
|
|
COPY public/images /srv/images
|
|
COPY public/favicon.* /srv/
|
|
COPY public/static /srv/static
|
|
|
|
# Copy our enhanced Caddyfile for development
|
|
COPY Caddyfile.default.template /etc/caddy/Caddyfile.override
|
|
|
|
# Add health check endpoint for production monitoring
|
|
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
|
CMD wget -q --spider http://localhost/health || exit 1 |