Skip to content

Commit 72e4991

Browse files
authored
feat(prototype): allow for manual cloud run deployment (#4)
This diff adds `cloudbuild.yml` and explains how to manually deploy using cloud run. We know this works because we successfully deployed the streamlit app.
1 parent 8c20fd8 commit 72e4991

File tree

3 files changed

+105
-1
lines changed

3 files changed

+105
-1
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ On other platforms, see the [uv installation guide](https://docs.astral.sh/uv/ge
7373

7474
```bash
7575
# Clone the repository
76-
git clone https://github.com/m-lab/iqb.git
76+
git clone git@github.com:m-lab/iqb.git
7777
cd iqb
7878

7979
# Sync all dependencies (creates .venv automatically)
@@ -85,5 +85,9 @@ uv run streamlit run Home.py
8585
```
8686

8787
See component-specific READMEs for more details:
88+
89+
- [analysis/README.md](analysis/README.md) - Working with Jupyter notebooks
90+
8891
- [library/README.md](library/README.md) - Working with the IQB library
92+
8993
- [prototype/README.md](prototype/README.md) - Running the Streamlit app

cloudbuild.yaml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Cloud Build configuration for IQB prototype deployment
2+
# Used for manual deployment: gcloud builds submit --config=cloudbuild.yaml
3+
#
4+
# Based on M-Lab token-exchange pattern, adapted for mlab-sandbox environment
5+
6+
substitutions:
7+
# Default values, can be overridden when submitting the build
8+
_REGION: us-central1
9+
_REPOSITORY: cloud-run-source-deploy # Same as github.com/sermpezis/m-lab-servers-dashboard
10+
_SERVICE_NAME: iqb-prototype
11+
_MEMORY: 1Gi
12+
_CPU: "2"
13+
14+
steps:
15+
# 1. Build the Docker image from prototype/Dockerfile
16+
- name: "gcr.io/cloud-builders/docker"
17+
id: Build
18+
args:
19+
- "build"
20+
- "-f"
21+
- "prototype/Dockerfile"
22+
- "-t"
23+
- "${_REGION}-docker.pkg.dev/${PROJECT_ID}/${_REPOSITORY}/${_SERVICE_NAME}:$BUILD_ID"
24+
- "-t"
25+
- "${_REGION}-docker.pkg.dev/${PROJECT_ID}/${_REPOSITORY}/${_SERVICE_NAME}:latest"
26+
- "."
27+
28+
# 2. Push the container image to Artifact Registry
29+
# Note: This explicit push ensures the image exists before Deploy step runs.
30+
# The BUILD_ID tag gets pushed again via images: section (harmless, just updates metadata).
31+
- name: "gcr.io/cloud-builders/docker"
32+
id: Push
33+
args:
34+
- "push"
35+
- "${_REGION}-docker.pkg.dev/${PROJECT_ID}/${_REPOSITORY}/${_SERVICE_NAME}:$BUILD_ID"
36+
waitFor: ["Build"]
37+
38+
# 3. Deploy to Cloud Run
39+
- name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
40+
id: Deploy
41+
entrypoint: gcloud
42+
args:
43+
- "run"
44+
- "deploy"
45+
- "${_SERVICE_NAME}"
46+
- "--image"
47+
- "${_REGION}-docker.pkg.dev/${PROJECT_ID}/${_REPOSITORY}/${_SERVICE_NAME}:$BUILD_ID"
48+
- "--platform"
49+
- "managed"
50+
- "--region"
51+
- "${_REGION}"
52+
- "--allow-unauthenticated"
53+
- "--memory=${_MEMORY}"
54+
- "--cpu=${_CPU}"
55+
- "--project=${PROJECT_ID}"
56+
waitFor: ["Push"]
57+
58+
# Push both tagged and latest images to registry
59+
images:
60+
- "${_REGION}-docker.pkg.dev/${PROJECT_ID}/${_REPOSITORY}/${_SERVICE_NAME}:$BUILD_ID"
61+
- "${_REGION}-docker.pkg.dev/${PROJECT_ID}/${_REPOSITORY}/${_SERVICE_NAME}:latest"
62+
63+
# Build timeout (20 minutes)
64+
timeout: 1200s

prototype/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,42 @@ docker stop iqb-test
7474
docker rm iqb-test
7575
```
7676

77+
## Deploying to Cloud Run (Manual)
78+
79+
Deploy to Google Cloud Run using Cloud Build:
80+
81+
```bash
82+
# From the directory containing cloudbuild.yaml
83+
gcloud builds submit --config=cloudbuild.yaml --project=mlab-sandbox
84+
```
85+
86+
This will:
87+
1. Build the Docker image from `prototype/Dockerfile`
88+
2. Push to Artifact Registry (`us-central1-docker.pkg.dev/mlab-sandbox/cloud-run-source-deploy`)
89+
3. Deploy to Cloud Run in `us-central1` region
90+
91+
**Configuration:** See `cloudbuild.yaml` for deployment settings (memory, CPU, region).
92+
93+
**Permissions required:**
94+
- `roles/editor` - Deploy and update services
95+
- `roles/run.admin` - Make new services public (only needed once per service)
96+
97+
**Making the service public:**
98+
99+
If deploying a new service or if you get 403 errors, an admin needs to run:
100+
101+
```bash
102+
gcloud run services add-iam-policy-binding iqb-prototype \
103+
--region=us-central1 \
104+
--member="allUsers" \
105+
--role="roles/run.invoker" \
106+
--project=mlab-sandbox
107+
```
108+
109+
This IAM policy persists across deployments, so it's only needed once.
110+
111+
**Current deployment:** https://iqb-prototype-581276032543.us-central1.run.app/
112+
77113
## Dependencies
78114

79115
The prototype depends on:

0 commit comments

Comments
 (0)