2023-07-26 20:22:25 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# stop on error
|
|
|
|
set -e -v
|
|
|
|
|
2023-07-28 07:18:39 +00:00
|
|
|
{
|
|
|
|
# Log date
|
|
|
|
date
|
2023-07-26 20:22:25 +00:00
|
|
|
|
2023-07-28 07:18:39 +00:00
|
|
|
# check if initial git run
|
2023-08-28 21:40:36 +00:00
|
|
|
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
|
2023-07-28 07:18:39 +00:00
|
|
|
else
|
2023-08-28 21:40:36 +00:00
|
|
|
# repo URL set
|
2023-10-14 13:31:43 +00:00
|
|
|
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
|
2023-08-28 21:40:36 +00:00
|
|
|
if [ ! -d /repo ]; then
|
|
|
|
# repo needs to be cloned
|
2023-09-09 17:35:43 +00:00
|
|
|
# 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
|
2023-08-28 21:40:36 +00:00
|
|
|
fi
|
2023-07-28 07:18:39 +00:00
|
|
|
fi
|
2023-07-26 20:22:25 +00:00
|
|
|
|
2023-08-28 21:40:36 +00:00
|
|
|
# create temporary working directory
|
|
|
|
tmpdir=$(mktemp --directory)
|
|
|
|
# copy over into temporary directory
|
|
|
|
cp -r /repo/* $tmpdir
|
|
|
|
|
2023-07-28 07:18:39 +00:00
|
|
|
# build and copy over
|
2023-08-28 21:40:36 +00:00
|
|
|
cd $tmpdir && \
|
2023-07-28 07:18:39 +00:00
|
|
|
hugo && \
|
|
|
|
rm -rf /usr/share/nginx/html/* && \
|
2023-08-28 21:40:36 +00:00
|
|
|
cp -R $tmpdir/public/* /usr/share/nginx/html && \
|
|
|
|
chown nginx:nginx -R /usr/share/nginx/html
|
|
|
|
|
|
|
|
# cleanup
|
|
|
|
rm -rf $tmpdir
|
2023-07-28 07:18:39 +00:00
|
|
|
|
2023-08-28 21:40:36 +00:00
|
|
|
} 2>&1 | tee /var/log/blogker-pull-n-build.log
|