From 4835cba4d26532b71425f5baca6a96d563c8e25f Mon Sep 17 00:00:00 2001 From: Greg Date: Sun, 25 May 2025 16:16:18 +0200 Subject: [PATCH] refactor: migrate from nixpacks to multi-stage Dockerfile with Nginx for Hugo site deployment --- Dockerfile | 37 +++++++++++++++++++++++++++++++++++++ nixpacks.toml | 20 -------------------- 2 files changed, 37 insertions(+), 20 deletions(-) create mode 100644 Dockerfile delete mode 100644 nixpacks.toml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..98926af --- /dev/null +++ b/Dockerfile @@ -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;"] diff --git a/nixpacks.toml b/nixpacks.toml deleted file mode 100644 index 6a6b509..0000000 --- a/nixpacks.toml +++ /dev/null @@ -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"] \ No newline at end of file