parent
43dac78dc1
commit
f2c5ea425c
@ -1,85 +0,0 @@ |
|||||||
#!/bin/bash |
|
||||||
|
|
||||||
# Usage: |
|
||||||
# <script> -path <path> [-noGit] |
|
||||||
# * <path>, if present, should point to the path to Hugo root |
|
||||||
# * -noGit will disable git operation |
|
||||||
|
|
||||||
set -e |
|
||||||
|
|
||||||
# https://stackoverflow.com/a/52156612/1040915 |
|
||||||
declare -A flags |
|
||||||
declare -A booleans |
|
||||||
args=() |
|
||||||
|
|
||||||
while [ "$1" ]; |
|
||||||
do |
|
||||||
arg=$1 |
|
||||||
if [ "${1:0:1}" == "-" ] |
|
||||||
then |
|
||||||
shift |
|
||||||
rev=$(echo "$arg" | rev) |
|
||||||
if [ -z "$1" ] || [ "${1:0:1}" == "-" ] || [ "${rev:0:1}" == ":" ] |
|
||||||
then |
|
||||||
bool=$(echo ${arg:1} | sed s/://g) |
|
||||||
booleans[$bool]=true |
|
||||||
# echo \"$bool\" is boolean |
|
||||||
else |
|
||||||
value=$1 |
|
||||||
flags[${arg:1}]=$value |
|
||||||
shift |
|
||||||
# echo \"$arg\" is flag with value \"$value\" |
|
||||||
fi |
|
||||||
else |
|
||||||
args+=("$arg") |
|
||||||
shift |
|
||||||
# echo \"$arg\" is an arg |
|
||||||
fi |
|
||||||
done |
|
||||||
|
|
||||||
if [ -z ${flags["path"]} ]; then |
|
||||||
path="blog"; |
|
||||||
else |
|
||||||
path=${flags["path"]}; |
|
||||||
fi |
|
||||||
|
|
||||||
# https://stackoverflow.com/a/56841359/1040915 |
|
||||||
if [[ -z "${booleans['noGit']:-}" ]]; then |
|
||||||
# This assumes that the blog content is within the Git repo which contains the script location. |
|
||||||
# https://unix.stackexchange.com/a/155077/30828 |
|
||||||
if [ -n "$(git status --porcelain)" ]; then |
|
||||||
echo "Working directory not clean - aborting"; |
|
||||||
exit |
|
||||||
fi |
|
||||||
|
|
||||||
git push |
|
||||||
fi |
|
||||||
|
|
||||||
hugo --quiet --source $path |
|
||||||
|
|
||||||
docker_image_tag="scubbo/blog_nginx" |
|
||||||
docker_instance_name="blog_nginx" |
|
||||||
|
|
||||||
cp -r $path/public ./builtContent |
|
||||||
docker build -t $docker_image_tag . -f-<<EOF |
|
||||||
FROM nginxinc/nginx-unprivileged |
|
||||||
COPY builtContent /usr/share/nginx/html |
|
||||||
EOF |
|
||||||
|
|
||||||
if [[ $(docker ps --filter "name=$docker_instance_name" | wc -l) -lt 2 ]]; then |
|
||||||
echo "No currently running blog" |
|
||||||
else |
|
||||||
docker kill $docker_instance_name |
|
||||||
docker rm $docker_instance_name |
|
||||||
fi |
|
||||||
|
|
||||||
docker run --name $docker_instance_name -p 8108:8080 \ |
|
||||||
--mount type=bind,source="$(pwd)"/default.conf,target=/etc/nginx/conf.d/default.conf \ |
|
||||||
-d $docker_image_tag |
|
||||||
# TODO - call Cloudflare's CDN API to explicitly purge cache on the index page |
|
||||||
# TODO - (more of a stretch) and parse the `git push` output to purge cache on updated pages, too |
|
||||||
# TODO - do the "docker kill and restart" more idiomatically - there must be a "proper" way to do it! |
|
||||||
# ...it's probably k8s, isn't it :) |
|
||||||
|
|
||||||
rm -rf builtContent |
|
||||||
|
|
Loading…
Reference in new issue