Allow passthrough repos using bind mounts, work in temp directory, log to screen and file
This commit is contained in:
parent
159dbe4b34
commit
89571e99dd
15
README.md
15
README.md
@ -4,5 +4,18 @@ A nginx-powered container hosting a hugo-built blog regularly pulled off git.
|
|||||||
|
|
||||||
## Run
|
## 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.
|
||||||
|
@ -8,18 +8,35 @@ set -e -v
|
|||||||
date
|
date
|
||||||
|
|
||||||
# check if initial git run
|
# check if initial git run
|
||||||
if [ ! -d /repo ]; then
|
if [ "$REPO_URL" == "" ]; then
|
||||||
# yes - repo needs to be cloned
|
# no repo URL set.
|
||||||
git clone --recurse-submodules $REPO_URL /repo
|
# most likely the repo is passed through as volume
|
||||||
|
# do not pull, treat the repo as-is
|
||||||
|
true
|
||||||
else
|
else
|
||||||
# no - pull existing repo
|
# repo URL set
|
||||||
cd /repo && git pull --recurse-submodules
|
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
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# create temporary working directory
|
||||||
|
tmpdir=$(mktemp --directory)
|
||||||
|
# copy over into temporary directory
|
||||||
|
cp -r /repo/* $tmpdir
|
||||||
|
|
||||||
# build and copy over
|
# build and copy over
|
||||||
cd /repo && \
|
cd $tmpdir && \
|
||||||
hugo && \
|
hugo && \
|
||||||
rm -rf /usr/share/nginx/html/* && \
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user