Update Dockerfile to improve Hugo build logging and Nginx config

This commit is contained in:
Greg 2025-05-25 16:58:40 +02:00
parent 478b1f5b75
commit 698d5a2b2a

View File

@ -8,30 +8,24 @@ RUN apk add --no-cache hugo
WORKDIR /src WORKDIR /src
# Copy the content of the project to the working directory # Copy the content of the project to the working directory
# This includes your Hugo site source, themes, and nginx.conf
COPY . . COPY . .
# Build the Hugo site with ignoreVendorPaths to avoid theme errors # Build the Hugo site.
RUN hugo --ignoreVendorPaths="**" --minify || mkdir -p /src/public && echo "<html><head><title>My New Hugo Site</title></head><body><h1>Welcome to My New Hugo Site!</h1><p>This is a placeholder page. Add a theme or custom content to customize it.</p></body></html>" > /src/public/index.html # - Output will be in /src/public by default.
# - Added --verbose and --debug for more detailed build logs.
# - Removed the '|| mkdir ...' fallback to ensure Hugo errors stop the build and are visible.
RUN hugo --gc --minify --verbose --debug
# Stage 2: Serve the site with Nginx # Stage 2: Serve the site with Nginx
FROM nginx:1.25-alpine FROM nginx:1.25-alpine
# Copy the built static site from the builder stage # Copy the built static site from the builder stage's /src/public directory
COPY --from=builder /src/public /usr/share/nginx/html COPY --from=builder /src/public /usr/share/nginx/html
# Optional: Add custom Nginx configuration optimized for static sites # Copy our custom Nginx configuration from the project root (copied in Stage 1)
RUN echo 'server {\ # into the Nginx configuration directory.
listen 80;\ COPY nginx.conf /etc/nginx/conf.d/default.conf
server_name _;\
root /usr/share/nginx/html;\
index index.html;\
gzip on;\
gzip_types text/plain text/css application/javascript image/svg+xml;\
error_page 404 /404.html;\
location ~* \.(css|js|jpg|jpeg|png|gif|ico|svg)$ {\
expires 30d;\
}\
}' > /etc/nginx/conf.d/default.conf
# Expose port 80 # Expose port 80
EXPOSE 80 EXPOSE 80