blogker/aux/pull-n-build.sh

53 lines
1.1 KiB
Bash
Executable File

#!/bin/sh
# stop on error
set -e -v
{
# Log date
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
# repo already exists, try to pull
cd /repo && git pull --recurse-submodules
if [ "$?" -ne 0 ]; then
# pull failed, clean and retry to clone
echo "Pull failed, attempting to clean clone"
rm -rf /repo
fi
fi
if [ ! -d /repo ]; then
# repo needs to be cloned
# check if there is a specific branch to clone
if [ ! "$REPO_BRANCH" == "" ]; then
BRANCHCMD="--branch $REPO_BRANCH"
fi
git clone --recurse-submodules $BRANCHCMD $REPO_URL /repo
fi
fi
# create temporary working directory
tmpdir=$(mktemp --directory)
# copy over into temporary directory
cp -r /repo/* $tmpdir
# build and copy over
cd $tmpdir && \
hugo && \
rm -rf /usr/share/nginx/html/* && \
cp -R $tmpdir/public/* /usr/share/nginx/html && \
chown nginx:nginx -R /usr/share/nginx/html
# cleanup
rm -rf $tmpdir
} 2>&1 | tee /var/log/blogker-pull-n-build.log