{"id":13638044,"url":"https://github.com/ahmetb/cloud-run-travisci","last_synced_at":"2025-06-27T18:08:26.251Z","repository":{"id":140599175,"uuid":"182618472","full_name":"ahmetb/cloud-run-travisci","owner":"ahmetb","description":"Example config for deploying from Travis CI to Google Cloud Run","archived":false,"fork":false,"pushed_at":"2019-06-24T20:10:48.000Z","size":496,"stargazers_count":54,"open_issues_count":0,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-23T15:56:45.592Z","etag":null,"topics":["cloud-run","google-cloud-run","travis-ci"],"latest_commit_sha":null,"homepage":"https://cloud.google.com/run","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ahmetb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-04-22T03:43:18.000Z","updated_at":"2024-03-04T22:08:50.000Z","dependencies_parsed_at":"2024-01-14T09:17:26.463Z","dependency_job_id":"a5e9ce46-020e-4935-9a64-0146c3ea81f4","html_url":"https://github.com/ahmetb/cloud-run-travisci","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ahmetb/cloud-run-travisci","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmetb%2Fcloud-run-travisci","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmetb%2Fcloud-run-travisci/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmetb%2Fcloud-run-travisci/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmetb%2Fcloud-run-travisci/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ahmetb","download_url":"https://codeload.github.com/ahmetb/cloud-run-travisci/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmetb%2Fcloud-run-travisci/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262307653,"owners_count":23291095,"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","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":["cloud-run","google-cloud-run","travis-ci"],"created_at":"2024-08-02T01:00:39.056Z","updated_at":"2025-06-27T18:08:26.212Z","avatar_url":"https://github.com/ahmetb.png","language":"Python","funding_links":[],"categories":["CI/CD"],"sub_categories":["Container guides"],"readme":"# Google Cloud Run + Travis CI\n\nThis repository shows how to use [Travis CI][tr] to build a container image and\ndeploy it to [Google Cloud Run][run] when you push a new commit.\n\n[tr]: https://www.travis-ci.com/\n[run]: https://cloud.google.com/run\n\n![](./logo.png)\n\n### Table of Contents\n\n\u003c!--\n  ⚠️ DO NOT UPDATE THE TABLE OF CONTENTS MANUALLY ️️⚠️\n  run `npx markdown-toc -i README.md`\n--\u003e\n\n\u003c!-- toc --\u003e\n\n- [Step 0: Fork this repository](#step-0-fork-this-repository)\n- [Step 1: Sign up to Travis CI](#step-1-sign-up-to-travis-ci)\n- [Step 1: Install required tools](#step-1-install-required-tools)\n- [Step 2: Create a service account for deploying](#step-2-create-a-service-account-for-deploying)\n- [Step 3: Assign permissions to the service account](#step-3-assign-permissions-to-the-service-account)\n- [Step 4: Encrypt the service account key](#step-4-encrypt-the-service-account-key)\n- [Step 5: Configure your project ID](#step-5-configure-your-project-id)\n- [Step 6: Commit the changes to your fork](#step-6-commit-the-changes-to-your-fork)\n- [Step 7: View build result](#step-7-view-build-result)\n- [Step 8: Clean up](#step-8-clean-up)\n\n\u003c!-- tocstop --\u003e\n\n## Step 0: Fork this repository\n\n1. Scroll up and click **\"Fork\"** so you can try pushing commits and testing\nbuilds.\n0. **Clone** the repository on your machine.\n0. Go to the `cloud-run-travisci` directory you cloned.\n\n## Step 1: Sign up to Travis CI\n\nSign up at [www.travis-ci.com][tr] and enable **Travis CI** app on your forked\n`cloud-run-travisci` repository at\nhttps://www.travis-ci.com/account/repositories.\n\n\u003e Note: If you have an travis-ci\u003cb\u003e.org\u003c/b\u003e account instead of .com, replace\n\u003e `--pro` arguments in this tutorial with `--org`.\n\n## Step 1: Install required tools\n\n- Google Cloud SDK (`gcloud`): https://cloud.google.com/sdk\n\n- `travis` command-line tool:\n\n    ```sh\n    sudo gem install travis\n    ```\n\n    ```sh\n    travis login --pro # (use --org if you're on travis-ci.ORG and not .COM)\n    ```\n\n## Step 2: Create a service account for deploying\n\nTo authenticate to GCP APIs from Travis CI build environment you will need a\n[service\naccount](https://cloud.google.com/iam/docs/understanding-service-accounts).\n\n```sh\nPROJECT_ID=\"$(gcloud config get-value project -q)\" # fetch current GCP project ID\n```\n\n```sh\nSVCACCT_NAME=travisci-deployer # choose name for service account\n```\n\nCreate a service account:\n\n```sh\ngcloud iam service-accounts create \"${SVCACCT_NAME?}\"\n```\n\nFind the email address of this account:\n\n```sh\nSVCACCT_EMAIL=\"$(gcloud iam service-accounts list \\\n  --filter=\"name:${SVCACCT_NAME?}@\"  \\\n  --format=value\\(email\\))\"\n```\n\nCreate a JSON key to authenticate as this service account, and save it as\n`google-key.json`:\n\n```sh\ngcloud iam service-accounts keys create \"google-key.json\" \\\n   --iam-account=\"${SVCACCT_EMAIL?}\"\n```\n\n## Step 3: Assign permissions to the service account\n\nYou need to give these IAM roles to the service account created:\n\n1. **Storage Admin:** Used for pushing docker images to Google Container\n   Registry (GCR).\n2. **Cloud Run Admin:** Used for deploying services to Cloud Run.\n3. **IAM Service Account user:** Required by Cloud Run to be able to \"act as\"\n   the runtime identity of the Cloud Run application (in this case, our deployer\n   service account needs to able to \"act as\" the GCE default service account).\n\n```sh\ngcloud projects add-iam-policy-binding \"${PROJECT_ID?}\" \\\n   --member=\"serviceAccount:${SVCACCT_EMAIL?}\" \\\n   --role=\"roles/storage.admin\"\n```\n\n```sh\ngcloud projects add-iam-policy-binding \"${PROJECT_ID?}\" \\\n   --member=\"serviceAccount:${SVCACCT_EMAIL?}\" \\\n   --role=\"roles/run.admin\"\n```\n\n```sh\ngcloud projects add-iam-policy-binding \"${PROJECT_ID?}\" \\\n   --member=\"serviceAccount:${SVCACCT_EMAIL?}\" \\\n   --role=\"roles/iam.serviceAccountUser\"\n```\n\n## Step 4: Encrypt the service account key\n\nRun the following command\n\n```sh\ntravis encrypt-file --pro google-key.json\n```\n\nThis command will print an `openssl [...]` command, **don’t lose it!**\n\nEdit the `.travis.yml` file, and add this commmand to the `before_install` step:\n\n```diff\n before_install:\n-- echo REMOVE_ME # replace with the openssl command from \"travis encrypt-file\"\n+- openssl aes-256-cbc -K $encrypted_fbfaf42b268c_key -iv $encrypted_fbfaf42b268c_iv -in google-key.json.enc -out google-key.json -d\n - curl https://sdk.cloud.google.com | bash \u003e /dev/null\n ...\n```\n\n## Step 5: Configure your project ID\n\nEdit the `.travis.yml` and configure the environment variables under the `env:`\nkey (such as `GCP_PROJECT_ID`, `IMAGE`, and `CLOUD_RUN_SERVICE`).\n\n## Step 6: Commit the changes to your fork\n\n:warning: Do not add `google-key.json` file to your repository as it can be\nreached by others.\n\nMake a commit, and push the changes to your fork:\n\n```sh\ngit add google-key.json.enc .travis.yml\n```\n\n```sh\ngit commit -m \"Enable Travis CI\"\n```\n\n```sh\ngit push -u origin master\n```\n\n## Step 7: View build result\n\nGo to [www.travis-ci.com][tr] and view your build results.\n\nThere might be errors that require you to fix.\n\nIf the build succeeds, the output of `gcloud run beta deploy` command will show\nyou the URL your app is deployed on! Visit the URL to see if the application\nworks!\n\n```\n[...]\nDeploying container to Cloud Run service [example-app] in project [...] region [us-central1]\nDeploying new service...\nSetting IAM Policy.....done\nCreating Revision......done\nRouting traffic........done\nDone.\nService [example-app] revision [example-app-00001] has been deployed\nand is serving traffic at https://example-app-pwfuv4g72q-uc.a.run.app\n```\n\n\n## Step 8: Clean up\n\nDelete the service account you created:\n\n```sh\ngcloud iam service-accounts delete \"${SVCACCT_EMAIL?}\"\n```\n\nDelete the Cloud Run application you deployed:\n\n```sh\ngcloud beta run services delete \"YOUR-APP-NAME\"\n```\n\n----\n\n👍**Did this tutorial work for you?** Click \"✭Star\" on the top right of this\npage and let me know!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahmetb%2Fcloud-run-travisci","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fahmetb%2Fcloud-run-travisci","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahmetb%2Fcloud-run-travisci/lists"}