MyFavStuff5/Dockerfile

41 lines
1.2 KiB
Docker

# Stage 1: Build the Hugo site
FROM alpine:3.19 AS builder
# Install Hugo
RUN apk add --no-cache hugo
# Set the working directory in the container
WORKDIR /src
# Copy the content of the project to the working directory
COPY . .
# Build the Hugo site with ignoreVendorPaths to avoid theme errors
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
# 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;"]