-
Notifications
You must be signed in to change notification settings - Fork 0
81 lines (67 loc) · 2.54 KB
/
deploy.yml
File metadata and controls
81 lines (67 loc) · 2.54 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
name: Deploy to Production
on:
push:
branches: [mainline]
workflow_dispatch:
# Only one deployment at a time
concurrency:
group: deploy-production
cancel-in-progress: false
permissions:
contents: read
jobs:
deploy:
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build
env:
VITE_MAPBOX_TOKEN: ${{ secrets.VITE_MAPBOX_TOKEN }}
VITE_ESRI_API_KEY: ${{ secrets.VITE_ESRI_API_KEY }}
run: npm run build
- name: Create deployment package
run: tar -czf webmap-deploy.tar.gz -C dist .
- name: Setup SSH key
run: |
mkdir -p ~/.ssh
echo "${{ secrets.DEPLOY_KEY }}" > ~/.ssh/deploy_key
chmod 600 ~/.ssh/deploy_key
ssh-keyscan -H ${{ secrets.DEPLOY_HOST }} >> ~/.ssh/known_hosts 2>/dev/null || true
- name: Deploy
run: |
SSH_OPTS="-i ~/.ssh/deploy_key -o ConnectTimeout=60 -o ServerAliveInterval=30"
SSH_TARGET="${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}"
VERSION=$(node -p "require('./package.json').version")
source "$GITHUB_WORKSPACE/scripts/ssh-retry.sh"
ssh_retry "scp $SSH_OPTS scripts/deploy-webmap.sh $SSH_TARGET:/tmp/deploy-webmap.sh"
ssh_retry "cat webmap-deploy.tar.gz | ssh $SSH_OPTS $SSH_TARGET 'DEPLOY_SHA=${{ github.sha }} DEPLOY_VERSION=$VERSION bash /tmp/deploy-webmap.sh'"
- name: Cleanup SSH key
if: always()
run: rm -f ~/.ssh/deploy_key
- name: Smoke test
run: |
echo "Waiting 5s for nginx to settle..."
sleep 5
MAX_RETRIES=6
RETRY_DELAY=10
for i in $(seq 1 $MAX_RETRIES); do
HTTP_CODE=$(curl -sf --max-time 15 -o /dev/null -w '%{http_code}' "https://www.webmap.dev" 2>/dev/null || echo '0')
if [ "$HTTP_CODE" = "200" ]; then
echo "Smoke test passed (HTTP $HTTP_CODE)"
break
fi
if [ "$i" = "$MAX_RETRIES" ]; then
echo "::error::Smoke test failed after $MAX_RETRIES attempts (last HTTP code: $HTTP_CODE)"
exit 1
fi
echo "Attempt $i: HTTP $HTTP_CODE, retrying in ${RETRY_DELAY}s..."
sleep $RETRY_DELAY
done