Allow passthrough repos using bind mounts, work in temp directory, log to screen and file

This commit is contained in:
maride 2023-08-28 23:40:36 +02:00
parent 159dbe4b34
commit 89571e99dd
2 changed files with 39 additions and 9 deletions

View File

@ -4,5 +4,18 @@ 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`
### Auto-Pull Git
If you store your blog data in a git repository, run the container with env `REPO_URL` set to a Git repo:
`docker run -e REPO_URL=https://git.maride.cc/maride/sec.maride.cc.git -p 80:80 -d blogker`
The repository will be pulled and built every 10 minutes.
### Passthrough via Bind
To just use a specific directory as the hugo blog contents, run the container with the repository passed through as bind directory:
`docker run -v /var/myblog:/repo -p 80:80 -d blogker`
The repository will be built every 10 minutes, but you need to implement a mechanism to update the blog repository on your own. This setup can be handy in a testing/dev environment where you don't want to have all your blog posts published right away.

View File

@ -8,18 +8,35 @@ set -e -v
date
# check if initial git run
if [ "$REPO_URL" == "" ]; then
# no repo URL set.
# most likely the repo is passed through as volume
# do not pull, treat the repo as-is
true
else
# repo URL set
if [ ! -d /repo ]; then
# yes - repo needs to be cloned
# repo needs to be cloned
git clone --recurse-submodules $REPO_URL /repo
else
# no - pull existing repo
cd /repo && git pull --recurse-submodules
fi
fi
# create temporary working directory
tmpdir=$(mktemp --directory)
# copy over into temporary directory
cp -r /repo/* $tmpdir
# build and copy over
cd /repo && \
cd $tmpdir && \
hugo && \
rm -rf /usr/share/nginx/html/* && \
cp -R /repo/public/* /usr/share/nginx/html
cp -R $tmpdir/public/* /usr/share/nginx/html && \
chown nginx:nginx -R /usr/share/nginx/html
} 2>&1 > /var/log/blogker-pull-n-build.log
# cleanup
rm -rf $tmpdir
} 2>&1 | tee /var/log/blogker-pull-n-build.log