diff options
Diffstat (limited to 'deployment/post-receive')
| -rw-r--r-- | deployment/post-receive | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/deployment/post-receive b/deployment/post-receive new file mode 100644 index 0000000..1647794 --- /dev/null +++ b/deployment/post-receive @@ -0,0 +1,44 @@ +#!/bin/bash +set -e + +# Server-side deploy hook for /site/doot.terst.org +# Install: cp deployment/post-receive /site/doot.terst.org/app-code/hooks/post-receive && chmod +x /site/doot.terst.org/app-code/hooks/post-receive + +FQDN="doot.terst.org" +SITE_DIR="/site/${FQDN}" +REPO_DIR="${SITE_DIR}/app-code" +CHECKOUT_DIR="${SITE_DIR}/checkout" +SERVICE="task-dashboard@${FQDN}" + +echo "==> Deploying ${FQDN}..." + +echo "Stopping service..." +systemctl stop ${SERVICE} || true + +echo "Checking out code..." +mkdir -p ${CHECKOUT_DIR} +GIT_WORK_TREE=${CHECKOUT_DIR} git --git-dir=${REPO_DIR} checkout -f master + +echo "Building binary..." +cd ${CHECKOUT_DIR} +GOOS=linux GOARCH=amd64 go build -o ${SITE_DIR}/app cmd/dashboard/main.go + +echo "Syncing static files..." +rsync -a --delete ${CHECKOUT_DIR}/web/static/ ${SITE_DIR}/public/ + +echo "Syncing templates..." +rsync -a --delete ${CHECKOUT_DIR}/web/templates/ ${SITE_DIR}/templates/ + +echo "Setting permissions..." +chown -R www-data:www-data ${SITE_DIR} +find ${SITE_DIR} -type d -exec chmod 755 {} \; +find ${SITE_DIR} -type f -exec chmod 644 {} \; +chmod +x ${SITE_DIR}/app +chmod 600 ${SITE_DIR}/.env 2>/dev/null || true + +echo "Starting service..." +systemctl start ${SERVICE} +sleep 1 +systemctl status ${SERVICE} --no-pager -l + +echo "==> Deploy complete!" |
