-
-
Notifications
You must be signed in to change notification settings - Fork 47
59 lines (48 loc) · 1.88 KB
/
deployment.yml
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
name: Deployment
on:
push:
branches: [ main ]
workflow_dispatch:
jobs:
pre_commit_ci:
uses: vutfitdiscord/rubbergod/.github/workflows/lint.yml@main
deployment_production:
runs-on: ubuntu-latest
environment: Production
needs: pre_commit_ci
if: github.ref == 'refs/heads/main' && !contains(github.event.pull_request.labels.*.name, 'no-deployment')
steps:
- name: Execute deployment on SSH
uses: appleboy/[email protected]
with:
host: ${{ secrets.PRODUCTION_HOST }}
key: ${{ secrets.PRODUCTION_SSH_KEY }}
username: ${{ secrets.PRODUCTION_USERNAME }}
port: 22
script: |
echo "================== Lock Mutex =================="
LOCK="/tmp/deployment.lock"
remove_lock()
{
rm -f "$LOCK"
}
acquire_failed()
{
echo "Failed to acquire lock, perphaps a stale deployment is running requiring manual fix?"
exit 1
}
# !IMPORTANT: For this to work, the remote server has to have `procmail` installed.
# Try to lock 5 times with a 60s sleep time between retries
# Remove any lock older than 10min (600s) and then wait 30s
lockfile -60 -r 5 -l 600 -s 30 "$LOCK" || acquire_failed
# Remove lock on exit
trap remove_lock EXIT
echo "================== Pull Changes =================="
cd rubbergod
git pull
echo "================== Build Image =================="
docker build . --tag rubbergod-bot
echo "================== Restart Services =================="
docker compose down && docker compose up -d
echo "================== Clean Up Images =================="
echo "y" | docker image prune -a