Skip to content

Commit 2f0d0f2

Browse files
committed
Enhance deployment script to sync infrastructure files and improve service management
- Updated deploy.sh to sync systemd unit and Caddyfile if changes are detected, ensuring the latest configurations are applied. - Added support for forced restarts with a --force option. - Improved pip installation command for desktop dependencies and added no-cache option for efficiency. - Enhanced service restart logic for environnets-xpra to ensure it picks up new code after deployment.
1 parent c3c8817 commit 2f0d0f2

2 files changed

Lines changed: 55 additions & 7 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Deploy sandbox to VM
2+
3+
on:
4+
push:
5+
branches:
6+
- desktop-app
7+
workflow_dispatch:
8+
9+
concurrency:
10+
group: deploy-sandbox
11+
cancel-in-progress: false
12+
13+
jobs:
14+
deploy:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: SSH and run deploy.sh
18+
uses: appleboy/ssh-action@v1.2.0
19+
with:
20+
host: ${{ secrets.DEPLOY_HOST }}
21+
username: ubuntu
22+
key: ${{ secrets.DEPLOY_SSH_KEY }}
23+
port: 22
24+
script_stop: true
25+
script: |
26+
cd ~/environnet-sim
27+
bash deploy/deploy.sh

deploy/deploy.sh

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
2-
# Pull latest, reinstall deps if needed, restart sandbox service.
3-
# Idempotent. Run on the VM.
2+
# Pull latest, sync infra files if changed, restart sandbox service.
3+
# Idempotent. Run on the VM (or by GitHub Actions over SSH).
44
set -euo pipefail
55

66
APP_DIR="${APP_DIR:-$HOME/environnet-sim}"
@@ -12,15 +12,36 @@ REMOTE=$(git rev-parse '@{u}')
1212

1313
if [[ "$LOCAL" == "$REMOTE" ]]; then
1414
echo "Already up to date ($LOCAL)"
15-
exit 0
15+
# Still allow forced restart with --force
16+
if [[ "${1:-}" != "--force" ]]; then
17+
exit 0
18+
fi
1619
fi
1720

1821
echo "==> Pulling $LOCAL -> $REMOTE"
1922
git pull --ff-only
2023

2124
source .venv/bin/activate
22-
pip install -e ".[web]" --quiet
25+
pip install -e ".[desktop]" --quiet --no-cache-dir || \
26+
pip install -e ".[desktop]" --no-cache-dir
2327

24-
sudo systemctl restart environnets-web
25-
echo "==> Restarted. Status:"
26-
systemctl --no-pager status environnets-web --lines=3
28+
# Sync systemd unit if changed
29+
if ! sudo diff -q deploy/environnets-xpra.service /etc/systemd/system/environnets-xpra.service >/dev/null 2>&1; then
30+
echo "==> systemd unit changed, updating"
31+
sudo cp deploy/environnets-xpra.service /etc/systemd/system/environnets-xpra.service
32+
sudo systemctl daemon-reload
33+
fi
34+
35+
# Sync Caddyfile if changed
36+
if ! sudo diff -q deploy/Caddyfile.prod /etc/caddy/Caddyfile >/dev/null 2>&1; then
37+
echo "==> Caddyfile changed, updating + reloading Caddy"
38+
sudo cp deploy/Caddyfile.prod /etc/caddy/Caddyfile
39+
sudo systemctl reload caddy
40+
fi
41+
42+
# Restart sandbox so it picks up new code
43+
echo "==> Restarting environnets-xpra"
44+
sudo systemctl restart environnets-xpra
45+
sleep 4
46+
systemctl --no-pager status environnets-xpra --lines=3
47+
echo "==> Deploy complete."

0 commit comments

Comments
 (0)