|
| 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 |
0 commit comments