-
Notifications
You must be signed in to change notification settings - Fork 18
executable file
·176 lines (144 loc) · 6.21 KB
/
deploy.yml
File metadata and controls
executable file
·176 lines (144 loc) · 6.21 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
name: Deploy to Production
on:
push:
branches:
- version-16
concurrency:
group: production-deploy
cancel-in-progress: false
permissions:
contents: read
env:
BENCH_PATH: ${{ secrets.BENCH_PATH || '/home/frappe/frappe-bench' }}
SITE_NAME: ${{ secrets.SITE_NAME }}
jobs:
deploy:
name: Deploy to Production
runs-on: ubuntu-latest
environment: pos.xconsol.com
timeout-minutes: 30
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Validate deployment secrets
run: |
set -e
missing=""
if [ -z "${{ secrets.SERVER_HOST }}" ]; then missing="$missing SERVER_HOST"; fi
if [ -z "${{ secrets.SERVER_USER }}" ]; then missing="$missing SERVER_USER"; fi
if [ -z "${{ secrets.SERVER_SSH_KEY }}" ]; then missing="$missing SERVER_SSH_KEY"; fi
if [ -z "${{ secrets.SITE_NAME }}" ]; then missing="$missing SITE_NAME"; fi
if [ -n "$missing" ]; then
echo "::error::Missing required secrets:$missing"
exit 1
fi
echo "✓ All required secrets are configured"
- name: "Deploy: Frappe app with integrated Vue frontend"
uses: appleboy/ssh-action@v1.2.0
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_SSH_KEY }}
port: ${{ secrets.SERVER_PORT || 22 }}
command_timeout: 20m
script: |
set -e
BENCH_PATH="${{ env.BENCH_PATH }}"
SITE_NAME="${{ secrets.SITE_NAME }}"
APP_NAME="xpos"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
echo "============================================"
echo " xpos Production Deployment"
echo " Started: $(date -u '+%Y-%m-%d %H:%M:%S UTC')"
echo " Bench: ${BENCH_PATH}"
echo " Site: ${SITE_NAME}"
echo "============================================"
echo ""
echo ">>> [1/7] Navigating to bench directory..."
cd "${BENCH_PATH}" || { echo "::error::Bench path not found: ${BENCH_PATH}"; exit 1; }
echo " Working directory: $(pwd)"
echo ""
echo ">>> [2/7] Pulling latest code for ${APP_NAME}..."
cd "apps/${APP_NAME}"
git fetch upstream version-16
git reset --hard upstream/version-16
echo " Commit: $(git rev-parse --short HEAD)"
echo " Message: $(git log -1 --pretty=%s)"
cd "${BENCH_PATH}"
echo ""
echo ">>> [3/7] Enabling maintenance mode..."
bench --site "${SITE_NAME}" set-maintenance-mode on || true
echo ""
echo ">>> [4/7] Creating pre-deployment backup..."
bench --site "${SITE_NAME}" backup --with-files 2>&1 | tail -3
echo " Backup completed at: $(date -u '+%H:%M:%S UTC')"
echo ""
echo ">>> [5/7] Installing dependencies and running migrations..."
# Python dependencies
echo " Installing Python dependencies..."
"${BENCH_PATH}/env/bin/pip" install -q -e "apps/${APP_NAME}" 2>&1 | tail -2
# Node dependencies (for bench build)
echo " Installing Node dependencies..."
if [ -f "apps/${APP_NAME}/frontend/package.json" ]; then
cd "apps/${APP_NAME}/frontend"
test -f yarn.lock || { echo "ERROR: apps/${APP_NAME}/frontend/yarn.lock is missing"; exit 1; }
yarn install --frozen-lockfile --production=false 2>&1 | tail -3
cd "${BENCH_PATH}"
fi
# Database migrations
echo " Running database migrations..."
bench --site "${SITE_NAME}" migrate 2>&1 | tail -5
echo " Migrations completed at: $(date -u '+%H:%M:%S UTC')"
echo ""
echo ">>> [6/7] Building frontend assets..."
bench build --app "${APP_NAME}" 2>&1 | tail -10
echo " Build completed at: $(date -u '+%H:%M:%S UTC')"
echo ""
echo ">>> [7/7] Restarting services..."
# Clear cache first
bench --site "${SITE_NAME}" clear-cache
bench --site "${SITE_NAME}" clear-website-cache
# Graceful restart
bench restart 2>&1 | head -20 || sudo supervisorctl restart all 2>&1 | head -20 || true
# Disable maintenance mode
bench --site "${SITE_NAME}" set-maintenance-mode off || true
echo ""
echo "============================================"
echo " Deployment completed successfully!"
echo " Finished: $(date -u '+%Y-%m-%d %H:%M:%S UTC')"
echo " Commit: $(cd apps/${APP_NAME} && git rev-parse --short HEAD)"
echo "============================================"
health-check:
name: Post-Deployment Health Check
runs-on: ubuntu-latest
environment: pos.xconsol.com
needs: deploy
if: success()
timeout-minutes: 5
steps:
- name: Wait for services to stabilize
run: sleep 30
- name: Health check via SSH
uses: appleboy/ssh-action@v1.2.0
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_SSH_KEY }}
port: ${{ secrets.SERVER_PORT || 22 }}
command_timeout: 5m
script: |
BENCH_PATH="${{ env.BENCH_PATH }}"
SITE_NAME="${{ secrets.SITE_NAME }}"
echo ">>> Post-deployment health check..."
# Check supervisor processes
echo " Checking supervisor processes..."
sudo supervisorctl status 2>/dev/null | grep -E "RUNNING|FATAL|STOPPED" || echo " (skipped - sudo not available)"
# Check if bench doctor reports issues
echo " Running bench doctor..."
cd "${BENCH_PATH}"
bench doctor 2>&1 | tail -10 || true
# Check if site is accessible
echo " Checking site accessibility..."
bench --site "${SITE_NAME}" execute frappe.ping 2>&1 || true
echo ""
echo ">>> Health check completed"