-
Notifications
You must be signed in to change notification settings - Fork 39
Use Terraform to manage cloud-build triggers #1472
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
douglasjacobsen
merged 11 commits into
GoogleCloudPlatform:develop
from
linsword13:cloud-build-triggers
Mar 31, 2026
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2e03d4a
Set up the foundations for transitioning to Terraform
linsword13 48dca84
Add in the unit-test triggers
linsword13 9e2418a
Add in the perf test triggers
linsword13 3462397
Add in the image-build triggers
linsword13 005fa1c
Add in the doc build trigger
linsword13 a2dddd5
Add in the pr style and software conflict check triggers
linsword13 a709f5b
Add in the pr image-build test trigger
linsword13 fd5c7df
Reference image_matrix instead of hard-coding
linsword13 337facf
Restructure to define images as a map
linsword13 69ace4a
Set `INCLUDE_BUILD_LOGS_WITH_STATUS` for all PR-based triggers
linsword13 87b91dd
Fix up invalid (dot) trigger names
linsword13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # We don't ignore any tfstate files, as those should reside on the GCS bucket instead | ||
| .terraform/ | ||
| .terraform.lock.hcl |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # Ramble Cloud Build Image Triggers | ||
|
|
||
| This directory contains Terraform configuration to deploy and manage Google Cloud Build Triggers used by the Ramble repository. | ||
|
|
||
| ## How to deploy | ||
|
|
||
| The deployment states are stored in a GCS bucket, to allow for running Terraform from different locations. The bucket was created with: | ||
|
|
||
| ```bash | ||
| gcloud storage buckets create gs://ramble-terraform-state --project=ramble-eng --location=us-central1 | ||
| ``` | ||
|
|
||
| With the bucket created, the triggers can be deployed with: | ||
|
|
||
| ```bash | ||
| terraform init | ||
| # Optional to check the changes to be made | ||
| terraform plan | ||
| terraform apply --auto-approve | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| terraform { | ||
| backend "gcs" { | ||
| bucket = "ramble-terraform-state" | ||
| prefix = "terraform/state/image-triggers" | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
share/ramble/cloud-build/terraform/triggers/image_builds.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| resource "google_cloudbuild_trigger" "image_builders" { | ||
| for_each = local.image_map | ||
|
|
||
| name = "ramble-image-builder-${each.value.base}${replace(each.value.base_ver, ".", "-")}-py${replace(each.value.python, ".", "-")}-spack${replace(each.value.spack, ".", "-")}" | ||
| description = "Build Ramble cloud build image for ${each.value.base} ${each.value.base_ver} with Python ${each.value.python} and Spack ${each.value.spack}" | ||
|
|
||
| github { | ||
| owner = var.github_owner | ||
| name = var.github_repo | ||
| push { | ||
| branch = "^develop$" | ||
| } | ||
| } | ||
|
|
||
| included_files = [ | ||
| "share/ramble/cloud-build/ramble-image-builder.yaml", | ||
| "share/ramble/cloud-build/Dockerfile-${local.pm_map[each.value.base]}" | ||
| ] | ||
|
|
||
| filename = "share/ramble/cloud-build/ramble-image-builder.yaml" | ||
|
|
||
| substitutions = { | ||
| _PYTHON_VER = each.value.python | ||
| _SPACK_REF = each.value.spack | ||
| _PKG_MANAGER = local.pm_map[each.value.base] | ||
| _BASE_IMG = each.value.base | ||
| _BASE_VER = each.value.base_ver | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| locals { | ||
| # This map holds the full list of available images. | ||
| # A trigger should always reference these images instead of hard-coding new ones. | ||
| image_map = { | ||
| "debian12-5-py3-12-0-spack-v0-21-2" = { python = "3.12.0", spack = "v0.21.2", base = "debian", base_ver = "12.5" }, | ||
| "debian12-5-py3-8-0-spack-v0-21-2" = { python = "3.8.0", spack = "v0.21.2", base = "debian", base_ver = "12.5" }, | ||
| "debian12-5-py3-12-1-spack-v0-22-1" = { python = "3.12.1", spack = "v0.22.1", base = "debian", base_ver = "12.5" }, | ||
| "debian12-5-py3-8-0-spack-v0-22-1" = { python = "3.8.0", spack = "v0.22.1", base = "debian", base_ver = "12.5" }, | ||
| "debian12-5-py3-13-5-spack-v1-0-0" = { python = "3.13.5", spack = "v1.0.0", base = "debian", base_ver = "12.5" }, | ||
| "debian12-5-py3-7-17-spack-v1-0-0" = { python = "3.7.17", spack = "v1.0.0", base = "debian", base_ver = "12.5" }, | ||
| "rocky8-py3-12-0-spack-v0-21-2" = { python = "3.12.0", spack = "v0.21.2", base = "rockylinux", base_ver = "8" }, | ||
| "rocky8-py3-7-0-spack-v0-21-2" = { python = "3.7.0", spack = "v0.21.2", base = "rockylinux", base_ver = "8" }, | ||
| "rocky8-py3-12-1-spack-v0-22-1" = { python = "3.12.1", spack = "v0.22.1", base = "rockylinux", base_ver = "8" }, | ||
| "rocky8-py3-7-0-spack-v0-22-1" = { python = "3.7.0", spack = "v0.22.1", base = "rockylinux", base_ver = "8" }, | ||
| "rocky8-py3-13-5-spack-v1-0-0" = { python = "3.13.5", spack = "v1.0.0", base = "rockylinux", base_ver = "8" }, | ||
| "rocky8-py3-7-17-spack-v1-0-0" = { python = "3.7.17", spack = "v1.0.0", base = "rockylinux", base_ver = "8" }, | ||
| } | ||
|
|
||
| pm_map = { | ||
| "debian" = "apt" | ||
| "rockylinux" = "yum" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| locals { | ||
| perf_test_img = local.image_map["rocky8-py3-13-5-spack-v1-0-0"] | ||
| } | ||
|
|
||
| resource "google_cloudbuild_trigger" "perf_test_pr" { | ||
| name = "PerfTest-PR-${local.perf_test_img.base}${local.perf_test_img.base_ver}-${replace(local.perf_test_img.spack, ".", "-")}spack-${replace(local.perf_test_img.python, ".", "-")}python" | ||
| description = "Ramble perf tests for PR builds" | ||
|
|
||
| github { | ||
| owner = var.github_owner | ||
| name = var.github_repo | ||
| pull_request { | ||
| branch = "(?:main|develop)" | ||
| comment_control = "COMMENTS_ENABLED_FOR_EXTERNAL_CONTRIBUTORS_ONLY" | ||
| } | ||
| } | ||
|
|
||
| include_build_logs = "INCLUDE_BUILD_LOGS_WITH_STATUS" | ||
|
|
||
| filename = "share/ramble/cloud-build/ramble-perf-tests.yaml" | ||
|
|
||
| substitutions = { | ||
| _SPACK_REF = local.perf_test_img.spack | ||
| _PYTHON_VER = local.perf_test_img.python | ||
| _BASE_IMG = local.perf_test_img.base | ||
| _BASE_VER = local.perf_test_img.base_ver | ||
| _DATASET_ID = "ramble_metrics" | ||
| _PROJECT_ID = var.project_id | ||
| _TABLE_ID = "perf_test_durations" | ||
| _UPLOAD_TO_BQ = "false" | ||
| } | ||
| } | ||
|
|
||
| resource "google_cloudbuild_trigger" "perf_test_push" { | ||
| name = "PerfTest-Push-${local.perf_test_img.base}${local.perf_test_img.base_ver}-${replace(local.perf_test_img.spack, ".", "-")}spack-${replace(local.perf_test_img.python, ".", "-")}python" | ||
| description = "Continuous monitoring of Ramble performance for develop push" | ||
|
|
||
| github { | ||
| owner = var.github_owner | ||
| name = var.github_repo | ||
| push { | ||
| branch = "^develop$" | ||
| } | ||
| } | ||
|
|
||
| filename = "share/ramble/cloud-build/ramble-perf-tests.yaml" | ||
|
|
||
| substitutions = { | ||
| _SPACK_REF = local.perf_test_img.spack | ||
| _PYTHON_VER = local.perf_test_img.python | ||
| _BASE_IMG = local.perf_test_img.base | ||
| _BASE_VER = local.perf_test_img.base_ver | ||
| _DATASET_ID = "ramble_metrics" | ||
| _PROJECT_ID = var.project_id | ||
| _TABLE_ID = "perf_test_durations" | ||
| _UPLOAD_TO_BQ = "true" | ||
| } | ||
| } |
28 changes: 28 additions & 0 deletions
28
share/ramble/cloud-build/terraform/triggers/pr_doc_build.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| locals { | ||
| pr_doc_img = local.image_map["rocky8-py3-13-5-spack-v1-0-0"] | ||
| } | ||
|
|
||
| resource "google_cloudbuild_trigger" "pr_doc_build_tests" { | ||
| name = "PR-Doc-Build-Tests" | ||
| description = "A presubmit check for building Ramble documentation" | ||
|
|
||
| github { | ||
| owner = var.github_owner | ||
| name = var.github_repo | ||
| pull_request { | ||
| branch = "(?:main|develop)" | ||
| comment_control = "COMMENTS_ENABLED_FOR_EXTERNAL_CONTRIBUTORS_ONLY" | ||
| } | ||
| } | ||
|
|
||
| include_build_logs = "INCLUDE_BUILD_LOGS_WITH_STATUS" | ||
|
|
||
| filename = "share/ramble/cloud-build/ramble-pr-docs.yaml" | ||
|
|
||
| substitutions = { | ||
| _BASE_IMG = local.pr_doc_img.base | ||
| _BASE_VER = local.pr_doc_img.base_ver | ||
| _PYTHON_VER = local.pr_doc_img.python | ||
| _SPACK_REF = local.pr_doc_img.spack | ||
| } | ||
| } |
21 changes: 21 additions & 0 deletions
21
share/ramble/cloud-build/terraform/triggers/pr_image_build.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| resource "google_cloudbuild_trigger" "pr_image_build_tests" { | ||
| name = "PR-Image-Build-Tests" | ||
| description = "A presubmit check for building images used by other cloud build triggers" | ||
|
|
||
| github { | ||
| owner = var.github_owner | ||
| name = var.github_repo | ||
| pull_request { | ||
| branch = "(?:main|develop)" | ||
| comment_control = "COMMENTS_ENABLED_FOR_EXTERNAL_CONTRIBUTORS_ONLY" | ||
| } | ||
| } | ||
|
|
||
| include_build_logs = "INCLUDE_BUILD_LOGS_WITH_STATUS" | ||
|
|
||
| filename = "share/ramble/cloud-build/ramble-pr-image-builds.yaml" | ||
|
|
||
| included_files = [ | ||
| "share/ramble/cloud-build/**" | ||
| ] | ||
| } | ||
linsword13 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
34 changes: 34 additions & 0 deletions
34
share/ramble/cloud-build/terraform/triggers/pr_software_conflicts.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| locals { | ||
| pr_software_conflicts_img = local.image_map["rocky8-py3-12-1-spack-v0-22-1"] | ||
| } | ||
|
|
||
| resource "google_cloudbuild_trigger" "pr_software_conflicts" { | ||
| name = "PR-Software-Conflicts-${local.pr_software_conflicts_img.base}${local.pr_software_conflicts_img.base_ver}-${replace(local.pr_software_conflicts_img.spack, ".", "-")}spack-${replace(local.pr_software_conflicts_img.python, ".", "-")}python" | ||
| description = "Check for conflicts in application definitions on Ramble pull requests" | ||
|
|
||
| github { | ||
| owner = var.github_owner | ||
| name = var.github_repo | ||
| pull_request { | ||
| branch = "(?:main|develop)" | ||
| comment_control = "COMMENTS_ENABLED_FOR_EXTERNAL_CONTRIBUTORS_ONLY" | ||
| } | ||
| } | ||
|
|
||
| include_build_logs = "INCLUDE_BUILD_LOGS_WITH_STATUS" | ||
|
|
||
| filename = "share/ramble/cloud-build/ramble-pr-software-conflicts.yaml" | ||
|
|
||
| included_files = [ | ||
| "var/ramble/repos/**", | ||
| "lib/ramble/ramble/**", | ||
| "share/ramble/cloud-build/**" | ||
| ] | ||
|
|
||
| substitutions = { | ||
| _BASE_IMG = local.pr_software_conflicts_img.base | ||
| _BASE_VER = local.pr_software_conflicts_img.base_ver | ||
| _PYTHON_VER = local.pr_software_conflicts_img.python | ||
| _SPACK_REF = local.pr_software_conflicts_img.spack | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| locals { | ||
| pr_style_img = local.image_map["rocky8-py3-12-1-spack-v0-22-1"] | ||
| } | ||
|
|
||
| resource "google_cloudbuild_trigger" "pr_style" { | ||
| name = "PR-Style-${local.pr_style_img.base}${local.pr_style_img.base_ver}-${replace(local.pr_style_img.spack, ".", "-")}spack-${replace(local.pr_style_img.python, ".", "-")}python" | ||
| description = "Run linting on Ramble pull requests" | ||
|
|
||
| github { | ||
| owner = var.github_owner | ||
| name = var.github_repo | ||
| pull_request { | ||
| branch = "(?:main|develop)" | ||
| comment_control = "COMMENTS_ENABLED_FOR_EXTERNAL_CONTRIBUTORS_ONLY" | ||
| } | ||
| } | ||
|
|
||
| include_build_logs = "INCLUDE_BUILD_LOGS_WITH_STATUS" | ||
|
|
||
| filename = "share/ramble/cloud-build/ramble-pr-style.yaml" | ||
|
|
||
| substitutions = { | ||
| _BASE_IMG = local.pr_style_img.base | ||
| _BASE_VER = local.pr_style_img.base_ver | ||
| _PYTHON_VER = local.pr_style_img.python | ||
| _SPACK_REF = local.pr_style_img.spack | ||
| } | ||
| } |
37 changes: 37 additions & 0 deletions
37
share/ramble/cloud-build/terraform/triggers/pr_unit_tests.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| resource "google_cloudbuild_trigger" "pr_unit_tests" { | ||
| for_each = local.image_map | ||
|
|
||
| name = "PR-Unit-Tests-${each.value.base}${replace(each.value.base_ver, ".", "-")}-${replace(each.value.spack, ".", "-")}spack-${replace(each.value.python, ".", "-")}python" | ||
| description = "Run unit tests and linting on Ramble pull requests" | ||
|
|
||
| github { | ||
| owner = var.github_owner | ||
| name = var.github_repo | ||
| pull_request { | ||
| branch = "(?:main|develop)" | ||
| comment_control = "COMMENTS_ENABLED_FOR_EXTERNAL_CONTRIBUTORS_ONLY" | ||
| } | ||
| } | ||
|
|
||
| ignored_files = [ | ||
| "lib/ramble/docs/**" | ||
| ] | ||
|
|
||
| included_files = [ | ||
| "lib/ramble/**", | ||
| "var/ramble/repos/**", | ||
| "share/ramble/cloud-build/**", | ||
| "conftest.py" | ||
| ] | ||
|
|
||
| include_build_logs = "INCLUDE_BUILD_LOGS_WITH_STATUS" | ||
|
|
||
| filename = "share/ramble/cloud-build/ramble-pr-unit-tests.yaml" | ||
|
|
||
| substitutions = { | ||
| _BASE_IMG = each.value.base | ||
| _BASE_VER = each.value.base_ver | ||
| _PYTHON_VER = each.value.python | ||
| _SPACK_REF = each.value.spack | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| terraform { | ||
| required_providers { | ||
| google = { | ||
| source = "hashicorp/google" | ||
| version = "~> 7.0" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| provider "google" { | ||
| project = var.project_id | ||
| region = var.region | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| project_id = "ramble-eng" | ||
| region = "us-central1" | ||
| github_owner = "GoogleCloudPlatform" | ||
| github_repo = "ramble" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| variable "project_id" { | ||
| type = string | ||
| description = "The GCP Project ID to host the Cloud Build triggers" | ||
| } | ||
|
|
||
| variable "region" { | ||
| type = string | ||
| description = "The GCP Region to deploy the triggers into" | ||
| default = "us-central1" | ||
| } | ||
|
|
||
| variable "github_owner" { | ||
| type = string | ||
| description = "The GitHub organization or user hosting the repository" | ||
| default = "GoogleCloudPlatform" | ||
| } | ||
|
|
||
| variable "github_repo" { | ||
| type = string | ||
| description = "The GitHub repository name" | ||
| default = "ramble" | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.