# builder
FROM hugomods/hugo:base-non-root AS builder
ARG BASE_URL ""
ARG RELEASETAG "unset"
# --chown is required since kaniko in woodpecker otherwise copies as root and 
# the hugo command below fails since it is executed as hugo
COPY --chown=hugo:hugo content/ /src
RUN sed -i 's/%RELEASETAG%/'${RELEASETAG}'/' /src/content/about.md
RUN if [ "$BASE_URL" = ""]; then hugo; else hugo -b $BASE_URL; fi 

# server
FROM nginx:alpine
COPY --from=builder /src/public /usr/share/nginx/html
RUN \
  chown -R nobody:nobody /var/cache/nginx /var/log/nginx && \
  sed -i 's/listen\s\+80;/listen 8080;/' /etc/nginx/conf.d/default.conf && \
  sed -i 's,pid\s\+/var/run/nginx.pid;,pid /tmp/nginx.pid;,' /etc/nginx/nginx.conf
USER nobody
EXPOSE 8080





