forked from rotkonetworks/w3registrar
-
Notifications
You must be signed in to change notification settings - Fork 1
55 lines (46 loc) · 1.62 KB
/
rollback.yaml
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
name: Rollback Deployment
env:
SERVER_USER: 'w3reg'
SERVER_IP: '135.181.202.179'
DEPLOY_PATH: '/home/w3reg/app.w3reg.org'
BACKUP_PATH: '/home/w3reg/backups'
on:
workflow_dispatch:
jobs:
rollback:
runs-on: ubuntu-latest
steps:
- name: Set up SSH agent
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Add SSH Key to Known Hosts
run: |
mkdir -p ~/.ssh
ssh-keyscan -t ed25519 ${{ env.SERVER_IP }} >> ~/.ssh/known_hosts
chmod 644 ~/.ssh/known_hosts
- name: Rollback to Previous Deployment
run: |
ssh ${{ env.SERVER_USER }}@${{ env.SERVER_IP }} << EOF
set -euo pipefail
# Check for the latest backup
if [ ! -d "${{ env.BACKUP_PATH }}" ]; then
echo "No backups found. Cannot rollback." >&2
exit 1
fi
LATEST_BACKUP=\$(ls -td ${{ env.BACKUP_PATH }}/w3registrar-www-* | head -n 1)
if [ -z "\$LATEST_BACKUP" ]; then
echo "No valid backups found. Cannot rollback." >&2
exit 1
fi
# Move current deployment to backup
TIMESTAMP=\$(date +%Y%m%d%H%M%S)
if [ -d "${{ env.DEPLOY_PATH }}" ]; then
mv ${{ env.DEPLOY_PATH }}${{ env.BACKUP_PATH }}/w3registrar-www-\$TIMESTAMP
fi
# Restore the latest backup
mv \$LATEST_BACKUP ${{ env.DEPLOY_PATH }}
# Restart services
cd ${{ env.DEPLOY_PATH }}
docker compose up --build -d web-nginx
EOF