FROM hugomods/hugo:exts AS builder
WORKDIR /src

COPY archetypes/ archetypes/
COPY themes/ themes/
COPY layouts/ layouts/
COPY static/ static/
COPY assets/ assets/
COPY content/ content/
COPY hugo.toml .

RUN hugo --gc --minify

FROM alpine:3.20 AS video-posters

RUN apk add --no-cache python3 ffmpeg

WORKDIR /src

COPY --from=builder /src/public /src/public
COPY scripts/add-video-posters.py /add-video-posters.py

RUN python3 /add-video-posters.py /src/public

FROM nginx:alpine

RUN apk add --no-cache openssl

COPY --from=video-posters /src/public /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY docker-entrypoint.sh /docker-entrypoint.sh

RUN chmod +x /docker-entrypoint.sh

EXPOSE 80

ENTRYPOINT ["/docker-entrypoint.sh"]
