# Stage 1
FROM alpine:latest AS base

FROM base AS hugo
# Install the Hugo go app.
RUN apk add --update curl

ARG TARGETARCH
ARG HUGO_VERSION=0.161.1
RUN wget -O "hugo.tar.gz" "https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-${TARGETARCH}.tar.gz"
RUN tar -xf "hugo.tar.gz" hugo -C /usr/bin

FROM base AS build

COPY --from=hugo /usr/bin/hugo /bin/hugo

RUN apk add --update git libc6-compat libstdc++

WORKDIR /opt/HugoApp

# Copy Hugo config into the container Workdir.
COPY . .

RUN git submodule update --init --recursive

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

# Stage 2
FROM nginx:1.25-alpine

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

# Copy HTML from previous build into the Workdir.
COPY --from=build /opt/HugoApp/public .

# Expose port 80
EXPOSE 80/tcp
