{"id":18616218,"url":"https://github.com/scottrigby/trigger-gcp-cloudbuild","last_synced_at":"2025-09-22T21:59:34.368Z","repository":{"id":139900735,"uuid":"120056544","full_name":"scottrigby/trigger-gcp-cloudbuild","owner":"scottrigby","description":"👋🌍☁️🏗 A hello world for Google Cloudbuild","archived":false,"fork":false,"pushed_at":"2018-02-14T22:22:11.000Z","size":51,"stargazers_count":5,"open_issues_count":0,"forks_count":6,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-11T11:40:28.003Z","etag":null,"topics":["cloudbuild","gcp","golang","hello-world","helm-charts","kubernetes"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/scottrigby.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-02-03T03:39:26.000Z","updated_at":"2020-02-15T07:13:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"292771b3-8d98-41c2-a892-5e2de745d8c6","html_url":"https://github.com/scottrigby/trigger-gcp-cloudbuild","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/scottrigby/trigger-gcp-cloudbuild","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scottrigby%2Ftrigger-gcp-cloudbuild","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scottrigby%2Ftrigger-gcp-cloudbuild/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scottrigby%2Ftrigger-gcp-cloudbuild/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scottrigby%2Ftrigger-gcp-cloudbuild/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scottrigby","download_url":"https://codeload.github.com/scottrigby/trigger-gcp-cloudbuild/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scottrigby%2Ftrigger-gcp-cloudbuild/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276481067,"owners_count":25649988,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-22T02:00:08.972Z","response_time":79,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloudbuild","gcp","golang","hello-world","helm-charts","kubernetes"],"created_at":"2024-11-07T03:34:23.659Z","updated_at":"2025-09-22T21:59:34.292Z","avatar_url":"https://github.com/scottrigby.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Hello emoji](https://raw.githubusercontent.com/googlei18n/noto-emoji/master/png/128/emoji_u1f44b.png) ![World emoji](https://raw.githubusercontent.com/googlei18n/noto-emoji/master/png/128/emoji_u1f30d.png) ![Cloud emoji](https://raw.githubusercontent.com/googlei18n/noto-emoji/master/png/128/emoji_u2601.png) ![Build emoji](https://raw.githubusercontent.com/googlei18n/noto-emoji/master/png/128/emoji_u1f3d7.png)\n\n# Trigger GCP Cloudbuild\n\nA \"hello world\" for triggering Google Cloudbuild in Golang.\n\n## IAM setup\n\n1. Create a GCP service account:\n\n    ```console\n    $ gcloud iam service-accounts create trigger-gcb\n    ```\n\n1. Add the \"Cloud Container Builder Editor\" and \"Storage Object Admin\" roles to the service account.\n\n    ```console\n    $ export SA_EMAIL=$(gcloud iam service-accounts list --filter=\"name:trigger-gcb\" --format='value(email)')\n    $ export PROJECT=$(gcloud info --format='value(config.project)')\n    $ gcloud projects add-iam-policy-binding $PROJECT --member serviceAccount:$SA_EMAIL --role roles/storage.admin\n    $ gcloud projects add-iam-policy-binding $PROJECT --member serviceAccount:$SA_EMAIL --role roles/cloudbuild.builds.editor\n    ```\n\n1. Create a JSON key for the service-account.\n\n    ```console\n    $ gcloud iam service-accounts keys create trigger-gcb.json --iam-account $SA_EMAIL\n    ```\n\n## GKE test steps\n\n- Create generic secret for `$GOOGLE_APPLICATION_CREDENTIALS` ENV var:\n\n    ```console\n    $ kubectl create secret generic google-application-credentials --from-file=key.json=trigger-gcb.json\n    ```\n- Deploy the main test app:\n\n    ```console\n    $ export PROJECT=$(gcloud info --format='value(config.project)')\n    $ helm install trigger-gcp-cloudbuild/ --set projectID=$PROJECT --name gcb\n    ```\n- Monitor the output with `kubectl logs` (or - shameless plug - try [klog](https://github.com/farmotive/klog) for fast, prompted k8s logs)\n    - The `gcb-built` Job pod logs should output:\n      \u003e Built by GCP Cloudbuild\n- Cleanup:\n\n    ```console\n    $ helm delete --purge gcb\n    $ kubectl delete secret google-application-credentials\n    ```\n\n## IAM, Storage and Images cleanup\n\n- Delete the service account:\n\n    ```console\n    $ gcloud iam service-accounts delete $SA_EMAIL\n    ```\n- Remove the storage source file, then bucket:\n\n    ```console\n    $ gsutil rm gs://${PROJECT}_trigger-gcp-cloudbuild/source.tgz\n    $ gsutil rb gs://${PROJECT}_trigger-gcp-cloudbuild\n    ```\n\n- Remove the built images:\n\n    ```console\n    $ gcloud container images list-tags gcr.io/${PROJECT}/built-by-gcp-cloudbuild --format='get(digest)' | while read -r d; do command gcloud container images delete gcr.io/${PROJECT}/built-by-gcp-cloudbuild@\"$d\" --force-delete-tags --quiet; done\n    ```\n\n## Local test steps\n\n- Remove any existing built images:\n\n    ```console\n    $ gcloud container images delete gcr.io/${PROJECT}/built-by-gcp-cloudbuild --quiet\n    $ docker rmi gcr.io/${PROJECT}/built-by-gcp-cloudbuild\n    ```\n\n- Trigger cloudbuild locally with Docker:\n\n    ```console\n    $ docker run --rm -v trigger-gcb.json:/key.json --env PROJECT_ID=${PROJECT} --env GOOGLE_APPLICATION_CREDENTIALS=/key.json docker.io/r6by/trigger-gcp-cloudbuild\n    ```\n- Run the built test image:\n\n    ```console\n    $ docker run --rm gcr.io/${PROJECT}/built-by-gcp-cloudbuild\n    ```\n    Should output:\n    \u003e Built by GCP Cloudbuild\n\n## Local development steps\n\n- Build vendor directory and packages:\n\n    ```console\n    $ dep ensure -v\n    ```\n- In your local session, set the `$GOOGLE_APPLICATION_CREDENTIALS` variable that `golang.org/x/oauth2/google` `FindDefaultCredentials()` looks for, and the `$PROJECT_ID` variable with the name of your GCP project ID:\n\n    ```console\n    $ export GOOGLE_APPLICATION_CREDENTIALS=$(pwd)/trigger-gcb.json\n    $ export PROJECT_ID=${PROJECT}\n    ```\n- Run the main package:\n\n    ```console\n    $ go run main.go\n    ```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscottrigby%2Ftrigger-gcp-cloudbuild","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscottrigby%2Ftrigger-gcp-cloudbuild","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscottrigby%2Ftrigger-gcp-cloudbuild/lists"}