# ๐Ÿš€ Auto-Deploy Implementation Plan **Status:** Phase 1 Complete - Ready for Full Implementation **Date:** 2026-03-08 --- ## ๐Ÿ“‹ REQUIREMENTS SUMMARY ### From User 1. โœ… **Gitea Integration** - Auto-create/update repos on git.moreminimore.com 2. โœ… **Easypanel Auth** - Username/password (auto-generate token) 3. โœ… **Unified .env** - Single file for all skills 4. โœ… **Install Script** - Auto-sync all skills to OpenCode global 5. โœ… **Auto-Detection** - New vs existing projects --- ## ๐Ÿ—๏ธ ARCHITECTURE ### Skills Structure ``` opencode-skill/ โ”œโ”€โ”€ .env.example # Unified template (ALL skills) โ”œโ”€โ”€ scripts/ โ”‚ โ””โ”€โ”€ install-skills.sh # Updated for unified .env โ””โ”€โ”€ skills/ โ”œโ”€โ”€ gitea-sync/ # NEW - Gitea automation โ”‚ โ”œโ”€โ”€ SKILL.md โ”‚ โ””โ”€โ”€ scripts/ โ”‚ โ”œโ”€โ”€ sync.py # Main script โ”‚ โ””โ”€โ”€ .env.example # (uses unified .env) โ”‚ โ”œโ”€โ”€ easypanel-deploy/ # UPDATED - Python script added โ”‚ โ”œโ”€โ”€ SKILL.md โ”‚ โ””โ”€โ”€ scripts/ โ”‚ โ”œโ”€โ”€ deploy.py # NEW - Auto-deploy with username/pass โ”‚ โ””โ”€โ”€ .env.example # (uses unified .env) โ”‚ โ””โ”€โ”€ website-creator/ # UPDATED - Auto-deploy integration โ”œโ”€โ”€ SKILL.md โ””โ”€โ”€ scripts/ โ”œโ”€โ”€ create_astro_website.py # Updated โ””โ”€โ”€ .env.example # (uses unified .env) ``` ### Unified .env File **Location during development:** `/Users/kunthawatgreethong/Gitea/opencode-skill/.env` **Location after install:** `~/.config/opencode/.env` **Contents:** ```bash # =========================================== # UNIFIED OPENCODE SKILLS CONFIGURATION # =========================================== # Gitea Configuration GITEA_URL=https://git.moreminimore.com GITEA_API_TOKEN=your-gitea-api-token GITEA_USERNAME=your-username # Easypanel Configuration EASYPANEL_URL=http://110.164.146.47:3000 EASYPANEL_USERNAME=your-username EASYPANEL_PASSWORD=your-password EASYPANEL_DEFAULT_PROJECT=default # Umami Analytics (optional) UMAMI_DOMAIN=analytics.example.com # Admin (for all websites) ADMIN_PASSWORD=your-secure-password ``` --- ## ๐ŸŽฏ IMPLEMENTATION PHASES ### Phase 1: easypanel-deploy โœ… COMPLETE **Created:** - `scripts/deploy.py` - Full Python implementation - `scripts/.env.example` - Credentials template - `scripts/requirements.txt` - Dependencies **Features:** - Username/password authentication - Auto-generates API token - Follows exact workflow from SKILL.md - Creates project โ†’ service โ†’ connects Git โ†’ deploys - Checks deployment status **Usage:** ```bash cd skills/easypanel-deploy python3 scripts/deploy.py \ --project my-website \ --service my-website-service \ --git-url https://git.moreminimore.com/user/my-website.git ``` --- ### Phase 2: gitea-sync โณ NEXT **To Create:** - New skill: `gitea-sync` - Python script for Gitea API - Auto-detect new/existing repos - Push code automatically **Features:** ```python # sync.py - Planned functionality def check_repo_exists(username, repo_name): """Check if repository exists on Gitea.""" response = requests.get( f"{GITEA_URL}/api/v1/repos/{username}/{repo_name}", headers={"Authorization": f"token {GITEA_API_TOKEN}"} ) return response.status_code == 200 def create_repo(repo_name, description=""): """Create new repository.""" if check_repo_exists(GITEA_USERNAME, repo_name): print(f"โœ… Repository exists: {repo_name}") return update_repo(repo_name) else: print(f"๐Ÿ“ฆ Creating repository: {repo_name}") response = requests.post( f"{GITEA_URL}/api/v1/user/repos", headers={"Authorization": f"token {GITEA_API_TOKEN}"}, json={ "name": repo_name, "description": description, "private": False, "auto_init": True } ) return response.json() def push_code(repo_path, git_url): """Push code to Gitea repository.""" subprocess.run(["git", "init"], cwd=repo_path) subprocess.run(["git", "add", "."], cwd=repo_path) subprocess.run(["git", "commit", "-m", "Initial commit"], cwd=repo_path) subprocess.run(["git", "remote", "add", "origin", git_url], cwd=repo_path) subprocess.run(["git", "push", "-u", "origin", "main"], cwd=repo_path) ``` **Usage:** ```bash python3 scripts/sync.py \ --repo my-website \ --path ./my-website \ --description "My PDPA-compliant website" ``` --- ### Phase 3: website-creator Integration โณ PENDING **Update:** `create_astro_website.py` **Add auto-deploy workflow:** ```python def auto_deploy(website_path, website_name, args): """Complete auto-deploy workflow.""" # Step 1: Sync to Gitea print("๐Ÿ“ฆ Syncing to Gitea...") git_url = f"https://git.moreminimore.com/{GITEA_USERNAME}/{website_name}.git" subprocess.run([ "python3", f"{SKILLS_DIR}/gitea-sync/scripts/sync.py", "--repo", website_name, "--path", str(website_path), "--description", f"Auto-generated website: {website_name}" ]) # Step 2: Deploy to Easypanel print("๐Ÿš€ Deploying to Easypanel...") subprocess.run([ "python3", f"{SKILLS_DIR}/easypanel-deploy/scripts/deploy.py", "--project", website_name, "--service", f"{website_name}-service", "--git-url", git_url, "--branch", "main", "--port", "80" ]) # Step 3: Return deployment URL print("โœ… Deployment complete!") print(f"๐ŸŒ URL: https://{website_name}.easypanel.app") ``` **Integration point:** At end of `main()` function, after website generation. --- ### Phase 4: install-skills.sh Update โณ PENDING **Current behavior:** - Prompts for each skill's .env separately - Creates .env files in each skill directory **New behavior:** - Single unified .env at repo root - Copies to `~/.config/opencode/.env` - All skills read from same file **Updated workflow:** ```bash #!/bin/bash # 1. Check for unified .env.example if [ -f "${REPO_ROOT}/.env.example" ]; then # Prompt for unified .env create_unified_env fi # 2. Install skills for skill in $SKILLS; do cp -r "${SKILLS_DIR}/${skill}" "$TARGET" # Create skill-specific .env that sources unified .env cat > "${TARGET}/${skill}/scripts/.env" << EOF # Auto-generated - sources unified .env # Edit ${HOME}/.config/opencode/.env instead EOF done # 3. Copy unified .env to global location cp "${REPO_ROOT}/.env" "${HOME}/.config/opencode/.env" chmod 600 "${HOME}/.config/opencode/.env" ``` --- ### Phase 5: Unified .env.example โณ PENDING **Create:** `/Users/kunthawatgreethong/Gitea/opencode-skill/.env.example` ```bash # =========================================== # OPENCODE SKILLS - UNIFIED CONFIGURATION # =========================================== # Copy this file to .env and fill in your values # This file is shared by ALL skills # =========================================== # Gitea Configuration # Get API token from: https://git.moreminimore.com/user/settings/applications GITEA_URL=https://git.moreminimore.com GITEA_API_TOKEN= GITEA_USERNAME= # Easypanel Configuration # Login credentials for auto-deployment EASYPANEL_URL=http://110.164.146.47:3000 EASYPANEL_USERNAME= EASYPANEL_PASSWORD= EASYPANEL_DEFAULT_PROJECT=default # Website Defaults # Applied to all generated websites ADMIN_PASSWORD= UMAMI_DOMAIN=analytics.example.com # Optional: Umami Analytics # Leave empty if not using UMAMI_WEBSITE_ID= ``` --- ## ๐Ÿ“Š DEPLOYMENT WORKFLOW ### Complete Auto-Deploy Flow ``` User runs: python3 create_astro_website.py --name "mysite" --output "./mysite" โ†“ 1. Generate website structure - Astro project - PDPA pages - Docker files โ†“ 2. Auto-sync to Gitea (NEW) - Check if repo exists - Create if new - Update if exists - Push code โ†“ 3. Auto-deploy to Easypanel (NEW) - Authenticate (username/pass โ†’ token) - Create project - Create service - Connect Git - Set build type (Dockerfile) - Trigger deployment โ†“ 4. Return deployment URL โœ… https://mysite.easypanel.app ``` --- ## ๐Ÿ”ง ENVIRONMENT VARIABLE FLOW ``` Development: โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ /Users/kunthawatgreethong/Gitea/ โ”‚ โ”‚ opencode-skill/.env โ”‚ โ† User edits this โ”‚ โ”‚ โ”‚ [GITEA_API_TOKEN=xxx] โ”‚ โ”‚ [EASYPANEL_USERNAME=xxx] โ”‚ โ”‚ [ADMIN_PASSWORD=xxx] โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ install-skills.sh reads โ†“ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ ~/.config/opencode/.env โ”‚ โ† Skills read this โ”‚ (copied from repo root) โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ Python scripts load via: โ”‚ load_env() from parent โ†“ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ skills/ โ”‚ โ”œโ”€โ”€ gitea-sync/scripts/sync.py โ”‚ โ”‚ โ”œโ”€โ”€ easypanel-deploy/scripts/ โ”‚ โ”‚ โ””โ”€โ”€ website-creator/scripts/ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ ``` --- ## ๐ŸŽฏ IMPLEMENTATION PRIORITY ### Must Have (MVP) 1. โœ… easypanel-deploy script - **DONE** 2. โณ gitea-sync script 3. โณ Unified .env.example 4. โณ Updated install-skills.sh ### Should Have 5. โณ website-creator integration 6. โณ Auto-deploy on generation ### Nice to Have 7. โณ Status checking 8. โณ Rollback capability 9. โณ Multi-project support --- ## โš ๏ธ KNOWN ISSUES TO FIX ### easypanel-deploy - LSP errors (minor, script works) - Need to test authentication flow - Error handling needs improvement ### gitea-sync - Not yet created - Need Gitea API token from user ### install-skills.sh - Doesn't handle unified .env yet - Doesn't update existing installations --- ## ๐Ÿงช TESTING PLAN ### Test 1: easypanel-deploy ```bash cd skills/easypanel-deploy python3 scripts/deploy.py --help # Should show all options ``` ### Test 2: gitea-sync ```bash cd skills/gitea-sync python3 scripts/sync.py --help # Should show all options ``` ### Test 3: Unified .env ```bash cd /Users/kunthawatgreethong/Gitea/opencode-skill ./scripts/install-skills.sh # Should prompt for unified .env # Should copy to ~/.config/opencode/.env ``` ### Test 4: End-to-End ```bash python3 scripts/create_astro_website.py \ --name "test-site" \ --auto-deploy # NEW flag # Should: generate โ†’ gitea โ†’ easypanel โ†’ URL ``` --- ## ๐Ÿ“ NEXT STEPS ### Immediate (User Action Required) 1. **Provide Gitea API Token** - Go to: https://git.moreminimore.com/user/settings/applications - Generate new token - Add to .env file 2. **Verify Easypanel Credentials** - Test username/password - Confirm API access works 3. **Review This Plan** - Confirm architecture is correct - Approve before I continue implementation ### Next Implementation Session 1. Create gitea-sync skill 2. Create unified .env.example 3. Update install-skills.sh 4. Integrate with website-creator 5. Test complete workflow --- ## โ“ QUESTIONS FOR USER 1. **Gitea Organization**: Should repos be created under your personal account or an organization? - **Your answer:** Personal account โœ… 2. **Easypanel Auth**: Confirm username/password works (not just API token) - **Your answer:** Username/password preferred โœ… 3. **Unified .env Location**: Confirm locations - Dev: `/Users/kunthawatgreethong/Gitea/opencode-skill/.env` โœ… - Production: `~/.config/opencode/.env` โœ… 4. **Auto-Deploy Default**: Should auto-deploy be: - A) Always on (every website auto-deploys) - B) Optional (--auto-deploy flag) - C) Ask interactively --- **Status:** Ready to proceed with Phase 2 (gitea-sync) pending your review of this plan.