Major Enhancement: Smart deployment with setup/update modes
Features Added:
==============
1. **Auto-Detection Mode** (default)
- Checks for .deployment-uuid file
- First run → Setup mode (creates new deployment)
- Subsequent runs → Update mode (updates existing)
- No flags needed for common workflows
2. **Three Operation Modes:**
A. Setup Mode (--setup or auto if no UUID)
- Creates NEW application via POST /api/v1/applications
- Saves UUID to .deployment-uuid file (git-ignored)
- Sets up Gitea webhook (one-time)
- Warns if UUID file already exists
B. Update Mode (--update or auto if UUID exists)
- Reads UUID from .deployment-uuid
- Verifies application exists: GET /api/v1/applications/:uuid
- Updates env vars: PATCH /api/v1/applications/:uuid/env
- Triggers redeploy: POST /api/v1/applications/:uuid/deploy
- GITEA_API_TOKEN not required (webhook already configured)
C. Status Mode (--status)
- Fetches current deployment details
- Shows application info, status, domain
- Provides monitoring commands
3. **UUID Persistence**
- .deployment-uuid file stores application UUID
- Enables stateful deployments
- Prevents duplicate application creation
- Git-ignored for security
4. **Improved User Experience**
- Clear mode indication (SETUP/UPDATE/STATUS)
- Verification step before overwriting existing deployment
- Comprehensive error messages with actionable steps
- Updated deployment-info.txt with mode information
- Smart dependency checks (GITEA_TOKEN only for setup)
5. **Updated .gitignore**
- Added .deployment-uuid to prevent accidental commits
Usage Examples:
===============
# First deployment (auto-detects no UUID → setup)
./deploy-to-apps.sh
→ Creates application, saves UUID, sets up webhook
# Update after changing .env (auto-detects UUID → update)
./deploy-to-apps.sh
→ Updates env vars, triggers redeployment
# Force new deployment
./deploy-to-apps.sh --setup
# Check status
./deploy-to-apps.sh --status
Benefits:
=========
✅ Idempotent - Can run multiple times safely
✅ Stateful - Remembers previous deployments
✅ User-friendly - Automatic mode detection
✅ Safe - Prevents duplicate applications
✅ Flexible - Supports multiple scenarios
✅ Clear feedback - Shows exactly what's happening
Files Modified:
===============
- deploy-to-apps.example.sh: Complete rewrite with 3 modes
- .gitignore: Added .deployment-uuid
- DEPLOYMENT_SCRIPT_PROPOSAL.md: Full design document
Migration for Existing Users:
==============================
If you already deployed with the old script:
1. Find your UUID: curl -H "X-API-Key: $SAAC_API_KEY" $SAAC_API/applications
2. Save it: echo "your-uuid" > .deployment-uuid
3. Run updates: ./deploy-to-apps.sh
🤖 Generated with Claude Code
https://claude.com/claude-code
Co-Authored-By: Claude <noreply@anthropic.com>
7.0 KiB
7.0 KiB
Deployment Script Enhancement Proposal
Problem Statement
The current deploy-to-apps.sh script only handles initial deployment. Running it a second time will:
- Attempt to create a duplicate application
- Likely fail with "subdomain already exists" error
- Have no way to update existing application's environment variables
- Have no way to trigger redeployment
Solution: Setup vs Update Modes
Architecture
.deployment-uuid (git-ignored file storing application UUID)
deploy-to-apps.sh (enhanced script with mode detection)
Script Modes
1. Auto-Detection (Default)
./deploy-to-apps.sh
- Checks if
.deployment-uuidexists - If NOT exists: Run setup mode (first deployment)
- If exists: Run update mode (redeploy with new env vars)
2. Explicit Setup (Force New Deployment)
./deploy-to-apps.sh --setup
- Creates NEW application
- Overwrites
.deployment-uuidwith new UUID - Use case: Deploying to different subdomain/environment
3. Explicit Update
./deploy-to-apps.sh --update
- Requires
.deployment-uuidto exist - Updates environment variables
- Triggers redeployment
- Fails if
.deployment-uuidnot found
4. Status Check
./deploy-to-apps.sh --status
- Shows current deployment info
- Fetches live status from API
- Shows domain, deployment status, etc.
Implementation Details
File Structure
.deployment-uuid # Single line: application UUID
deployment-info.txt # Human-readable deployment details
.gitignore # Must include .deployment-uuid
Setup Mode Flow
- Check if subdomain already deployed (optional safety check)
- Create application via
POST /api/v1/applications - Save UUID to
.deployment-uuid - Set up Gitea webhook (only once)
- Save deployment info to
deployment-info.txt - Show success message with next steps
Update Mode Flow
- Read UUID from
.deployment-uuid - Verify application exists via
GET /api/v1/applications/:uuid - Update environment variables via
PATCH /api/v1/applications/:uuid/env - Trigger redeployment via
POST /api/v1/applications/:uuid/deploy - Show redeployment progress
Status Mode Flow
- Read UUID from
.deployment-uuid - Fetch application details via
GET /api/v1/applications/:uuid - Display formatted status information
API Endpoints Used
Setup Mode
POST /api/v1/applications
→ Returns: { application_uuid, domain, webhook_url, ... }
POST https://git.startanaicompany.com/api/v1/repos/{owner}/{repo}/hooks
→ Sets up Gitea webhook (one-time)
Update Mode
GET /api/v1/applications/:uuid
→ Verify application exists
PATCH /api/v1/applications/:uuid/env
→ Body: { "variables": { "COMPANY_NAME": "...", ... } }
POST /api/v1/applications/:uuid/deploy
→ Triggers redeployment
Status Mode
GET /api/v1/applications/:uuid
→ Returns application details and status
Error Handling
Setup Mode Errors
- Subdomain already exists: Suggest using
--updateor different subdomain - API key invalid: Show registration instructions
- Gitea token invalid: Show token generation instructions
- Webhook already exists: Warn but continue (non-fatal)
Update Mode Errors
- No .deployment-uuid file: Suggest running
--setupfirst - Application not found: UUID invalid or app deleted, suggest
--setup - Environment variable validation failed: Show which vars are invalid
- Deployment failed: Show error from API
Example Usage
First Deployment
$ ./deploy-to-apps.sh
========================================
AI Recruitment Site Deployment
========================================
📝 Mode: SETUP (first deployment)
📦 Configuration:
Company: Acme Corp
Repository: git@git.startanaicompany.com:user/acme-recruit.git
Domain: https://acmerecruit.startanaicompany.com
📝 Creating application on StartAnAiCompany server...
✅ Application created!
Application UUID: abc-123-def-456
Domain: https://acmerecruit.startanaicompany.com
💾 UUID saved to .deployment-uuid
🪝 Setting up deployment webhook...
✅ Webhook configured for automatic deployments
========================================
Deployment Complete!
========================================
Your site will be available in 2-3 minutes.
Next runs will automatically UPDATE this deployment.
To deploy a new site, use: ./deploy-to-apps.sh --setup
Update Deployment (Changed Company Name)
$ ./deploy-to-apps.sh
========================================
AI Recruitment Site Deployment
========================================
📝 Mode: UPDATE (existing deployment)
📦 Configuration:
Application UUID: abc-123-def-456
Company: New Company Name (CHANGED)
Domain: https://acmerecruit.startanaicompany.com
🔄 Updating environment variables...
✅ Environment variables updated (8 variables)
🚀 Triggering redeployment...
✅ Deployment triggered
========================================
Update Complete!
========================================
Your changes will be live in 2-3 minutes.
Monitor deployment:
./deploy-to-apps.sh --status
Check Status
$ ./deploy-to-apps.sh --status
========================================
Deployment Status
========================================
Application UUID: abc-123-def-456
Name: acme-recruit
Domain: https://acmerecruit.startanaicompany.com
Status: running
Last deployment: 2026-01-24 17:30:00 UTC
Company: Acme Corp
Repository: git@git.startanaicompany.com:user/acme-recruit.git
Branch: master
.gitignore Updates Required
Add to .gitignore:
# Deployment configuration (contains UUID, API keys)
.deployment-uuid
deployment-info.txt
deploy-to-apps.sh
# Keep the example for users to copy
!deploy-to-apps.example.sh
Benefits
- ✅ Idempotent: Can run script multiple times safely
- ✅ User-friendly: Auto-detects mode based on context
- ✅ Flexible: Supports multiple deployment scenarios
- ✅ Safe: Prevents duplicate applications
- ✅ Traceable: UUID stored locally for easy updates
- ✅ Stateful: Remembers previous deployment
- ✅ Informative: Clear feedback on what's happening
Migration for Existing Users
If someone already ran the old script:
# Find their application UUID
curl -H "X-API-Key: $SAAC_API_KEY" https://apps.startanaicompany.com/api/v1/applications
# Save UUID to file
echo "abc-123-def-456" > .deployment-uuid
# Now they can use update mode
./deploy-to-apps.sh --update
Implementation Priority
Phase 1 (Must Have)
- Auto-detection (check for
.deployment-uuid) - Setup mode (create new + save UUID)
- Update mode (update env vars + redeploy)
Phase 2 (Nice to Have)
- Status mode (query current status)
- Enhanced error messages
- Safety checks (subdomain conflicts, etc.)
Phase 3 (Future)
- Rollback support
- Multiple environment support (dev/staging/prod)
- Configuration validation before deployment