refactor: migrate from nixpacks to multi-stage Dockerfile with Nginx for Hugo site deployment
This commit is contained in:
parent
63b96b70eb
commit
4835cba4d2
37
Dockerfile
Normal file
37
Dockerfile
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
# 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;"]
|
||||||
@ -1,20 +0,0 @@
|
|||||||
# Explicitly set the provider to 'static' to help with detection
|
|
||||||
[provider]
|
|
||||||
name = "static"
|
|
||||||
website = "https://gohugo.io/"
|
|
||||||
|
|
||||||
[phases.setup]
|
|
||||||
aptPkgs = ["hugo"]
|
|
||||||
|
|
||||||
[ phases.build ]
|
|
||||||
cmds = ["hugo --minify"]
|
|
||||||
|
|
||||||
[ environment ]
|
|
||||||
HUGO_VERSION = "0.112.3"
|
|
||||||
|
|
||||||
[[ nixpacks.included_files ]]
|
|
||||||
paths = ["/public"]
|
|
||||||
|
|
||||||
# Add a custom plan to ensure the static provider is recognized
|
|
||||||
[plan]
|
|
||||||
providers = ["static"]
|
|
||||||
Loading…
x
Reference in New Issue
Block a user