Alikestocode commited on
Commit
fd26b3d
Β·
1 Parent(s): 1b04006

Add Cloud Build deployment script and permission setup helper

Browse files

- deploy-cloud-build.sh: Uses Cloud Build service (no local Docker needed)
- setup-gcp-permissions.sh: Helper to create project and enable APIs
- Updated cloudbuild.yaml with better substitutions
- QUICK_DEPLOY.md: Troubleshooting guide for permission issues

QUICK_DEPLOY.md ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Quick Deploy to Google Cloud Run
2
+
3
+ ## Current Status
4
+
5
+ **Issue**: Permission denied on project `light-quest-475608-k7`
6
+
7
+ ## Quick Fix Options
8
+
9
+ ### Option 1: Fix Permissions (Recommended)
10
+
11
+ 1. **Grant yourself permissions** on the existing project:
12
+ - Visit: https://console.cloud.google.com/iam-admin/iam/project?project=light-quest-475608-k7
13
+ - Add role: `Editor` or `Owner` to your account (`jameswilsonlearnsrocode@gmail.com`)
14
+ - Wait 2-3 minutes for propagation
15
+
16
+ 2. **Enable APIs**:
17
+ ```bash
18
+ gcloud services enable cloudbuild.googleapis.com run.googleapis.com containerregistry.googleapis.com --project=light-quest-475608-k7
19
+ ```
20
+
21
+ 3. **Deploy**:
22
+ ```bash
23
+ cd Milestone-6/router-agent/zero-gpu-space
24
+ ./deploy-cloud-build.sh
25
+ ```
26
+
27
+ ### Option 2: Create New Project
28
+
29
+ ```bash
30
+ # Run setup helper
31
+ ./setup-gcp-permissions.sh
32
+
33
+ # Or manually:
34
+ gcloud projects create router-agent-deploy --name="Router Agent Deployment"
35
+ gcloud config set project router-agent-deploy
36
+ gcloud services enable cloudbuild.googleapis.com run.googleapis.com containerregistry.googleapis.com
37
+
38
+ # Then deploy
39
+ ./deploy-cloud-build.sh
40
+ ```
41
+
42
+ ### Option 3: Use Different Account/Project
43
+
44
+ If you have access to another project:
45
+
46
+ ```bash
47
+ export GCP_PROJECT_ID="your-other-project-id"
48
+ gcloud config set project ${GCP_PROJECT_ID}
49
+ ./deploy-cloud-build.sh
50
+ ```
51
+
52
+ ## Manual Deployment Steps
53
+
54
+ If scripts don't work, deploy manually:
55
+
56
+ ```bash
57
+ # 1. Set project
58
+ gcloud config set project YOUR_PROJECT_ID
59
+
60
+ # 2. Enable APIs (if not already enabled)
61
+ gcloud services enable cloudbuild.googleapis.com run.googleapis.com containerregistry.googleapis.com
62
+
63
+ # 3. Submit build
64
+ cd Milestone-6/router-agent/zero-gpu-space
65
+ gcloud builds submit --config=cloudbuild.yaml .
66
+
67
+ # 4. Or build and deploy separately
68
+ gcloud builds submit --tag gcr.io/YOUR_PROJECT_ID/router-agent:latest .
69
+ gcloud run deploy router-agent \
70
+ --image gcr.io/YOUR_PROJECT_ID/router-agent:latest \
71
+ --platform managed \
72
+ --region us-central1 \
73
+ --allow-unauthenticated \
74
+ --port 7860 \
75
+ --memory 8Gi \
76
+ --cpu 4
77
+ ```
78
+
79
+ ## Required Permissions
80
+
81
+ Your account needs these roles:
82
+ - `roles/cloudbuild.builds.editor` - To build images
83
+ - `roles/run.admin` - To deploy to Cloud Run
84
+ - `roles/serviceusage.serviceUsageConsumer` - To enable APIs
85
+ - `roles/storage.admin` - To push to Container Registry
86
+
87
+ Or use `roles/editor` or `roles/owner` for full access.
88
+
89
+ ## Troubleshooting
90
+
91
+ **Permission Denied**:
92
+ - Check IAM: https://console.cloud.google.com/iam-admin/iam
93
+ - Ensure billing is enabled
94
+ - Wait 2-3 minutes after granting permissions
95
+
96
+ **API Not Enabled**:
97
+ - Enable manually: https://console.cloud.google.com/apis/library
98
+ - Or use: `gcloud services enable <api-name>`
99
+
100
+ **Build Fails**:
101
+ - Check logs: `gcloud builds list` then `gcloud builds log BUILD_ID`
102
+ - Ensure Dockerfile is correct
103
+ - Check requirements.txt for compatibility
104
+
cloudbuild.yaml CHANGED
@@ -1,25 +1,23 @@
1
  # Cloud Build configuration for Google Cloud Run
 
 
2
  steps:
3
  # Build the container image
4
  - name: 'gcr.io/cloud-builders/docker'
5
  args:
6
  - 'build'
7
  - '-t'
8
- - 'gcr.io/$PROJECT_ID/router-agent:$COMMIT_SHA'
9
- - '-t'
10
  - 'gcr.io/$PROJECT_ID/router-agent:latest'
 
 
11
  - '.'
12
 
13
  # Push the container image
14
  - name: 'gcr.io/cloud-builders/docker'
15
  args:
16
  - 'push'
17
- - 'gcr.io/$PROJECT_ID/router-agent:$COMMIT_SHA'
18
-
19
- - name: 'gcr.io/cloud-builders/docker'
20
- args:
21
- - 'push'
22
- - 'gcr.io/$PROJECT_ID/router-agent:latest'
23
 
24
  # Deploy to Cloud Run (CPU only - for GPU use Compute Engine)
25
  - name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
@@ -29,11 +27,11 @@ steps:
29
  - 'deploy'
30
  - 'router-agent'
31
  - '--image'
32
- - 'gcr.io/$PROJECT_ID/router-agent:$COMMIT_SHA'
33
  - '--platform'
34
  - 'managed'
35
  - '--region'
36
- - 'us-central1'
37
  - '--allow-unauthenticated'
38
  - '--port'
39
  - '7860'
@@ -43,12 +41,17 @@ steps:
43
  - '4'
44
  - '--timeout'
45
  - '3600'
 
 
46
  - '--set-env-vars'
47
  - 'GRADIO_SERVER_NAME=0.0.0.0,GRADIO_SERVER_PORT=7860'
48
 
49
  images:
50
- - 'gcr.io/$PROJECT_ID/router-agent:$COMMIT_SHA'
51
  - 'gcr.io/$PROJECT_ID/router-agent:latest'
 
 
 
 
52
 
53
  options:
54
  machineType: 'E2_HIGHCPU_8'
 
1
  # Cloud Build configuration for Google Cloud Run
2
+ # Usage: gcloud builds submit --config=cloudbuild.yaml .
3
+
4
  steps:
5
  # Build the container image
6
  - name: 'gcr.io/cloud-builders/docker'
7
  args:
8
  - 'build'
9
  - '-t'
 
 
10
  - 'gcr.io/$PROJECT_ID/router-agent:latest'
11
+ - '-t'
12
+ - 'gcr.io/$PROJECT_ID/router-agent:$SHORT_SHA'
13
  - '.'
14
 
15
  # Push the container image
16
  - name: 'gcr.io/cloud-builders/docker'
17
  args:
18
  - 'push'
19
+ - '--all-tags'
20
+ - 'gcr.io/$PROJECT_ID/router-agent'
 
 
 
 
21
 
22
  # Deploy to Cloud Run (CPU only - for GPU use Compute Engine)
23
  - name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
 
27
  - 'deploy'
28
  - 'router-agent'
29
  - '--image'
30
+ - 'gcr.io/$PROJECT_ID/router-agent:latest'
31
  - '--platform'
32
  - 'managed'
33
  - '--region'
34
+ - '${_REGION}'
35
  - '--allow-unauthenticated'
36
  - '--port'
37
  - '7860'
 
41
  - '4'
42
  - '--timeout'
43
  - '3600'
44
+ - '--max-instances'
45
+ - '10'
46
  - '--set-env-vars'
47
  - 'GRADIO_SERVER_NAME=0.0.0.0,GRADIO_SERVER_PORT=7860'
48
 
49
  images:
 
50
  - 'gcr.io/$PROJECT_ID/router-agent:latest'
51
+ - 'gcr.io/$PROJECT_ID/router-agent:$SHORT_SHA'
52
+
53
+ substitutions:
54
+ _REGION: 'us-central1'
55
 
56
  options:
57
  machineType: 'E2_HIGHCPU_8'
deploy-cloud-build.sh ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # Deploy using Cloud Build (no local Docker required)
3
+ # This uses Google Cloud Build service to build and deploy
4
+
5
+ set -e
6
+
7
+ PROJECT_ID=${GCP_PROJECT_ID:-"light-quest-475608-k7"}
8
+ REGION=${GCP_REGION:-"us-central1"}
9
+ SERVICE_NAME="router-agent"
10
+
11
+ # Colors for output
12
+ RED='\033[0;31m'
13
+ GREEN='\033[0;32m'
14
+ YELLOW='\033[1;33m'
15
+ NC='\033[0m' # No Color
16
+
17
+ echo -e "${GREEN}πŸš€ Deploying Router Agent to Cloud Run using Cloud Build${NC}"
18
+
19
+ # Check if gcloud is installed
20
+ if ! command -v gcloud &> /dev/null; then
21
+ echo -e "${RED}❌ gcloud CLI not found. Please install it: https://cloud.google.com/sdk/docs/install${NC}"
22
+ exit 1
23
+ fi
24
+
25
+ # Set project
26
+ echo -e "${YELLOW}πŸ“‹ Setting project to ${PROJECT_ID}...${NC}"
27
+ gcloud config set project ${PROJECT_ID}
28
+
29
+ # Check if Cloud Build API is enabled
30
+ echo -e "${YELLOW}πŸ“‹ Checking Cloud Build API...${NC}"
31
+ if ! gcloud services list --enabled --filter="name:cloudbuild.googleapis.com" --format="value(name)" | grep -q cloudbuild; then
32
+ echo -e "${YELLOW}⚠️ Cloud Build API not enabled. Attempting to enable...${NC}"
33
+ gcloud services enable cloudbuild.googleapis.com run.googleapis.com containerregistry.googleapis.com || {
34
+ echo -e "${RED}❌ Failed to enable APIs. Please enable them manually:${NC}"
35
+ echo -e "${YELLOW} https://console.cloud.google.com/apis/library/cloudbuild.googleapis.com?project=${PROJECT_ID}${NC}"
36
+ exit 1
37
+ }
38
+ fi
39
+
40
+ # Submit build to Cloud Build
41
+ echo -e "${GREEN}πŸ“¦ Submitting build to Cloud Build...${NC}"
42
+ COMMIT_SHA=$(git rev-parse --short HEAD 2>/dev/null || echo "latest")
43
+
44
+ gcloud builds submit --config=cloudbuild.yaml \
45
+ --substitutions=_SERVICE_NAME=${SERVICE_NAME},_REGION=${REGION},COMMIT_SHA=${COMMIT_SHA} \
46
+ . || {
47
+ echo -e "${YELLOW}⚠️ Cloud Build failed. Trying alternative approach...${NC}"
48
+
49
+ # Alternative: Build and deploy separately
50
+ echo -e "${GREEN}πŸ“¦ Building image with Cloud Build...${NC}"
51
+ gcloud builds submit --tag gcr.io/${PROJECT_ID}/${SERVICE_NAME}:latest . || {
52
+ echo -e "${RED}❌ Build failed. Please check:${NC}"
53
+ echo -e "${YELLOW} 1. Cloud Build API is enabled${NC}"
54
+ echo -e "${YELLOW} 2. You have permissions (roles/cloudbuild.builds.editor)${NC}"
55
+ echo -e "${YELLOW} 3. Billing is enabled for the project${NC}"
56
+ exit 1
57
+ }
58
+
59
+ echo -e "${GREEN}πŸš€ Deploying to Cloud Run...${NC}"
60
+ gcloud run deploy ${SERVICE_NAME} \
61
+ --image gcr.io/${PROJECT_ID}/${SERVICE_NAME}:latest \
62
+ --platform managed \
63
+ --region ${REGION} \
64
+ --allow-unauthenticated \
65
+ --port 7860 \
66
+ --memory 8Gi \
67
+ --cpu 4 \
68
+ --timeout 3600 \
69
+ --max-instances 10 \
70
+ --set-env-vars "GRADIO_SERVER_NAME=0.0.0.0,GRADIO_SERVER_PORT=7860" \
71
+ --quiet || {
72
+ echo -e "${RED}❌ Deployment failed. Please check:${NC}"
73
+ echo -e "${YELLOW} 1. Cloud Run API is enabled${NC}"
74
+ echo -e "${YELLOW} 2. You have permissions (roles/run.admin)${NC}"
75
+ exit 1
76
+ }
77
+ }
78
+
79
+ echo -e "${GREEN}βœ… Deployment complete!${NC}"
80
+ SERVICE_URL=$(gcloud run services describe ${SERVICE_NAME} --platform managed --region ${REGION} --format 'value(status.url)' 2>/dev/null || echo "Check Cloud Console")
81
+ echo -e "${GREEN}🌐 Service URL: ${SERVICE_URL}${NC}"
82
+
setup-gcp-permissions.sh ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # Script to help set up GCP permissions and create a new project if needed
3
+
4
+ set -e
5
+
6
+ PROJECT_ID=${GCP_PROJECT_ID:-"light-quest-475608-k7"}
7
+
8
+ echo "πŸ”§ GCP Setup Helper"
9
+ echo "=================="
10
+ echo ""
11
+ echo "Current project: ${PROJECT_ID}"
12
+ echo ""
13
+
14
+ # Option 1: Create a new project
15
+ read -p "Create a new project? (y/N): " -n 1 -r
16
+ echo
17
+ if [[ $REPLY =~ ^[Yy]$ ]]; then
18
+ read -p "Enter new project ID (lowercase, hyphens only): " NEW_PROJECT_ID
19
+ read -p "Enter project name: " PROJECT_NAME
20
+
21
+ echo "Creating project..."
22
+ gcloud projects create ${NEW_PROJECT_ID} --name="${PROJECT_NAME}" || {
23
+ echo "❌ Failed to create project. It may already exist or you don't have permission."
24
+ exit 1
25
+ }
26
+
27
+ echo "Setting as active project..."
28
+ gcloud config set project ${NEW_PROJECT_ID}
29
+
30
+ echo "Enabling billing (you'll need to do this manually)..."
31
+ echo "Visit: https://console.cloud.google.com/billing/linkedaccount?project=${NEW_PROJECT_ID}"
32
+ read -p "Press Enter after enabling billing..."
33
+
34
+ PROJECT_ID=${NEW_PROJECT_ID}
35
+ fi
36
+
37
+ # Enable required APIs
38
+ echo ""
39
+ echo "Enabling required APIs..."
40
+ gcloud services enable \
41
+ cloudbuild.googleapis.com \
42
+ run.googleapis.com \
43
+ containerregistry.googleapis.com \
44
+ --project=${PROJECT_ID} || {
45
+ echo "⚠️ Failed to enable APIs. You may need:"
46
+ echo " 1. Billing enabled: https://console.cloud.google.com/billing?project=${PROJECT_ID}"
47
+ echo " 2. Permissions: roles/serviceusage.serviceUsageConsumer"
48
+ echo " 3. Owner role on the project"
49
+ exit 1
50
+ }
51
+
52
+ echo ""
53
+ echo "βœ… Setup complete!"
54
+ echo " Project ID: ${PROJECT_ID}"
55
+ echo ""
56
+ echo "Next steps:"
57
+ echo " 1. Set HF_TOKEN secret (if using private models)"
58
+ echo " 2. Run: ./deploy-cloud-build.sh"
59
+ echo ""
60
+