{"id":23933109,"url":"https://github.com/The-Swarm-Corporation/SwarmsXGCP","last_synced_at":"2025-09-11T15:33:45.634Z","repository":{"id":270757215,"uuid":"911364163","full_name":"The-Swarm-Corporation/SwarmsXGCP","owner":"The-Swarm-Corporation","description":"Deploy your agents on Cloud Run!","archived":false,"fork":false,"pushed_at":"2025-01-02T21:44:32.000Z","size":23,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-02T22:25:06.761Z","etag":null,"topics":["ai","gcp","google","googlecloud","ml","multi-agent","swarms"],"latest_commit_sha":null,"homepage":"https://swarms.ai","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/The-Swarm-Corporation.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["kyegomez"]}},"created_at":"2025-01-02T21:00:05.000Z","updated_at":"2025-01-02T21:44:35.000Z","dependencies_parsed_at":"2025-01-02T22:25:16.781Z","dependency_job_id":"21db8b4f-c4e8-4c48-8739-5e5197968e3f","html_url":"https://github.com/The-Swarm-Corporation/SwarmsXGCP","commit_stats":null,"previous_names":["the-swarm-corporation/swarmsxgcp"],"tags_count":0,"template":false,"template_full_name":"The-Swarm-Corporation/Swarms-Example-1-Click-Template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/The-Swarm-Corporation%2FSwarmsXGCP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/The-Swarm-Corporation%2FSwarmsXGCP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/The-Swarm-Corporation%2FSwarmsXGCP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/The-Swarm-Corporation%2FSwarmsXGCP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/The-Swarm-Corporation","download_url":"https://codeload.github.com/The-Swarm-Corporation/SwarmsXGCP/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232658224,"owners_count":18556979,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","gcp","google","googlecloud","ml","multi-agent","swarms"],"created_at":"2025-01-06T00:29:31.815Z","updated_at":"2025-01-06T00:30:43.227Z","avatar_url":"https://github.com/The-Swarm-Corporation.png","language":"Python","funding_links":["https://github.com/sponsors/kyegomez"],"categories":["Building"],"sub_categories":["Deployment"],"readme":"\n# Deploying Swarms on Google Cloud Platform (GCP) Cloud Run\n\n\n[![Join our Discord](https://img.shields.io/badge/Discord-Join%20our%20server-5865F2?style=for-the-badge\u0026logo=discord\u0026logoColor=white)](https://discord.gg/agora-999382051935506503) [![Subscribe on YouTube](https://img.shields.io/badge/YouTube-Subscribe-red?style=for-the-badge\u0026logo=youtube\u0026logoColor=white)](https://www.youtube.com/@kyegomez3242) [![Connect on LinkedIn](https://img.shields.io/badge/LinkedIn-Connect-blue?style=for-the-badge\u0026logo=linkedin\u0026logoColor=white)](https://www.linkedin.com/in/kye-g-38759a207/) [![Follow on X.com](https://img.shields.io/badge/X.com-Follow-1DA1F2?style=for-the-badge\u0026logo=x\u0026logoColor=white)](https://x.com/kyegomezb)\n\n\n[![GitHub stars](https://img.shields.io/github/stars/The-Swarm-Corporation/Legal-Swarm-Template?style=social)](https://github.com/The-Swarm-Corporation/Legal-Swarm-Template)\n[![Swarms Framework](https://img.shields.io/badge/Built%20with-Swarms-blue)](https://github.com/kyegomez/swarms)\n\n\n## Introduction\n\nThis guide provides a comprehensive walkthrough for deploying a **Swarms-based application** on **Google Cloud Platform (GCP) Cloud Run**. It covers setup, Dockerization, deployment, and best practices to ensure high availability, scalability, and security. This document assumes an enterprise audience with the goal of deploying production-ready applications.\n\n---\n\n## Prerequisites\n\nBefore starting, ensure you have the following:\n\n### 1. **GCP Account and Project Setup**\n   - Access to a GCP account.\n   - A GCP project created for this deployment.\n   - Billing enabled on the project.\n\n### 2. **Tools Installed**\n   - **Google Cloud SDK** ([Install Guide](https://cloud.google.com/sdk/docs/install))\n   - **Docker** ([Install Guide](https://docs.docker.com/get-docker/))\n   - **Python 3.8 or higher**\n\n### 3. **API Enablement**\nEnable the following APIs in your GCP project:\n   - **Cloud Run API**\n   - **Container Registry API** or **Artifact Registry API**\n\n### 4. **Code Structure**\nYour Swarms project should have the following directory structure:\n\n```plaintext\nproject-root/\n├── api/\n│   └── api.py\n├── requirements.txt\n├── Dockerfile\n└── .dockerignore\n```\n\n---\n\n## Step 1: Project Initialization\n\n### 1.1 Clone or Create the Swarms Application\nEnsure your application follows best practices for API design and uses **FastAPI** or an equivalent framework. Below is an example of `api.py`:\n\n```python\nfrom fastapi import FastAPI\n\napp = FastAPI()\n\n@app.get(\"/\")\ndef read_root():\n    return {\"message\": \"Welcome to Swarms API on GCP Cloud Run!\"}\n```\n\n### 1.2 Create the `requirements.txt`\nList all Python dependencies in the `requirements.txt` file. For example:\n\n```plaintext\nfastapi\nuvicorn[standard]\n```\n\n### 1.3 Create a `.dockerignore` File\nOptimize your Docker build process by excluding unnecessary files:\n\n```plaintext\n__pycache__/\n*.pyc\n*.pyo\n*.pyd\n.env\n.DS_Store\n```\n\n---\n\n## Step 2: Create the Dockerfile\n\nThe `Dockerfile` is essential for containerizing your application. Below is an enterprise-grade example:\n\n```dockerfile\n# Base image\nFROM python:3.9-slim\n\n# Set environment variables\nENV PYTHONDONTWRITEBYTECODE=1\nENV PYTHONUNBUFFERED=1\n\n# Set working directory\nWORKDIR /app\n\n# Copy application files\nCOPY api /app/api\nCOPY requirements.txt /app\n\n# Install dependencies\nRUN pip install --no-cache-dir -r requirements.txt\n\n# Expose port for the application\nEXPOSE 8080\n\n# Run the FastAPI application with Uvicorn\nCMD [\"uvicorn\", \"api.api:app\", \"--host\", \"0.0.0.0\", \"--port\", \"8080\"]\n```\n\n---\n\n## Step 3: Build and Test the Docker Image\n\n### 3.1 Build the Docker Image\nRun the following command from the root of your project:\n\n```bash\ndocker build -t swarms-api .\n```\n\n### 3.2 Test Locally\nTo verify that your application runs correctly:\n\n```bash\ndocker run -p 8080:8080 swarms-api\n```\n\nAccess the API by visiting `http://localhost:8080` in your browser.\n\n---\n\n## Step 4: Push the Docker Image to Google Container Registry\n\n### 4.1 Authenticate with GCP\nLogin and configure your project:\n\n```bash\ngcloud auth login\ngcloud config set project [PROJECT_ID]\n```\n\n### 4.2 Tag the Docker Image\nTag your Docker image for GCP Container Registry:\n\n```bash\ndocker tag swarms-api gcr.io/[PROJECT_ID]/swarms-api\n```\n\n### 4.3 Push the Image to Container Registry\nPush the image to GCP:\n\n```bash\ndocker push gcr.io/[PROJECT_ID]/swarms-api\n```\n\n---\n\n## Step 5: Deploy to Cloud Run\n\n### 5.1 Deploy the Application\nUse the following command to deploy your containerized application to Cloud Run:\n\n```bash\ngcloud run deploy swarms-api \\\n  --image gcr.io/[PROJECT_ID]/swarms-api \\\n  --platform managed \\\n  --region [REGION] \\\n  --allow-unauthenticated\n```\n\nReplace:\n- `[PROJECT_ID]` with your GCP project ID.\n- `[REGION]` with your desired deployment region (e.g., `us-central1`).\n\n### 5.2 Verify Deployment\nAfter deployment, you will receive a public URL. Visit the URL to confirm that your application is running.\n\n---\n\n## Step 6: Implement Enterprise-Level Best Practices\n\n### 6.1 Security Best Practices\n- **Authentication:** Use **IAM** to restrict access to Cloud Run services.\n- **Environment Variables:** Use GCP **Secret Manager** for managing sensitive data like API keys.\n- **Private Networking:** Deploy Cloud Run services within a **VPC** for secure communication.\n\n### 6.2 Scalability and Availability\n- **Auto-scaling:** Cloud Run automatically scales based on traffic. Ensure your application can handle multiple concurrent requests.\n- **Concurrency Settings:** Tune the `--max-instances` and `--concurrency` flags to optimize resource usage.\n\n### 6.3 Logging and Monitoring\nEnable logging and monitoring for better observability:\n\n```bash\ngcloud logging read \"resource.type=cloud_run_revision\" --limit 100\n```\n\nUse **Cloud Monitoring** dashboards to visualize metrics like request latency and error rates.\n\n---\n\n## Step 7: Continuous Integration and Deployment (CI/CD)\n\n### 7.1 Configure CI/CD Pipeline\nIntegrate with a CI/CD tool like **GitHub Actions**, **GitLab CI**, or **Google Cloud Build**. Below is an example GitHub Actions workflow:\n\n```yaml\nname: GCP Cloud Run Deployment\n\non:\n  push:\n    branches:\n      - main\n\njobs:\n  deploy:\n    runs-on: ubuntu-latest\n    steps:\n    - name: Checkout code\n      uses: actions/checkout@v3\n\n    - name: Set up Cloud SDK\n      uses: google-github-actions/setup-gcloud@v1\n      with:\n        project_id: ${{ secrets.GCP_PROJECT_ID }}\n        service_account_key: ${{ secrets.GCP_SA_KEY }}\n\n    - name: Authenticate Docker with GCP\n      run: gcloud auth configure-docker\n\n    - name: Build and push Docker image\n      run: |\n        docker build -t gcr.io/${{ secrets.GCP_PROJECT_ID }}/swarms-api .\n        docker push gcr.io/${{ secrets.GCP_PROJECT_ID }}/swarms-api\n\n    - name: Deploy to Cloud Run\n      run: |\n        gcloud run deploy swarms-api \\\n          --image gcr.io/${{ secrets.GCP_PROJECT_ID }}/swarms-api \\\n          --platform managed \\\n          --region us-central1 \\\n          --allow-unauthenticated\n```\n\n---\n\n## Troubleshooting\n\n### 8.1 Common Issues\n\n| Error                                  | Solution                                     |\n|----------------------------------------|---------------------------------------------|\n| **Permission denied**                  | Ensure correct IAM permissions for the user |\n| **Container fails to start**           | Check application logs in Cloud Run console |\n| **High latency or errors under load**  | Optimize concurrency settings and code      |\n\n### 8.2 Debugging Tips\n- Use `gcloud run logs read` to view logs in real-time.\n- Test APIs locally using tools like Postman or cURL.\n\n---\n\n## Conclusion\n\nBy following this guide, you have successfully deployed a Swarms application on GCP Cloud Run, leveraging enterprise-grade best practices for scalability, security, and CI/CD integration. For further improvements, explore advanced topics like **service meshes**, **multi-region deployments**, and **custom domains**.\n\nFor questions or contributions, contact [support@swarms.example.com].\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FThe-Swarm-Corporation%2FSwarmsXGCP","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FThe-Swarm-Corporation%2FSwarmsXGCP","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FThe-Swarm-Corporation%2FSwarmsXGCP/lists"}