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
|
|
|
|
if [ ! -d /repo ]; then
|
|
|
|
# repo needs to be cloned
|
|
|
|
git clone --recurse-submodules $REPO_URL /repo
|
|
|
|
else
|
|
|
|
# no - pull existing repo
|
|
|
|
cd /repo && git pull --recurse-submodules
|
|
|
|
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
|