##
## Step 1 - add content and build with Hugo
##

FROM debian:stretch as hugo
RUN apt-get -qq update \
	&& DEBIAN_FRONTEND=noninteractive apt-get -qq install -y --no-install-recommends python-pygments git ca-certificates ruby \
	&& rm -rf /var/lib/apt/lists/* \
	&& gem install asciidoctor pygments.rb

ENV HUGO_VERSION 0.54.0
ENV HUGO_BINARY hugo_extended_${HUGO_VERSION}_Linux-64bit.deb

ADD https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/${HUGO_BINARY} /tmp/hugo.deb
RUN dpkg -i /tmp/hugo.deb \
	&& rm /tmp/hugo.deb

ADD . /tmp/site
RUN hugo -b https://kb.chameth.com/ -v -s /tmp/site -d /tmp/hugo && \
	cp /tmp/hugo/index.xml /tmp/hugo/feed.xml

##
## Step 3 - host!
##

FROM nginx:mainline-alpine AS nginx
RUN rm -rf /usr/share/nginx/html/*
COPY --from=hugo /tmp/hugo /usr/share/nginx/html
ADD nginx.conf /etc/nginx/nginx.conf
