# Copyright 2024 Massimo Girondi massimo@girondi.net
# GNU GPL v3 license
# Package a Hugo website as a minimal Docker container

FROM alpine:latest AS build

# Install the Hugo go app.
RUN apk add --update hugo git bash sed

WORKDIR /workspace

# Copy Hugo config into the container
COPY . .

# Run Hugo in the Workdir to generate HTML.
RUN hugo 

WORKDIR /workspace/public
RUN bash ../generate_nginx_conf.sh > /workspace/default.conf

# Stage 2
FROM nginx:stable-alpine

# Set workdir to the NGINX default dir.
WORKDIR /usr/share/nginx/html

# Copy HTML from previous build into the Workdir.
COPY --from=build /workspace/public .
COPY --from=build /workspace/default.conf /etc/nginx/conf.d/default.conf
RUN rm -rf _redirects

# Expose port 80
EXPOSE 80/tcp

