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