63 lines
1.3 KiB
Bash
63 lines
1.3 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
# Simple Continuous Deployment script
|
|
# - Compares hashes of the local and remote main git branches
|
|
# - Pulls changes if needed
|
|
# - If changes was pulled, builds and deploys them
|
|
|
|
# TODO
|
|
# - Configuration to use with a specific git branch
|
|
# - Replace hard coded variables with script arguments
|
|
|
|
# Crontab entry:
|
|
# * * * * * bash /usr/local/bin/static-site-continious-deployment.sh >> /var/log/deploy-cuqmbr-xyz.log 2>&1
|
|
|
|
set -Eeuo pipefail
|
|
trap 's=$?; echo >&2 "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR
|
|
|
|
|
|
GIT_REPO_PATH="/opt/cuqmbr.xyz.git"
|
|
DEPLOY_PATH="/var/www/cuqmbr.xyz"
|
|
|
|
|
|
build() {
|
|
touch cron-lock
|
|
|
|
# Replace with your build script
|
|
hugo
|
|
|
|
rm cron-lock
|
|
}
|
|
|
|
deploy() {
|
|
# Replace with your deployment strategy
|
|
ln -snfv ${GIT_REPO_PATH}/public ${DEPLOY_PATH}
|
|
}
|
|
|
|
|
|
# Initial deployment
|
|
|
|
if [ ! -d ${GIT_REPO_PATH} ]; then
|
|
git clone --recurse-submodules 'https://gitea.cuqmbr.xyz/cuqmbr/cuqmbr.xyz.git' ${GIT_REPO_PATH}
|
|
cd ${GIT_REPO_PATH}
|
|
build
|
|
deploy
|
|
exit 0
|
|
fi
|
|
|
|
|
|
# Periodic updates
|
|
|
|
cd ${GIT_REPO_PATH}
|
|
|
|
git remote update
|
|
LOCAL_COMMIT=$(git rev-parse @)
|
|
REMOTE_COMMIT=$(git rev-parse @{u})
|
|
|
|
if [ "$LOCAL_COMMIT" != "$REMOTE_COMMIT" ]; then
|
|
git reset --hard 'origin/main'
|
|
rm -Rf public
|
|
build
|
|
deploy
|
|
fi
|