commit fce2368393de4f938b335ac8f11ca4b5a3c4ab9d Author: maride Date: Wed Jul 26 22:22:25 2023 +0200 Init diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1d06d25 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM nginx:mainline-alpine + +# Install hugo +RUN apk add hugo git + +# Copy over auxiliary scripts +COPY aux /aux + +# Cron hook for pulling and building +RUN echo "10 * * * * /aux/pull-n-build.sh" >> /var/spool/cron/crontabs/root + +# bootstrap script, basically cron && build +# after that, the base-image-specific CMD will kick in, which is quite complex +ENTRYPOINT /aux/bootstrap.sh + diff --git a/README.md b/README.md new file mode 100644 index 0000000..b6a120e --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# blogker + +A nginx-powered container hosting a hugo-built blog regularly pulled off git. + +## Run + +`docker run -e REPO_URL=https://git.maride.cc/maride/sec.maride.cc.git -p 80:80 blogker` + diff --git a/aux/bootstrap.sh b/aux/bootstrap.sh new file mode 100755 index 0000000..a38f62c --- /dev/null +++ b/aux/bootstrap.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +# stop on error +set -e + +# start cron daemon (goes into background) +crond + +# pull and build freshly +/aux/pull-n-build.sh + +# run nginx +nginx -g "daemon off;" diff --git a/aux/pull-n-build.sh b/aux/pull-n-build.sh new file mode 100755 index 0000000..2aa2b9b --- /dev/null +++ b/aux/pull-n-build.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +# stop on error +set -e -v + +# check if initial git run +if [ ! -d /repo ]; then + # yes - repo needs to be cloned + git clone --recurse-submodules $REPO_URL /repo +else + # no - pull existing repo + cd /repo && git pull --recurse-submodules +fi + +# build and copy over +cd /repo && \ +hugo && \ +rm -rf /usr/share/nginx/html/* && \ +cp -R /repo/public/* /usr/share/nginx/html +