MyFavStuff5/Dockerfile

45 lines
1.5 KiB
Docker

# Stage 1: Build the Hugo site
FROM alpine:3.19 AS builder
# Install dependencies
RUN apk add --no-cache wget tar jq curl
# Install latest Hugo extended version
RUN LATEST_RELEASE=$(curl -s https://api.github.com/repos/gohugoio/hugo/releases/latest | jq -r '.tag_name') && \
VERSION=${LATEST_RELEASE#v} && \
echo "Installing latest Hugo version: $VERSION" && \
wget https://github.com/gohugoio/hugo/releases/download/${LATEST_RELEASE}/hugo_extended_${VERSION}_linux-amd64.tar.gz -O hugo.tar.gz && \
tar -xzf hugo.tar.gz -C /usr/local/bin/ && \
rm hugo.tar.gz && \
chmod +x /usr/local/bin/hugo && \
hugo version
# Set the working directory in the container
WORKDIR /src
# Copy the content of the project to the working directory
# This includes your Hugo site source, themes, and nginx.conf
COPY . .
# Build the Hugo site.
# - Output will be in /src/public by default.
# - Added --verbose and --debug for more detailed build logs.
# - Removed the '|| mkdir ...' fallback to ensure Hugo errors stop the build and are visible.
RUN hugo --gc --minify --logLevel info --logLevel debug
# Stage 2: Serve the site with Nginx
FROM nginx:1.25-alpine
# Copy the built static site from the builder stage's /src/public directory
COPY --from=builder /src/public /usr/share/nginx/html
# Copy our custom Nginx configuration from the project root (copied in Stage 1)
# into the Nginx configuration directory.
COPY nginx.conf /etc/nginx/conf.d/default.conf
# Expose port 80
EXPOSE 80
# Start Nginx in foreground
CMD ["nginx", "-g", "daemon off;"]