-
Notifications
You must be signed in to change notification settings - Fork 9
200 lines (183 loc) · 7.08 KB
/
Copy pathprod.docs.plus.yml
File metadata and controls
200 lines (183 loc) · 7.08 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# This workflow name appears in GitHub Actions UI.
name: CI-Stage
# Workflow will be triggered when code is pushed or a pull request is created on 'main' branch.
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
# This job builds and runs Uptime Kuma.
build-uptime-kuma:
runs-on: prod.docs.plus
if: contains(github.event.head_commit.message, 'uptime-kuma')
steps:
- name: Check out code
uses: actions/checkout@v4
with:
# Only fetch the latest commit to minimize checkout time
fetch-depth: 1
# Preserve existing files
clean: false
- name: Deploy Uptime Kuma
run: |
# Run your build command here
make build_uptime_kuma
# The "setup" job is responsible for setting up the environment and preparing for the build processes.
setup:
runs-on: prod.docs.plus
if: contains(github.event.head_commit.message, 'build') &&!contains(github.event.head_commit.message, 'uptime-kuma')
strategy:
matrix:
# This matrix configuration will run the job on the specific version of Node.js.
node-version: ['lts/*']
steps:
# This step checks out your repository under $GITHUB_WORKSPACE so your job can access it.
- name: Check out code
uses: actions/checkout@v4
with:
# Only fetch the latest commit to minimize checkout time
fetch-depth: 1
# Preserve existing files for faster deploys
clean: false
# Cache node_modules for faster installs
- name: Cache node modules
uses: actions/cache@v4
with:
path: |
~/.yarn/cache
**/node_modules
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
# This step sets up Node.js on the runner and installs the version specified in the matrix above.
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
# Install dependencies with optimizations
- name: Install dependencies
run: |
# Use yarn with production optimizations
yarn install --frozen-lockfile --production=false --cache-folder ~/.yarn/cache
# Clean up dev dependencies in production
if [ "$NODE_ENV" = "production" ]; then
yarn install --frozen-lockfile --production=true --cache-folder ~/.yarn/cache
fi
# This step copies the .env file from the root directory to the required directories for each package.
# Update these paths if your repository structure is different.
- name: Copy .env files
run: |
cp ../../../.env packages/webapp
cp ../../../.env packages/hocuspocus.server
# Pre-build health check
- name: Pre-build health check
run: |
# Check if essential services are running
make supabase_status || echo "Supabase not running, continuing..."
- name: Build monorepo packages
run: |
# Build with performance optimizations
NODE_ENV=production yarn build
# Post-build validation
- name: Validate build artifacts
run: |
# Check if critical build outputs exist
if [ -d "packages/webapp/.next" ]; then
echo "✓ Next.js build artifacts found"
ls -la packages/webapp/.next/
else
echo "✗ Next.js build failed - no .next directory"
exit 1
fi
env:
# The environment variable DATABASE_URL is sourced from a secret in your repository.
DATABASE_URL: ${{secrets.STAGE_DATABASE_URL}}
NODE_ENV: production
# The "build-front" job builds the front-end, it depends on the "setup" job.
build-front:
# Specifies that this job depends on the 'setup' job.
needs: setup
runs-on: prod.docs.plus
# This job will only run if the commit message contains the word 'front'.
if: contains(github.event.head_commit.message, 'front')
steps:
# Pre-deployment health check
- name: Pre-deployment health check
run: |
# Check current PM2 status
pm2 list || echo "PM2 not running, will start fresh"
# Check disk space
df -h
# Check memory usage
free -h
# Backup current deployment for rollback
- name: Backup current deployment
run: |
# Create backup of current .next build if it exists
if [ -d "packages/webapp/.next" ]; then
mv packages/webapp/.next packages/webapp/.next.backup.$(date +%Y%m%d-%H%M%S)
echo "✓ Backup created"
fi
# This step runs the build command for the front-end.
- name: Build and Deploy Front-end
run: |
# Build with enhanced error handling
if ! make build_front_production; then
echo "✗ Build failed, attempting rollback..."
# Restore backup if build fails
if [ -d "packages/webapp/.next.backup.*" ]; then
LATEST_BACKUP=$(ls -t packages/webapp/.next.backup.* | head -n1)
mv "$LATEST_BACKUP" packages/webapp/.next
echo "✓ Rollback completed"
fi
exit 1
fi
# Post-deployment health check
- name: Post-deployment health check
run: |
# Wait for application to start
sleep 10
# Check if the application is responding
if curl -f http://localhost:3001/api/health; then
echo "✓ Application health check passed"
else
echo "✗ Application health check failed"
# Show PM2 logs for debugging
pm2 logs nextjs_production --lines 50
exit 1
fi
# Cleanup old backups (keep last 3)
- name: Cleanup old backups
run: |
# Remove old backup directories (keep last 3)
ls -t packages/webapp/.next.backup.* 2>/dev/null | tail -n +4 | xargs rm -rf || true
# The "build-back" job builds the back-end, it also depends on the "setup" job.
build-back:
# Specifies that this job depends on the 'setup' job.
needs: setup
runs-on: prod.docs.plus
# This job will only run if the commit message contains the word 'back'.
if: contains(github.event.head_commit.message, 'back')
steps:
# This step runs the build command for the back-end.
- name: Build Back-end
run: make build_hocuspocus.server_prod
# -----------------------------------------------------------------------
# EXAMPLE USAGE:
# 1) To run setup + build-front:
# git commit -m "Add feature (build front)"
#
# 2) To run setup + build-back:
# git commit -m "Fix backend (build back)"
#
# 3) To run setup + build-uptime-kuma:
# git commit -m "build uptime-kuma"
#
# 4) To run multiple pipelines together:
# git commit -m "Update everything (build front back uptime-kuma)"
#
# Then push to the 'main' branch (or open a pull request):
# git push origin main
# -----------------------------------------------------------------------