setup-gcloud/deploy-cloudrun
Averi Kitsch a244a889d6
Cloud Run Action (#117)
* Cloud Run Action Drafted

* Cloud Run action

* refactor

* rename

* Add metadata and tests

* Update Readme and required fields

* Update e2e tests

* Update tests

* Add log messages

* fix typo in obj field

* Update YAML

* Update Env Var names

* Update workflow tests

* Update tests

* Update testing

* Update tests

* Update workflow

* Update workflow dir

* fix typo

* test output

* Update integration tests

* add workdir

* set up auth for service request

* Add check for empty array

* Wait for URL

* fix test

* Update for PR comments
2020-07-30 12:59:17 -07:00
..
dist Cloud Run Action (#117) 2020-07-30 12:59:17 -07:00
src Cloud Run Action (#117) 2020-07-30 12:59:17 -07:00
tests Cloud Run Action (#117) 2020-07-30 12:59:17 -07:00
.eslintrc.js Cloud Run Action (#117) 2020-07-30 12:59:17 -07:00
.gitignore Cloud Run Action (#117) 2020-07-30 12:59:17 -07:00
.prettierrc.js Cloud Run Action (#117) 2020-07-30 12:59:17 -07:00
action.yml Cloud Run Action (#117) 2020-07-30 12:59:17 -07:00
package-lock.json Cloud Run Action (#117) 2020-07-30 12:59:17 -07:00
package.json Cloud Run Action (#117) 2020-07-30 12:59:17 -07:00
README.md Cloud Run Action (#117) 2020-07-30 12:59:17 -07:00
tsconfig.json Cloud Run Action (#117) 2020-07-30 12:59:17 -07:00

deploy-cloudrun

This action deploys your container image to Cloud Run and makes the URL available to later build steps via outputs.

Prerequisites

This action requires:

  • Google Cloud credentials that are authorized to deploy a Cloud Run service. See the Authorization section below for more information.

  • Enable the Cloud Run API

Usage

steps:
- id: deploy
  uses: GoogleCloudPlatform/github-actions/deploy-appengine@master
  with:
    image: gcr.io/cloudrun/hello
    service: hello-cloud-run
    credentials: ${{ secrets.gcp_credentials }}

# Example of using the output
- id: test
  run: curl "${{ steps.deploy.outputs.url }}"

Inputs

  • image: Name of the container image to deploy (e.g. gcr.io/cloudrun/hello:latest). Required if not using a service YAML.

  • service: ID of the service or fully qualified identifier for the service. Required if not using a service YAML.

  • region: Region in which the resource can be found.

  • credentials: Service account key to use for authentication. This should be the JSON formatted private key which can be exported from the Cloud Console. The value can be raw or base64-encoded. Required if not using a the setup-gcloud action with exported credentials.

  • env_vars: List of key-value pairs to set as environment variables in the format: KEY1=VALUE1,KEY2=VALUE2. All existing environment variables will be removed first.

  • metadata: YAML serivce description for the Cloud Run service. See Metadata customizations for more information.

  • project_id: (Optional) ID of the Google Cloud project. If provided, this will override the project configured by gcloud.

Metadata customizations

You can store your service specification in a YAML file. This will allow for further service configuration, such as memory limits, CPU allocation, max instances, and more.

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: SERVICE
spec:
  template:
    spec:
      containers:
      - image: IMAGE
gcloud run services describe SERVICE --format yaml > service.yaml

Allow unauthenticated requests

A Cloud Run product recommendation is that CI/CD systems not set or change settings for allowing unauthenticated invocations. New deployments are automatically private services, while deploying a revision of a public (unauthenticated) service will preserve the IAM setting of public (unauthenticated). For more information, see Controlling access on an individual service.

Outputs

  • url: The URL of your Cloud Run service.

Authorization

There are a few ways to authenticate this action. A service account will be needed with the following roles:

  • Cloud Run Admin (roles/run.admin):
    • Can create, update, and delete services.
    • Can get and set IAM policies.

This service account needs to a member of the Compute Engine default service account, (PROJECT_NUMBER-compute@developer.gserviceaccount.com), with role Service Account User. To grant a user permissions for a service account, use one of the methods found in Configuring Ownership and access to a service account.

Used with setup-gcloud

You can provide credentials using the setup-gcloud action:

- uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
  with:
    version: '290.0.1'
    service_account_key: ${{ secrets.GCP_SA_KEY }}
    export_default_credentials: true
- id: Deploy
  uses: GoogleCloudPlatform/github-actions/deploy-cloudrun@master
  with:
    image: gcr.io/cloudrun/hello
    service: hello-cloud-run

Via Credentials

You can provide Google Cloud Service Account JSON directly to the action by specifying the credentials input. First, create a GitHub Secret that contains the JSON content, then import it into the action:

- id: Deploy
  uses: GoogleCloudPlatform/github-actions/deploy-cloudrun@master
  with:
    credentials: ${{ secrets.GCP_SA_KEY }}
    image: gcr.io/cloudrun/hello
    service: hello-cloud-run

Via Application Default Credentials

If you are hosting your own runners, and those runners are on Google Cloud, you can leverage the Application Default Credentials of the instance. This will authenticate requests as the service account attached to the instance. This only works using a custom runner hosted on GCP.

- id: Deploy
  uses: GoogleCloudPlatform/github-actions/deploy-cloudrun@master
  with:
    image: gcr.io/cloudrun/hello
    service: hello-cloud-run

The action will automatically detect and use the Application Default Credentials.