diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..c51ae5b --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,24 @@ +FROM nginx:alpine + +ARG HUGO_VERSION +ENV HUGO_VERSION=${HUGO_VERSION} +ENV HUGO_DEST=/usr/share/nginx/html + +# Install git and curl +RUN apk add --no-cache git curl + +# Download Hugo +RUN curl -sSL https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_Linux-64bit.tar.gz \ + | tar -xz -C /usr/local/bin hugo + +# Add entrypoint script +COPY entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh + +# Copy custom nginx config +COPY nginx.conf /etc/nginx/conf.d/default.conf +# Nginx serves on port 80 +EXPOSE 80 + +# Set default entrypoint +ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100644 index 0000000..ebb58ec --- /dev/null +++ b/docker/entrypoint.sh @@ -0,0 +1,16 @@ +#!/bin/sh +set -e + +# Configuration +REPO_URL="${REPO_URL:-https://git.vezpi.me/Vezpi/blog.git}" +BRANCH="${BRANCH:-preview}" +CLONE_DIR="${CLONE_DIR:-/blog}" + +echo "Cloning $REPO_URL (branch: $BRANCH)..." +git clone --depth 1 --branch "$BRANCH" "$REPO_URL" "$CLONE_DIR" + +echo "Building site with Hugo $HUGO_VERSION..." +hugo --source "$CLONE_DIR" --destination "$HUGO_DEST" --cleanDestinationDir + +echo "Starting Nginx..." +exec nginx -g 'daemon off;' \ No newline at end of file diff --git a/docker/nginx.conf b/docker/nginx.conf new file mode 100644 index 0000000..921a03f --- /dev/null +++ b/docker/nginx.conf @@ -0,0 +1,26 @@ +map $http_accept_language $lang { + default en; + ~fr fr; +} + +server { + listen 80; + server_name _; + + root /usr/share/nginx/html; + index index.html; + + # Redirect users to their language home page + rewrite ^/$ /$lang/ redirect; + + location / { + try_files $uri $uri/ =404; + } + + # Custom 404 page + error_page 404 /$lang/404.html; + location = /$lang/404.html { + internal; + } +} +