-
Notifications
You must be signed in to change notification settings - Fork 0
133 lines (115 loc) · 4.18 KB
/
Copy pathdeploy-production.yml
File metadata and controls
133 lines (115 loc) · 4.18 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
name: Deploy Planprice Production
on:
push:
branches: [main]
paths-ignore:
- 'docs/**'
- '*.md'
- '.github/workflows/data-audit.yml'
- '.github/workflows/scrape-pricing.yml'
workflow_dispatch:
permissions:
contents: read
concurrency:
group: planprice-production-deploy
cancel-in-progress: false
env:
NODE_VERSION: '22'
jobs:
verify:
name: Verify release
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: npm
- name: Install dependencies
run: npm ci
- name: Lint
continue-on-error: true
run: npm run lint
- name: Build production bundle
env:
NEXT_PUBLIC_GA_ID: ${{ vars.NEXT_PUBLIC_GA_ID }}
run: npm run build
deploy:
name: Deploy to devbox
needs: verify
runs-on: [self-hosted, planprice-production]
timeout-minutes: 25
environment: Production
env:
DEPLOY_PATH: ${{ vars.DEPLOY_PATH || '/opt/x2v/planprice' }}
steps:
- name: Checkout release
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Validate runner access
run: |
set -euo pipefail
test -d "$DEPLOY_PATH"
sudo -n docker version --format '{{.Server.Version}}'
sudo -n test -r "$DEPLOY_PATH/deploy/production/.env.production"
- name: Create release archive
run: git archive --format=tar.gz --output="$RUNNER_TEMP/planprice-${GITHUB_SHA}.tar.gz" "$GITHUB_SHA"
- name: Roll out release on devbox
run: |
set -euo pipefail
base="$DEPLOY_PATH"
release_dir="$base/.releases/$GITHUB_SHA"
archive="$RUNNER_TEMP/planprice-$GITHUB_SHA.tar.gz"
env_file="$base/deploy/production/.env.production"
test -d "$base"
sudo -n test -r "$env_file"
# The timer uses the same stable directory inode as its flock target.
exec 9<"$base"
flock -w 1800 9
case "$release_dir" in
"$base/.releases/"*) ;;
*) echo "Unsafe release directory: $release_dir" >&2; exit 1 ;;
esac
sudo -n rm -rf "$release_dir"
sudo -n mkdir -p "$release_dir"
sudo -n tar -xzf "$archive" -C "$release_dir"
sudo -n install -m 0600 "$env_file" "$release_dir/deploy/production/.env.production"
sudo -n chown -R root:root "$release_dir"
sudo -n env \
DEPLOY_DIR="$release_dir" \
COMPOSE_FILE="$release_dir/deploy/production/compose.yml" \
ENV_FILE="$release_dir/deploy/production/.env.production" \
DOCKER_CMD=/usr/bin/docker \
LOCK_PATH="$base" \
BUILD_SCRAPER=1 \
"$release_dir/deploy/production/rollout.sh" "$GITHUB_SHA"
sudo -n rsync -a \
--exclude='deploy/production/.env.production' \
"$release_dir/" "$base/"
sudo -n chown root:root "$base/Dockerfile" "$base/deploy/production/rollout.sh" 2>/dev/null || true
sudo -n install -m 0644 "$base/deploy/production/planprice-scraper.service" \
/etc/systemd/system/planprice-scraper.service
sudo -n install -m 0644 "$base/deploy/production/planprice-scraper.timer" \
/etc/systemd/system/planprice-scraper.timer
sudo -n systemctl daemon-reload
sudo -n systemctl enable planprice-scraper.timer
sudo -n systemctl restart planprice-scraper.timer
sudo -n docker compose -p planprice-production \
-f "$base/deploy/production/compose.yml" \
--env-file "$env_file" ps
curl -fsS https://aiplans.dev/api/health
sudo -n rm -rf "$release_dir"
- name: Deployment summary
if: always()
run: |
{
echo '## Planprice production deployment'
echo
echo "Commit: \`$GITHUB_SHA\`"
echo "Target: \`$DEPLOY_PATH\`"
echo "Health: https://aiplans.dev/api/health"
} >> "$GITHUB_STEP_SUMMARY"