38 lines
927 B
Docker
38 lines
927 B
Docker
# Stage 1: Build the Hugo site
|
|
FROM klakegg/hugo:0.112.3-alpine AS builder
|
|
|
|
# Set the working directory in the container
|
|
WORKDIR /src
|
|
|
|
# Copy the content of the project to the working directory
|
|
COPY . .
|
|
|
|
# Build the Hugo site
|
|
RUN hugo --minify
|
|
|
|
# Stage 2: Serve the site with Nginx
|
|
FROM nginx:1.25-alpine
|
|
|
|
# Copy the built static site from the builder stage
|
|
COPY --from=builder /src/public /usr/share/nginx/html
|
|
|
|
# Optional: Add custom Nginx configuration optimized for static sites
|
|
RUN echo 'server {\
|
|
listen 80;\
|
|
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 80
|
|
|
|
# Start Nginx in foreground
|
|
CMD ["nginx", "-g", "daemon off;"]
|