# ๐Ÿค– Automated Deployment - Quick Reference ## Overview The grab worker now supports **fully automated deployment** with DNS configuration, matching the pattern used in other aesthetic.computer services (nanos, dark-window, etc.). --- ## One-Command Deployment ```fish cd /workspaces/aesthetic-computer/grab ./scripts/deploy-with-dns.fish ``` **What it does:** 1. โœ… Deploys worker to Cloudflare Workers 2. โœ… Creates/updates CNAME record via Cloudflare API 3. โœ… Waits for DNS propagation (~30-60 seconds) 4. โœ… Verifies deployment is accessible 5. โœ… Provides test commands and summary **Time:** ~2-3 minutes total (including DNS propagation) --- ## Prerequisites ### 1. Get Cloudflare API Token **One-time setup** (1 minute): 1. Go to: https://dash.cloudflare.com/profile/api-tokens 2. Click: **"Create Token"** 3. Use template: **"Edit zone DNS"** 4. Configure permissions: - Zone โ†’ DNS โ†’ Edit - Zone Resources โ†’ Include โ†’ Specific zone โ†’ aesthetic.computer 5. Click: **"Continue to summary"** โ†’ **"Create Token"** 6. Copy the token ### 2. Add to Vault Edit `/aesthetic-computer-vault/grab/.env`: ```bash CLOUDFLARE_EMAIL=me@jas.life CLOUDFLARE_API_TOKEN=your-token-here ``` **Note:** `CLOUDFLARE_API_TOKEN` (scoped DNS token) is different from `CLOUDFLARE_API_KEY` (global API key). We use the scoped token for security. --- ## How It Works ### Deployment Flow ``` 1. Deploy Worker โ†“ 2. Check for existing DNS record GET /zones/{zone_id}/dns_records?type=CNAME&name=grab.aesthetic.computer โ†“ 3a. Record exists โ†’ Update PUT /zones/{zone_id}/dns_records/{record_id} OR 3b. Record doesn't exist โ†’ Create POST /zones/{zone_id}/dns_records โ†“ 4. Wait for DNS propagation Poll: curl https://grab.aesthetic.computer/icon/128x128/prompt.png Retry: Every 5 seconds for up to 60 seconds โ†“ 5. Success! Display URLs and test commands ``` ### DNS Record Created ```json { "type": "CNAME", "name": "grab", "content": "aesthetic-grab.aesthetic-computer.workers.dev", "ttl": 1, "proxied": true } ``` Result: `grab.aesthetic.computer` โ†’ `aesthetic-grab.aesthetic-computer.workers.dev` --- ## Script Output Example ``` ๐Ÿš€ Deploying grab worker with automatic DNS setup... โœ… Loaded environment variables from vault ๐Ÿ“ฆ Step 1: Deploying worker to Cloudflare... Total Upload: 684.44 KiB / gzip: 183.18 KiB Uploaded aesthetic-grab (2.34 sec) Published aesthetic-grab (0.19 sec) https://aesthetic-grab.aesthetic-computer.workers.dev Current Deployment ID: 511d31bc-c2e8-4f00-aea7-9b9d95e08733 โœ… Worker deployed successfully! ๐ŸŒ Step 2: Configuring DNS (CNAME record)... Zone: aesthetic.computer (a23b54e8877a833a1cf8db7765bce3ca) Creating: grab.aesthetic.computer โ†’ aesthetic-grab.aesthetic-computer.workers.dev Checking for existing DNS record... ๐ŸŸก Creating new CNAME record... โœ… DNS record configured successfully! โณ Step 3: Waiting for DNS propagation... This usually takes 30-60 seconds... Attempt 1/12: โณ Waiting... (HTTP 000) Attempt 2/12: โณ Waiting... (HTTP 000) Attempt 3/12: โœ… DNS working! โœจ Deployment complete! ๐Ÿ“Š Deployment Summary: Worker URL: https://aesthetic-grab.aesthetic-computer.workers.dev Custom URL: https://grab.aesthetic.computer DNS Record: grab.aesthetic.computer โ†’ aesthetic-grab.aesthetic-computer.workers.dev (CNAME, Proxied) ๐Ÿงช Test Commands: curl -I "https://grab.aesthetic.computer/icon/128x128/prompt.png" curl -I "https://grab.aesthetic.computer/preview/1200x630/prompt.png" ๐Ÿ“‹ Next Steps: 1. Test screenshot generation with various pieces 2. Monitor logs: npx wrangler tail 3. Check Cloudflare dashboard for errors 4. Validate production integration on aesthetic.computer ``` --- ## Comparison: Manual vs Automated | Method | Time | Steps | Automation | |--------|------|-------|------------| | **Manual Dashboard** | ~5-10 min | 1. Deploy worker
2. Open Dashboard
3. Navigate to DNS
4. Add record
5. Wait
6. Test | โŒ None | | **Manual API** | ~3-5 min | 1. Deploy worker
2. Run curl command
3. Wait
4. Test | โš ๏ธ Partial | | **Automated Script** | ~2-3 min | 1. Run script
2. โœ… Done! | โœ… Full | --- ## Troubleshooting ### Script Fails: "CLOUDFLARE_EMAIL not set" **Solution:** Add credentials to vault/.env: ```fish cd /workspaces/aesthetic-computer/aesthetic-computer-vault/grab nano .env # Add CLOUDFLARE_EMAIL and CLOUDFLARE_API_TOKEN ``` ### Script Fails: "DNS configuration failed" **Possible causes:** 1. API token doesn't have DNS edit permission 2. API token is for wrong zone 3. Network issue **Solution:** Check API token permissions or use manual DNS method: ```fish # Open dashboard open "https://dash.cloudflare.com/a23b54e8877a833a1cf8db7765bce3ca/aesthetic.computer/dns/records" # Manually add: # Type: CNAME # Name: grab # Target: aesthetic-grab.aesthetic-computer.workers.dev # Proxy: Enabled ``` ### DNS Not Propagating **Solution:** Wait longer (up to 5 minutes) or check manually: ```fish dig grab.aesthetic.computer curl -I "https://grab.aesthetic.computer/icon/128x128/prompt.png" ``` --- ## Pattern Used Across Aesthetic Computer This automated deployment pattern matches other services: - **nanos/conductor.mjs** - Deploys GCP instances + updates DNS - **dark-window/** - Similar DNS automation - **feed/** - Manual DNS (could be automated with this pattern) - **grab/** - โœ… Now fully automated! ### Benefits 1. โœ… **Consistency** - Same pattern across all services 2. โœ… **Speed** - Deployment + DNS in one command 3. โœ… **Reliability** - Automated verification 4. โœ… **Developer Experience** - No context switching to Dashboard 5. โœ… **CI/CD Ready** - Can be used in automation pipelines --- ## Alternative: Manual Methods If you prefer manual control or the script fails: ### Option 1: DNS Dashboard (2 minutes) ``` https://dash.cloudflare.com/a23b54e8877a833a1cf8db7765bce3ca/aesthetic.computer/dns/records ``` ### Option 2: Workers Dashboard (5 minutes) ``` Workers & Pages โ†’ aesthetic-grab โ†’ Settings โ†’ Domains & Routes ``` ### Option 3: API with curl ```fish curl -X POST "https://api.cloudflare.com/client/v4/zones/a23b54e8877a833a1cf8db7765bce3ca/dns_records" \ -H "X-Auth-Email: $CLOUDFLARE_EMAIL" \ -H "X-Auth-Key: $CLOUDFLARE_API_TOKEN" \ -H "Content-Type: application/json" \ --data '{ "type": "CNAME", "name": "grab", "content": "aesthetic-grab.aesthetic-computer.workers.dev", "proxied": true }' ``` All methods produce the same result! --- ## Security Notes ### API Token vs API Key - **API Token** (scoped, recommended): Limited to DNS editing only - **API Key** (global, avoid if possible): Full account access The script uses API Token for better security. ### Secrets Storage All secrets stored in `/aesthetic-computer-vault/grab/.env`: - โœ… In gitignore - โœ… Not committed to repo - โœ… Separate from code --- ## Summary **Before:** Manual DNS setup via Dashboard (~5-10 minutes) **After:** One command automated deployment (~2-3 minutes) ```fish ./scripts/deploy-with-dns.fish ``` That's it! ๐Ÿš€