setup-gcloud/example-workflows/cloud-run
2020-03-28 13:05:45 -04:00
..
.github/workflows Fix bad copy 2020-01-30 15:08:46 -08:00
.dockerignore Add example 2020-01-14 13:01:56 -08:00
Dockerfile Add example 2020-01-14 13:01:56 -08:00
index.js Add example 2020-01-14 13:01:56 -08:00
package-lock.json Add example 2020-01-14 13:01:56 -08:00
package.json Add example 2020-01-14 13:01:56 -08:00
README.md Add instructions to set up service account and repo secrets 2020-03-28 13:05:45 -04:00

Cloud Run - GitHub Actions

An example workflow that uses GitHub Actions to deploy a Hello World Node.js app to Cloud Run (Fully Managed).

Workflow

For pushes to the default branch, master, the workflow will:

  1. Verify the Google Cloud Platform credentials are correct.

  2. Build, tag, and push the image to Google Container Registry.

    • The image is built using Cloud Build and pushed to Google Container Registry.

    • The image is available through the following tags: latest and first 8 of the commit SHA.

  3. Deploy the image to Cloud Run.

Setup

  1. Create or reuse a Github repository for the example workflow:

    1. Create a repository.

    2. Move into your repository directory.

    3. Copy the example into the repository:

    cp -r <path_to>/github-actions/example-workflows/cloud-run/ ./
    
  2. Add your Project Id to the repository's secrets, named RUN_PROJECT.

  3. Update cloud-run.yml with the following values:

    • RUN_REGION: the region in which the resource will be deployed.

    • SERVICE_NAME: your preferred name of your service and image.

  4. Create a service account if there isn't one.

  5. Add the the following role to your service account:

    • Cloud Run Admin - roles/run.admin: allows for the creation of new services
    • Viewer - roles/viewer: allows for viewing the project (needed for Storage access)
    • Cloud Build Service Account - roles/cloudbuild.builds.builder: allows for running and manipulating Cloud Build and Storage resources
    • Cloud Build Editor - roles/cloudbuild.builds.editor: allows for deploying cloud builds
    • Service Account User - roles/iam.serviceAccountUser: actAs requirement
  6. Create key for the service account (type JSON).

  7. Add the following secrets to your repository's secrets:

    • SA_EMAIL: the email of the service account

    • GOOGLE_APPLICATION_CREDENTIALS: the content of the service account JSON file

  8. Enable the Cloud Run API and Cloud Build API..

Run the workflow

  1. Add and commit your changes:
git add .
git commit -m "Set up Github workflow"
  1. Push to the master branch:
git push origin master
  1. View the workflow by selecting the Actions tab at the top of your repository. Then click on the Build and Deploy to Cloud Run workflow to see the details.

Note: If this is your first Cloud Run deployment, your image will not allow unauthenticated requests. If this is a service revision, then your service will persist the current setting. Learn more about allowing public access.