# Stage 1: Build the Hugo site FROM alpine:3.19 AS builder # Install dependencies RUN apk add --no-cache wget tar # Install Hugo extended version 0.147.0 (latest stable version) RUN HUGO_VERSION=0.147.0 && \ wget -q https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.tar.gz -O hugo.tar.gz && \ mkdir -p /tmp/hugo && \ tar -xzf hugo.tar.gz -C /tmp/hugo && \ mv /tmp/hugo/hugo /usr/local/bin/ && \ chmod +x /usr/local/bin/hugo && \ rm -rf /tmp/hugo hugo.tar.gz && \ hugo version # Set the working directory in the container WORKDIR /src # Copy the content of the project to the working directory # This includes your Hugo site source, themes, and nginx.conf COPY . . # Build the Hugo site. # - Output will be in /src/public by default. # - Using --verbose and --debug for more detailed build logs. RUN hugo --gc --minify --verbose --debug # Stage 2: Serve the site with Nginx FROM nginx:1.25-alpine # Copy the built static site from the builder stage's /src/public directory COPY --from=builder /src/public /usr/share/nginx/html # Copy our custom Nginx configuration from the project root (copied in Stage 1) # into the Nginx configuration directory. COPY nginx.conf /etc/nginx/conf.d/default.conf # Expose port 80 EXPOSE 80 # Start Nginx in foreground CMD ["nginx", "-g", "daemon off;"]