myaidev-method 0.2.4 โ†’ 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/USER_GUIDE.md +389 -8
  2. package/bin/cli.js +165 -30
  3. package/package.json +1 -1
  4. package/src/lib/ascii-banner.js +100 -0
  5. package/src/templates/claude/commands/myai-deploy-dev.md +500 -0
  6. package/src/templates/claude/commands/myai-deploy-prod.md +837 -0
  7. package/src/templates/claude/commands/myai-deploy-staging.md +331 -0
  8. package/src/templates/claude/commands/myai-git-hotfix.md +957 -0
  9. package/src/templates/claude/commands/myai-git-pr.md +200 -0
  10. package/src/templates/claude/commands/myai-git-release.md +806 -0
  11. package/src/templates/claude/commands/myai-git-sync.md +796 -0
  12. package/src/templates/codex/commands/myai-astro-publish.md +51 -0
  13. package/src/templates/codex/commands/myai-configure.md +185 -0
  14. package/src/templates/codex/commands/myai-content-writer.md +73 -0
  15. package/src/templates/codex/commands/myai-coolify-deploy.md +159 -0
  16. package/src/templates/codex/commands/myai-deploy-dev.md +379 -0
  17. package/src/templates/codex/commands/myai-deploy-prod.md +431 -0
  18. package/src/templates/codex/commands/myai-deploy-staging.md +275 -0
  19. package/src/templates/codex/commands/myai-dev-architect.md +69 -0
  20. package/src/templates/codex/commands/myai-dev-code.md +82 -0
  21. package/src/templates/codex/commands/myai-dev-docs.md +83 -0
  22. package/src/templates/codex/commands/myai-dev-review.md +85 -0
  23. package/src/templates/codex/commands/myai-dev-test.md +84 -0
  24. package/src/templates/codex/commands/myai-docusaurus-publish.md +42 -0
  25. package/src/templates/codex/commands/myai-git-hotfix.md +512 -0
  26. package/src/templates/codex/commands/myai-git-pr.md +196 -0
  27. package/src/templates/codex/commands/myai-git-release.md +516 -0
  28. package/src/templates/codex/commands/myai-git-sync.md +517 -0
  29. package/src/templates/codex/commands/myai-mintlify-publish.md +42 -0
  30. package/src/templates/codex/commands/myai-payloadcms-publish.md +42 -0
  31. package/src/templates/codex/commands/myai-sparc-workflow.md +185 -0
  32. package/src/templates/codex/commands/myai-wordpress-admin.md +143 -0
  33. package/src/templates/codex/commands/myai-wordpress-publish.md +66 -0
  34. package/src/templates/gemini/commands/myai-astro-publish.toml +76 -0
  35. package/src/templates/gemini/commands/myai-configure.toml +188 -0
  36. package/src/templates/gemini/commands/myai-content-writer.toml +76 -0
  37. package/src/templates/gemini/commands/myai-coolify-deploy.toml +138 -0
  38. package/src/templates/gemini/commands/myai-deploy-dev.toml +379 -0
  39. package/src/templates/gemini/commands/myai-deploy-prod.toml +438 -0
  40. package/src/templates/gemini/commands/myai-deploy-staging.toml +275 -0
  41. package/src/templates/gemini/commands/myai-dev-architect.toml +64 -0
  42. package/src/templates/gemini/commands/myai-dev-code.toml +75 -0
  43. package/src/templates/gemini/commands/myai-dev-docs.toml +76 -0
  44. package/src/templates/gemini/commands/myai-dev-review.toml +78 -0
  45. package/src/templates/gemini/commands/myai-dev-test.toml +77 -0
  46. package/src/templates/gemini/commands/myai-docusaurus-publish.toml +63 -0
  47. package/src/templates/gemini/commands/myai-git-hotfix.toml +953 -0
  48. package/src/templates/gemini/commands/myai-git-pr.toml +196 -0
  49. package/src/templates/gemini/commands/myai-git-release.toml +802 -0
  50. package/src/templates/gemini/commands/myai-git-sync.toml +792 -0
  51. package/src/templates/gemini/commands/myai-mintlify-publish.toml +67 -0
  52. package/src/templates/gemini/commands/myai-payloadcms-publish.toml +59 -0
  53. package/src/templates/gemini/commands/myai-sparc-workflow.toml +47 -0
  54. package/src/templates/gemini/commands/myai-wordpress-admin.toml +143 -0
  55. package/src/templates/gemini/commands/myai-wordpress-publish.toml +77 -0
@@ -0,0 +1,431 @@
1
+ # Deploy to production environment with strict checks and approval
2
+
3
+ You are a deployment automation assistant specializing in production environment deployments with strict safety protocols.
4
+
5
+ Task: Deploy to production environment - $ARGUMENTS
6
+
7
+ ## Production Deployment Workflow
8
+
9
+ ### 1. Pre-Deployment Checks (CRITICAL)
10
+
11
+ ```bash
12
+ echo "๐Ÿ”’ Starting production deployment pre-flight checks..."
13
+
14
+ # CRITICAL: Ensure on correct branch
15
+ current_branch=$(git branch --show-current)
16
+ if [[ "$current_branch" != "main" && "$current_branch" != "master" && "$current_branch" != "production" ]]; then
17
+ echo "โŒ BLOCKED: Not on production branch (main/master/production)"
18
+ echo "Current branch: $current_branch"
19
+ exit 1
20
+ fi
21
+
22
+ # Check for uncommitted changes
23
+ if ! git diff-index --quiet HEAD --; then
24
+ echo "โŒ BLOCKED: Uncommitted changes detected"
25
+ git status
26
+ exit 1
27
+ fi
28
+
29
+ # Ensure branch is up to date
30
+ git fetch origin
31
+ LOCAL=$(git rev-parse @)
32
+ REMOTE=$(git rev-parse @{u})
33
+ if [ $LOCAL != $REMOTE ]; then
34
+ echo "โŒ BLOCKED: Local branch not in sync with remote"
35
+ echo "Run: git pull origin $current_branch"
36
+ exit 1
37
+ fi
38
+
39
+ echo "โœ… Pre-flight checks passed"
40
+ ```
41
+
42
+ ### 2. Environment Validation (CRITICAL)
43
+
44
+ ```bash
45
+ echo "๐Ÿ” Validating production environment..."
46
+
47
+ # Required variables for Coolify
48
+ coolify_vars=("COOLIFY_URL" "COOLIFY_API_TOKEN" "COOLIFY_PROD_APP_ID")
49
+
50
+ # Required variables for Docker
51
+ docker_vars=("DOCKER_REGISTRY" "PROD_IMAGE_TAG")
52
+
53
+ # Application variables
54
+ app_vars=("PROD_URL" "NODE_ENV")
55
+
56
+ # Verify NODE_ENV is set to production
57
+ if [ "$NODE_ENV" != "production" ]; then
58
+ echo "โŒ BLOCKED: NODE_ENV must be 'production', not '$NODE_ENV'"
59
+ exit 1
60
+ fi
61
+
62
+ echo "โœ… Environment validation passed"
63
+ ```
64
+
65
+ ### 3. Comprehensive Testing (CRITICAL)
66
+
67
+ ```bash
68
+ echo "๐Ÿงช Running comprehensive test suite..."
69
+
70
+ # Unit tests
71
+ echo "Running unit tests..."
72
+ npm run test:unit || { echo "โŒ Unit tests FAILED"; exit 1; }
73
+
74
+ # Integration tests
75
+ echo "Running integration tests..."
76
+ npm run test:integration || { echo "โŒ Integration tests FAILED"; exit 1; }
77
+
78
+ # End-to-end tests
79
+ echo "Running E2E tests..."
80
+ npm run test:e2e || { echo "โŒ E2E tests FAILED"; exit 1; }
81
+
82
+ # Security audit
83
+ echo "Running security audit..."
84
+ npm audit --production --audit-level=moderate || {
85
+ echo "โŒ Security vulnerabilities detected"
86
+ npm audit
87
+ exit 1
88
+ }
89
+
90
+ # Linting
91
+ echo "Running linter..."
92
+ npm run lint || { echo "โŒ Linting FAILED"; exit 1; }
93
+
94
+ # Build
95
+ echo "Building production bundle..."
96
+ NODE_ENV=production npm run build || { echo "โŒ Build FAILED"; exit 1; }
97
+
98
+ echo "โœ… All tests passed"
99
+ ```
100
+
101
+ ### 4. Deployment Approval (REQUIRED)
102
+
103
+ ```bash
104
+ request_deployment_approval() {
105
+ echo ""
106
+ echo "โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—"
107
+ echo "โ•‘ ๐Ÿšจ PRODUCTION DEPLOYMENT APPROVAL ๐Ÿšจ โ•‘"
108
+ echo "โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•"
109
+ echo ""
110
+ echo "Environment: PRODUCTION"
111
+ echo "Branch: $(git branch --show-current)"
112
+ echo "Commit: $(git rev-parse --short HEAD)"
113
+ echo "Message: $(git log -1 --pretty=%B)"
114
+ echo "Author: $(git log -1 --pretty=%an)"
115
+ echo "Date: $(git log -1 --pretty=%ad)"
116
+ echo ""
117
+ echo "Deployment Target: $PROD_URL"
118
+ echo ""
119
+
120
+ # Show what will be deployed
121
+ echo "Changes since last deployment:"
122
+ git log --oneline -5
123
+ echo ""
124
+
125
+ # Require explicit confirmation
126
+ read -p "Type 'DEPLOY TO PRODUCTION' to confirm: " approval
127
+
128
+ if [ "$approval" != "DEPLOY TO PRODUCTION" ]; then
129
+ echo "โŒ Deployment cancelled"
130
+ exit 1
131
+ fi
132
+
133
+ echo "โœ… Deployment approved"
134
+ }
135
+
136
+ # Request approval
137
+ request_deployment_approval
138
+ ```
139
+
140
+ ### 5. Create Backup and Rollback Point
141
+
142
+ ```bash
143
+ echo "๐Ÿ’พ Creating rollback point..."
144
+
145
+ # Tag current production state
146
+ current_prod_commit=$(git rev-parse HEAD)
147
+ timestamp=$(date +%Y%m%d_%H%M%S)
148
+ rollback_tag="prod-backup-$timestamp"
149
+
150
+ git tag -a "$rollback_tag" -m "Production backup before deployment at $timestamp"
151
+ git push origin "$rollback_tag"
152
+
153
+ # Save current deployment info
154
+ cat > .deployment-backup.json << EOF
155
+ {
156
+ "timestamp": "$timestamp",
157
+ "commit": "$current_prod_commit",
158
+ "tag": "$rollback_tag",
159
+ "environment": "production"
160
+ }
161
+ EOF
162
+
163
+ echo "โœ… Rollback point created: $rollback_tag"
164
+ ```
165
+
166
+ ### 6. Blue-Green Deployment (Recommended)
167
+
168
+ ```bash
169
+ blue_green_deploy() {
170
+ echo "๐Ÿ”ต๐ŸŸข Executing blue-green deployment..."
171
+
172
+ # Deploy to green environment (inactive)
173
+ echo "Deploying to GREEN environment..."
174
+
175
+ if [ -n "$COOLIFY_URL" ]; then
176
+ # Deploy via Coolify to green slot
177
+ curl -X POST "$COOLIFY_URL/api/v1/deploy" \
178
+ -H "Authorization: Bearer $COOLIFY_API_TOKEN" \
179
+ -H "Content-Type: application/json" \
180
+ -d "{
181
+ \"application_id\": \"$COOLIFY_PROD_GREEN_APP_ID\",
182
+ \"commit\": \"$(git rev-parse HEAD)\"
183
+ }"
184
+ else
185
+ # Deploy via Docker to green
186
+ ssh prod-server << 'EOF'
187
+ docker pull $DOCKER_REGISTRY/app:prod-green
188
+ docker stop app-prod-green 2>/dev/null || true
189
+ docker rm app-prod-green 2>/dev/null || true
190
+ docker run -d \
191
+ --name app-prod-green \
192
+ --network prod-network \
193
+ -p 3001:3000 \
194
+ --env-file /etc/app/prod.env \
195
+ $DOCKER_REGISTRY/app:prod-green
196
+ EOF
197
+ fi
198
+
199
+ # Health check on green
200
+ echo "๐Ÿ” Health checking GREEN environment..."
201
+ max_retries=60
202
+ retry_count=0
203
+
204
+ while [ $retry_count -lt $max_retries ]; do
205
+ if curl -f -s "${PROD_GREEN_URL}/health" > /dev/null; then
206
+ echo "โœ… GREEN environment healthy"
207
+ break
208
+ fi
209
+ sleep 5
210
+ ((retry_count++))
211
+ done
212
+
213
+ if [ $retry_count -eq $max_retries ]; then
214
+ echo "โŒ GREEN environment failed health check"
215
+ exit 1
216
+ fi
217
+
218
+ # Run smoke tests on green
219
+ echo "๐Ÿงช Running smoke tests on GREEN..."
220
+ SMOKE_TEST_URL=$PROD_GREEN_URL npm run test:smoke || {
221
+ echo "โŒ Smoke tests FAILED on GREEN"
222
+ exit 1
223
+ }
224
+
225
+ # Switch traffic to green (blue becomes inactive)
226
+ echo "๐Ÿ”„ Switching traffic to GREEN..."
227
+
228
+ # Update load balancer or reverse proxy
229
+ if [ -n "$LOAD_BALANCER_URL" ]; then
230
+ curl -X POST "$LOAD_BALANCER_URL/switch" \
231
+ -H "Content-Type: application/json" \
232
+ -d '{"active":"green"}'
233
+ else
234
+ # Update nginx configuration
235
+ ssh prod-server << 'EOF'
236
+ # Swap upstream servers in nginx config
237
+ sed -i 's/app-prod-blue:3000/app-prod-green:3000/g' /etc/nginx/sites-enabled/production
238
+ nginx -t && nginx -s reload
239
+ EOF
240
+ fi
241
+
242
+ echo "โœ… Traffic switched to GREEN"
243
+ echo "๐Ÿ’ก BLUE environment kept running for quick rollback"
244
+ }
245
+
246
+ # Execute blue-green deployment
247
+ # blue_green_deploy
248
+ ```
249
+
250
+ ### 7. Post-Deployment Verification (CRITICAL)
251
+
252
+ ```bash
253
+ echo "๐Ÿ” Running post-deployment verification..."
254
+
255
+ # Wait for deployment to stabilize
256
+ echo "โณ Waiting for deployment to stabilize (60s)..."
257
+ sleep 60
258
+
259
+ # Comprehensive health checks
260
+ echo "๐Ÿฅ Running health checks..."
261
+
262
+ # 1. Application health endpoint
263
+ if ! curl -f -s "$PROD_URL/health" > /dev/null; then
264
+ echo "โŒ CRITICAL: Health endpoint unreachable"
265
+ exit 1
266
+ fi
267
+
268
+ # 2. API endpoints check
269
+ critical_endpoints=(
270
+ "/api/status"
271
+ "/api/version"
272
+ "/api/metrics"
273
+ )
274
+
275
+ for endpoint in "${critical_endpoints[@]}"; do
276
+ response=$(curl -s -o /dev/null -w "%{http_code}" "$PROD_URL$endpoint")
277
+ if [ "$response" != "200" ]; then
278
+ echo "โŒ CRITICAL: Endpoint $endpoint returned $response"
279
+ exit 1
280
+ fi
281
+ echo "โœ… $endpoint: OK"
282
+ done
283
+
284
+ # 3. Database connectivity
285
+ if curl -f -s "$PROD_URL/api/health/db" | grep -q "connected"; then
286
+ echo "โœ… Database: Connected"
287
+ else
288
+ echo "โŒ CRITICAL: Database connection failed"
289
+ exit 1
290
+ fi
291
+
292
+ # 4. Smoke tests
293
+ echo "๐Ÿงช Running production smoke tests..."
294
+ npm run test:smoke:prod || {
295
+ echo "โŒ CRITICAL: Smoke tests failed"
296
+ exit 1
297
+ }
298
+
299
+ echo "โœ… All post-deployment checks passed"
300
+ ```
301
+
302
+ ### 8. Emergency Rollback
303
+
304
+ ```bash
305
+ emergency_rollback() {
306
+ echo "๐Ÿšจ EMERGENCY ROLLBACK INITIATED"
307
+
308
+ # Load backup info
309
+ if [ -f ".deployment-backup.json" ]; then
310
+ backup_tag=$(jq -r '.tag' .deployment-backup.json)
311
+ backup_commit=$(jq -r '.commit' .deployment-backup.json)
312
+
313
+ echo "Rolling back to: $backup_tag ($backup_commit)"
314
+ else
315
+ # Use previous tag
316
+ backup_tag=$(git tag --sort=-creatordate | grep "prod-backup" | head -1)
317
+ fi
318
+
319
+ # For blue-green: Just switch back
320
+ if [ "$DEPLOYMENT_STRATEGY" == "blue-green" ]; then
321
+ echo "๐Ÿ”ต Switching traffic back to BLUE..."
322
+ ssh prod-server << 'EOF'
323
+ sed -i 's/app-prod-green:3000/app-prod-blue:3000/g' /etc/nginx/sites-enabled/production
324
+ nginx -s reload
325
+ EOF
326
+ echo "โœ… Rolled back to BLUE environment"
327
+ return
328
+ fi
329
+
330
+ # For other strategies: Redeploy previous version
331
+ echo "๐Ÿ”„ Redeploying previous version..."
332
+
333
+ git checkout "$backup_tag"
334
+
335
+ if [ -n "$COOLIFY_URL" ]; then
336
+ curl -X POST "$COOLIFY_URL/api/v1/deploy" \
337
+ -H "Authorization: Bearer $COOLIFY_API_TOKEN" \
338
+ -H "Content-Type: application/json" \
339
+ -d "{
340
+ \"application_id\": \"$COOLIFY_PROD_APP_ID\",
341
+ \"commit\": \"$backup_commit\",
342
+ \"force\": true
343
+ }"
344
+ fi
345
+
346
+ echo "โœ… Rollback complete"
347
+ }
348
+
349
+ # Export rollback functions
350
+ export -f emergency_rollback
351
+ ```
352
+
353
+ ## Complete Production Deployment Script
354
+
355
+ ```bash
356
+ #!/bin/bash
357
+ set -e
358
+
359
+ echo "๐Ÿš€ PRODUCTION DEPLOYMENT INITIATED"
360
+ echo "===================================="
361
+
362
+ # 1. CRITICAL: Pre-flight checks
363
+ echo "๐Ÿ”’ Running pre-flight checks..."
364
+ [[ "$(git branch --show-current)" =~ ^(main|master|production)$ ]] || { echo "โŒ Wrong branch"; exit 1; }
365
+ git diff-index --quiet HEAD -- || { echo "โŒ Uncommitted changes"; exit 1; }
366
+
367
+ # 2. CRITICAL: Run all tests
368
+ echo "๐Ÿงช Running test suite..."
369
+ npm test || { echo "โŒ Tests failed"; exit 1; }
370
+ npm audit --production --audit-level=moderate || { echo "โŒ Security issues"; exit 1; }
371
+
372
+ # 3. Build
373
+ echo "๐Ÿ—๏ธ Building production bundle..."
374
+ NODE_ENV=production npm run build || { echo "โŒ Build failed"; exit 1; }
375
+
376
+ # 4. REQUIRED: Get approval
377
+ read -p "Type 'DEPLOY TO PRODUCTION': " approval
378
+ [ "$approval" == "DEPLOY TO PRODUCTION" ] || { echo "โŒ Cancelled"; exit 1; }
379
+
380
+ # 5. Create rollback point
381
+ echo "๐Ÿ’พ Creating rollback point..."
382
+ timestamp=$(date +%Y%m%d_%H%M%S)
383
+ git tag "prod-backup-$timestamp"
384
+ git push origin "prod-backup-$timestamp"
385
+
386
+ # 6. Deploy (blue-green recommended)
387
+ echo "๐Ÿš€ Deploying..."
388
+ blue_green_deploy
389
+
390
+ # 7. CRITICAL: Verify deployment
391
+ echo "๐Ÿ” Verifying deployment..."
392
+ sleep 60
393
+ curl -f "$PROD_URL/health" || { echo "โŒ Health check failed"; emergency_rollback; exit 1; }
394
+ npm run test:smoke:prod || { echo "โŒ Smoke tests failed"; emergency_rollback; exit 1; }
395
+
396
+ # 8. Monitor
397
+ echo "๐Ÿ“Š Monitoring (5 minutes)..."
398
+ sleep 300
399
+
400
+ echo "โœ… PRODUCTION DEPLOYMENT COMPLETE"
401
+ echo "๐ŸŒ Live at: $PROD_URL"
402
+ ```
403
+
404
+ ## Environment Configuration
405
+
406
+ ```bash
407
+ # Coolify
408
+ COOLIFY_URL=https://coolify.your-server.com
409
+ COOLIFY_API_TOKEN=your_api_token
410
+ COOLIFY_PROD_APP_ID=your_prod_app_id
411
+ COOLIFY_PROD_GREEN_APP_ID=your_green_app_id
412
+
413
+ # Docker
414
+ DOCKER_REGISTRY=registry.your-domain.com
415
+ PROD_IMAGE_TAG=prod
416
+
417
+ # Application
418
+ PROD_URL=https://your-app.com
419
+ PROD_GREEN_URL=https://green.your-app.com
420
+ NODE_ENV=production
421
+
422
+ # Deployment Strategy
423
+ DEPLOYMENT_STRATEGY=blue-green # or: canary, rolling
424
+
425
+ # Notifications
426
+ SLACK_WEBHOOK_URL=https://hooks.slack.com/services/YOUR/WEBHOOK
427
+ DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/YOUR/WEBHOOK
428
+ TEAM_EMAIL=team@yourcompany.com
429
+ ```
430
+
431
+ Execute production deployment with maximum safety and approval gates.
@@ -0,0 +1,275 @@
1
+ # Deploy to staging environment via Coolify or Docker
2
+
3
+ You are a deployment automation assistant specializing in staging environment deployments.
4
+
5
+ Task: Deploy to staging environment - $ARGUMENTS
6
+
7
+ ## Staging Deployment Workflow
8
+
9
+ ### 1. Pre-Deployment Checks
10
+
11
+ ```bash
12
+ # Check current branch and status
13
+ git branch --show-current
14
+ git status
15
+
16
+ # Ensure on staging branch
17
+ if [ "$(git branch --show-current)" != "staging" ]; then
18
+ echo "โš ๏ธ Not on staging branch. Switch first."
19
+ git checkout staging
20
+ fi
21
+
22
+ # Pull latest changes
23
+ git pull origin staging
24
+
25
+ # Check for uncommitted changes
26
+ if ! git diff-index --quiet HEAD --; then
27
+ echo "โš ๏ธ Uncommitted changes detected"
28
+ git status
29
+ fi
30
+ ```
31
+
32
+ ### 2. Environment Validation
33
+
34
+ **Check Required Environment Variables:**
35
+ ```bash
36
+ # For Coolify
37
+ required_vars=("COOLIFY_URL" "COOLIFY_API_TOKEN" "COOLIFY_STAGING_APP_ID")
38
+
39
+ # For Docker
40
+ required_vars=("DOCKER_REGISTRY" "STAGING_IMAGE_TAG")
41
+
42
+ for var in "${required_vars[@]}"; do
43
+ if [ -z "${!var}" ]; then
44
+ echo "โŒ Missing required variable: $var"
45
+ exit 1
46
+ fi
47
+ done
48
+ ```
49
+
50
+ ### 3. Build and Test
51
+
52
+ ```bash
53
+ # Run tests before deploying
54
+ echo "๐Ÿงช Running test suite..."
55
+ npm test || { echo "โŒ Tests failed"; exit 1; }
56
+
57
+ # Build application
58
+ echo "๐Ÿ—๏ธ Building application..."
59
+ npm run build || { echo "โŒ Build failed"; exit 1; }
60
+
61
+ # Run linter
62
+ npm run lint || echo "โš ๏ธ Linting issues detected"
63
+ ```
64
+
65
+ ### 4. Deployment Options
66
+
67
+ #### Option A: Deploy with Coolify
68
+
69
+ ```bash
70
+ # Using Coolify API
71
+ echo "๐Ÿš€ Deploying to Coolify staging..."
72
+
73
+ # Trigger deployment
74
+ curl -X POST "$COOLIFY_URL/api/v1/deploy" \
75
+ -H "Authorization: Bearer $COOLIFY_API_TOKEN" \
76
+ -H "Content-Type: application/json" \
77
+ -d "{
78
+ \"application_id\": \"$COOLIFY_STAGING_APP_ID\",
79
+ \"force\": false,
80
+ \"commit\": \"$(git rev-parse HEAD)\"
81
+ }"
82
+
83
+ # Monitor deployment status
84
+ echo "๐Ÿ“Š Monitoring deployment..."
85
+ deployment_id=$(curl -s "$COOLIFY_URL/api/v1/deployments/latest" \
86
+ -H "Authorization: Bearer $COOLIFY_API_TOKEN" | jq -r '.id')
87
+
88
+ while true; do
89
+ status=$(curl -s "$COOLIFY_URL/api/v1/deployments/$deployment_id" \
90
+ -H "Authorization: Bearer $COOLIFY_API_TOKEN" | jq -r '.status')
91
+
92
+ echo "Status: $status"
93
+
94
+ if [ "$status" = "success" ]; then
95
+ echo "โœ… Deployment successful!"
96
+ break
97
+ elif [ "$status" = "failed" ]; then
98
+ echo "โŒ Deployment failed!"
99
+ exit 1
100
+ fi
101
+
102
+ sleep 5
103
+ done
104
+ ```
105
+
106
+ #### Option B: Deploy with Docker
107
+
108
+ ```bash
109
+ echo "๐Ÿณ Deploying with Docker..."
110
+
111
+ # Build Docker image
112
+ docker build -t $DOCKER_REGISTRY/app:staging .
113
+
114
+ # Push to registry
115
+ docker push $DOCKER_REGISTRY/app:staging
116
+
117
+ # Deploy to staging server via SSH
118
+ ssh staging-server << 'EOF'
119
+ docker pull $DOCKER_REGISTRY/app:staging
120
+ docker stop app-staging || true
121
+ docker rm app-staging || true
122
+ docker run -d \
123
+ --name app-staging \
124
+ --restart unless-stopped \
125
+ -p 3000:3000 \
126
+ --env-file /etc/app/staging.env \
127
+ $DOCKER_REGISTRY/app:staging
128
+ EOF
129
+
130
+ echo "โœ… Docker deployment complete!"
131
+ ```
132
+
133
+ #### Option C: Deploy with Docker Compose
134
+
135
+ ```bash
136
+ echo "๐Ÿณ Deploying with Docker Compose..."
137
+
138
+ # Deploy to staging server
139
+ ssh staging-server << 'EOF'
140
+ cd /opt/app
141
+ git pull origin staging
142
+ docker-compose -f docker-compose.staging.yml pull
143
+ docker-compose -f docker-compose.staging.yml up -d --remove-orphans
144
+ docker-compose -f docker-compose.staging.yml ps
145
+ EOF
146
+ ```
147
+
148
+ ### 5. Post-Deployment Verification
149
+
150
+ ```bash
151
+ echo "๐Ÿ” Verifying deployment..."
152
+
153
+ # Health check
154
+ max_retries=30
155
+ retry_count=0
156
+
157
+ while [ $retry_count -lt $max_retries ]; do
158
+ if curl -f -s "$STAGING_URL/health" > /dev/null; then
159
+ echo "โœ… Health check passed!"
160
+ break
161
+ else
162
+ echo "โณ Waiting for application to start... ($retry_count/$max_retries)"
163
+ sleep 5
164
+ ((retry_count++))
165
+ fi
166
+ done
167
+
168
+ if [ $retry_count -eq $max_retries ]; then
169
+ echo "โŒ Health check failed after $max_retries attempts"
170
+ exit 1
171
+ fi
172
+
173
+ # Run smoke tests
174
+ echo "๐Ÿงช Running smoke tests..."
175
+ npm run test:smoke:staging || echo "โš ๏ธ Smoke tests failed"
176
+
177
+ # Check application logs
178
+ echo "๐Ÿ“‹ Recent logs:"
179
+ if [ -n "$COOLIFY_URL" ]; then
180
+ curl -s "$COOLIFY_URL/api/v1/applications/$COOLIFY_STAGING_APP_ID/logs" \
181
+ -H "Authorization: Bearer $COOLIFY_API_TOKEN" | tail -20
182
+ else
183
+ ssh staging-server "docker logs --tail 20 app-staging"
184
+ fi
185
+ ```
186
+
187
+ ### 6. Rollback Procedure
188
+
189
+ ```bash
190
+ rollback_staging() {
191
+ echo "๐Ÿ”„ Rolling back staging deployment..."
192
+
193
+ # Get previous deployment
194
+ previous_commit=$(git log --oneline -2 | tail -1 | cut -d' ' -f1)
195
+
196
+ # Rollback via Coolify
197
+ if [ -n "$COOLIFY_URL" ]; then
198
+ curl -X POST "$COOLIFY_URL/api/v1/deploy" \
199
+ -H "Authorization: Bearer $COOLIFY_API_TOKEN" \
200
+ -H "Content-Type: application/json" \
201
+ -d "{
202
+ \"application_id\": \"$COOLIFY_STAGING_APP_ID\",
203
+ \"commit\": \"$previous_commit\"
204
+ }"
205
+ fi
206
+
207
+ # Or rollback via Docker
208
+ if [ -n "$DOCKER_REGISTRY" ]; then
209
+ ssh staging-server << EOF
210
+ docker pull $DOCKER_REGISTRY/app:staging-previous
211
+ docker stop app-staging
212
+ docker rm app-staging
213
+ docker run -d --name app-staging $DOCKER_REGISTRY/app:staging-previous
214
+ EOF
215
+ fi
216
+
217
+ echo "โœ… Rollback complete!"
218
+ }
219
+
220
+ # Call rollback if needed
221
+ # rollback_staging
222
+ ```
223
+
224
+ ## Complete Deployment Script
225
+
226
+ ```bash
227
+ #!/bin/bash
228
+ set -e
229
+
230
+ echo "๐Ÿš€ Starting staging deployment..."
231
+
232
+ # 1. Pre-flight checks
233
+ git checkout staging
234
+ git pull origin staging
235
+ npm test
236
+
237
+ # 2. Build
238
+ npm run build
239
+
240
+ # 3. Deploy (choose method)
241
+ # Coolify method
242
+ curl -X POST "$COOLIFY_URL/api/v1/deploy" \
243
+ -H "Authorization: Bearer $COOLIFY_API_TOKEN" \
244
+ -d '{"application_id":"'"$COOLIFY_STAGING_APP_ID"'"}'
245
+
246
+ # 4. Verify
247
+ sleep 10
248
+ curl -f "$STAGING_URL/health"
249
+
250
+ echo "โœ… Staging deployment complete!"
251
+ echo "๐ŸŒ Application available at: $STAGING_URL"
252
+ ```
253
+
254
+ ## Environment Configuration
255
+
256
+ **Required .env variables:**
257
+ ```bash
258
+ # Coolify
259
+ COOLIFY_URL=https://coolify.your-server.com
260
+ COOLIFY_API_TOKEN=your_api_token
261
+ COOLIFY_STAGING_APP_ID=your_staging_app_id
262
+
263
+ # Docker
264
+ DOCKER_REGISTRY=registry.your-domain.com
265
+ STAGING_IMAGE_TAG=staging
266
+
267
+ # Application
268
+ STAGING_URL=https://staging.your-app.com
269
+
270
+ # Notifications (optional)
271
+ SLACK_WEBHOOK_URL=https://hooks.slack.com/services/YOUR/WEBHOOK/URL
272
+ DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/YOUR/WEBHOOK
273
+ ```
274
+
275
+ Execute the staging deployment workflow with appropriate method based on available infrastructure.