summaryrefslogtreecommitdiff
path: root/deployment/post-receive
blob: 164779433e697476e33983c7391c6cf1017b7b19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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!"