|
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | 14 | # |
15 | | -# Child Cloud Build configuration for deploying to a specific environment. |
16 | | -# Defaults are set to PRODUCTION. Staging builds must override these values. |
17 | | -# |
| 15 | +# Parent Cloud Build configuration that orchestrates Staging and Production deployments. |
| 16 | +# Usage: gcloud builds submit . --config=cloudbuild.yaml --project=datcom-ci |
| 17 | + |
18 | 18 | substitutions: |
19 | | - # Production config. |
20 | | - _PROJECT_ID: 'datcom-import-automation-prod' |
21 | | - _SPANNER_PROJECT_ID: 'datcom-store' |
22 | | - _SPANNER_INSTANCE_ID: 'dc-kg-test' |
23 | | - _SPANNER_DATABASE_ID: 'dc_graph_import' |
24 | | - _SPANNER_GRAPH_DATABASE_ID: 'dc_graph_2025_11_07' |
25 | | - _GCS_BUCKET_ID: 'datcom-prod-imports' |
26 | | - _LOCATION: 'us-central1' |
27 | | - _GCS_MOUNT_BUCKET: 'datcom-volume-mount' |
| 19 | + # Staging Configuration (Overrides defaults in child build) |
| 20 | + _PROJECT_ID: 'datcom-ci' |
| 21 | + _SPANNER_PROJECT_ID: 'datcom-ci' |
| 22 | + _SPANNER_INSTANCE_ID: 'datcom-spanner-test' |
| 23 | + _SPANNER_DATABASE_ID: 'dc-test-db' |
| 24 | + _SPANNER_GRAPH_DATABASE_ID: 'dc-test-db' |
| 25 | + _GCS_BUCKET_ID: 'datcom-ci-test' |
| 26 | + _GCS_MOUNT_BUCKET: 'datcom-ci-test' |
28 | 27 | _BQ_DATASET_ID: 'datacommons' |
29 | | - _PROJECT_NUMBER: '965988403328' |
| 28 | + _LOCATION: 'us-central1' |
| 29 | + _PROJECT_NUMBER: '879489846695' |
30 | 30 | _AR_REPO_URL: 'us-docker.pkg.dev/datcom-ci/gcr.io' |
31 | | - _BQ_SPANNER_CONN_ID: 'projects/datcom-import-automation-prod/locations/us/connections/bq_spanner_conn' |
| 31 | + _BQ_SPANNER_CONN_ID: 'projects/datcom-ci/locations/us-central1/connections/bq_spanner_conn_test' |
| 32 | + _VERSION: '${SHORT_SHA}' |
| 33 | + _DATAFLOW_TEMPLATE_PATH: 'gs://datcom-templates/templates/flex/ingestion.json' |
| 34 | + _PROD_TAG: 'latest' # TODO: rename to prod |
32 | 35 |
|
33 | 36 | steps: |
34 | | -- id: 'ingestion-helper-service' |
| 37 | + |
| 38 | +# 1. Build and push helper images |
| 39 | +- id: 'build-ingestion-helper' |
| 40 | + name: 'gcr.io/cloud-builders/gcloud' |
| 41 | + args: ['builds', 'submit', 'ingestion-helper', '--config', 'ingestion-helper/cloudbuild.yaml', '--substitutions', '_AR_REPO_URL=${_AR_REPO_URL},_VERSION=${_VERSION}'] |
| 42 | + dir: 'import-automation/workflow' |
| 43 | + |
| 44 | +- id: 'build-import-helper' |
35 | 45 | name: 'gcr.io/cloud-builders/gcloud' |
36 | | - args: ['run', 'deploy', 'ingestion-helper-service', '--image', '${_AR_REPO_URL}/datacommons-ingestion-helper:latest', '--region', '${_LOCATION}', '--project', '${_PROJECT_ID}', '--no-allow-unauthenticated', '--timeout', '60m', '--set-env-vars', 'PROJECT_ID=${_PROJECT_ID},LOCATION=${_LOCATION},SPANNER_PROJECT_ID=${_SPANNER_PROJECT_ID},SPANNER_INSTANCE_ID=${_SPANNER_INSTANCE_ID},SPANNER_DATABASE_ID=${_SPANNER_DATABASE_ID},SPANNER_GRAPH_DATABASE_ID=${_SPANNER_GRAPH_DATABASE_ID},GCS_BUCKET_ID=${_GCS_BUCKET_ID},BQ_DATASET_ID=${_BQ_DATASET_ID},BQ_SPANNER_CONN_ID=${_BQ_SPANNER_CONN_ID}'] |
| 46 | + args: ['builds', 'submit', 'import-helper', '--config', 'import-helper/cloudbuild.yaml', '--substitutions', '_AR_REPO_URL=${_AR_REPO_URL},_VERSION=${_VERSION}'] |
| 47 | + dir: 'import-automation/workflow' |
37 | 48 |
|
38 | | -- id: 'import-helper-service' |
| 49 | +# 2. Trigger Staging Build (Child) |
| 50 | +# Overrides default (Production) values with Staging values. |
| 51 | +- id: 'deploy-staging' |
39 | 52 | name: 'gcr.io/cloud-builders/gcloud' |
40 | | - args: ['run', 'deploy', 'import-helper-service', '--image', '${_AR_REPO_URL}/datacommons-import-helper:latest', '--region', '${_LOCATION}', '--project', '${_PROJECT_ID}', '--no-allow-unauthenticated', '--set-env-vars', 'PROJECT_ID=${_PROJECT_ID},LOCATION=${_LOCATION},PROJECT_NUMBER=${_PROJECT_NUMBER},GCS_BUCKET_ID=${_GCS_BUCKET_ID}'] |
| 53 | + args: |
| 54 | + - 'builds' |
| 55 | + - 'submit' |
| 56 | + - '.' |
| 57 | + - '--config=deploy-services.yaml' |
| 58 | + - '--project=${_PROJECT_ID}' |
| 59 | + - '--substitutions=_PROJECT_ID=${_PROJECT_ID},_SPANNER_PROJECT_ID=${_SPANNER_PROJECT_ID},_SPANNER_INSTANCE_ID=${_SPANNER_INSTANCE_ID},_SPANNER_DATABASE_ID=${_SPANNER_DATABASE_ID},_SPANNER_GRAPH_DATABASE_ID=${_SPANNER_GRAPH_DATABASE_ID},_GCS_BUCKET_ID=${_GCS_BUCKET_ID},_LOCATION=${_LOCATION},_GCS_MOUNT_BUCKET=${_GCS_MOUNT_BUCKET},_BQ_DATASET_ID=${_BQ_DATASET_ID},_PROJECT_NUMBER=${_PROJECT_NUMBER},_BQ_SPANNER_CONN_ID=${_BQ_SPANNER_CONN_ID},_VERSION=${_VERSION},_DATAFLOW_TEMPLATE_PATH=${_DATAFLOW_TEMPLATE_PATH}' |
| 60 | + dir: 'import-automation/workflow' |
| 61 | + |
| 62 | +# 2. Run E2E Tests on Staging |
| 63 | +- id: 'e2e-test-staging' |
| 64 | + name: 'python:3.11' |
| 65 | + entrypoint: 'bash' |
| 66 | + args: |
| 67 | + - '-c' |
| 68 | + - | |
| 69 | + pip install google-cloud-spanner google-cloud-workflows absl-py |
| 70 | + python spanner_ingestion_test.py |
| 71 | + env: |
| 72 | + - 'PROJECT_ID=${_PROJECT_ID}' |
| 73 | + - 'LOCATION=${_LOCATION}' |
| 74 | + - 'SPANNER_PROJECT_ID=${_SPANNER_PROJECT_ID}' |
| 75 | + - 'SPANNER_INSTANCE_ID=${_SPANNER_INSTANCE_ID}' |
| 76 | + - 'SPANNER_DATABASE_ID=${_SPANNER_DATABASE_ID}' |
| 77 | + - 'GCS_BUCKET_ID=${_GCS_BUCKET_ID}' |
| 78 | + dir: 'import-automation/workflow' |
41 | 79 |
|
42 | | -- id: 'import-automation-workflow' |
| 80 | +- id: 'tag-prod' |
43 | 81 | name: 'gcr.io/cloud-builders/gcloud' |
44 | | - args: ['workflows', 'deploy', 'import-automation-workflow', '--project', '${_PROJECT_ID}', '--location', '${_LOCATION}', '--source', 'import-automation-workflow.yaml', '--set-env-vars', 'LOCATION=${_LOCATION},GCS_BUCKET_ID=${_GCS_BUCKET_ID},GCS_MOUNT_BUCKET=${_GCS_MOUNT_BUCKET},PROJECT_NUMBER=${_PROJECT_NUMBER}'] |
| 82 | + args: ['builds', 'submit', '.', '--config', 'tag-prod.yaml', '--substitutions', '_AR_REPO_URL=${_AR_REPO_URL},_PROD_TAG=${_PROD_TAG},_VERSION=${_VERSION}'] |
| 83 | + dir: 'import-automation/workflow' |
45 | 84 |
|
46 | | -- id: 'spanner-ingestion-workflow' |
| 85 | +# 3. Trigger Production Build (Child) |
| 86 | +# Uses default (Production) values defined in cloudbuild.yaml. |
| 87 | +- id: 'deploy-prod' |
47 | 88 | name: 'gcr.io/cloud-builders/gcloud' |
48 | | - args: ['workflows', 'deploy', 'spanner-ingestion-workflow', '--project', '${_PROJECT_ID}', '--location', '${_LOCATION}', '--source', 'spanner-ingestion-workflow.yaml', '--set-env-vars', 'LOCATION=${_LOCATION},PROJECT_ID=${_PROJECT_ID},SPANNER_PROJECT_ID=${_SPANNER_PROJECT_ID},SPANNER_INSTANCE_ID=${_SPANNER_INSTANCE_ID},SPANNER_DATABASE_ID=${_SPANNER_GRAPH_DATABASE_ID},PROJECT_NUMBER=${_PROJECT_NUMBER}'] |
| 89 | + args: |
| 90 | + - 'builds' |
| 91 | + - 'submit' |
| 92 | + - '.' |
| 93 | + - '--config=deploy-services.yaml' |
| 94 | + - '--project=${_PROJECT_ID}' # Build runs in CI project, deploys to Prod |
| 95 | + - '--substitutions=_VERSION=${_PROD_TAG}' |
| 96 | + dir: 'import-automation/workflow' |
49 | 97 |
|
50 | 98 | options: |
51 | 99 | logging: CLOUD_LOGGING_ONLY |
0 commit comments