google: update workflow versions and instructions (#2478)
* google: update workflow versions and instructions * Pin hashes
This commit is contained in:
@@ -1,113 +1,95 @@
|
||||
# This workflow build and push a Docker container to Google Artifact Registry and deploy it on Cloud Run when a commit is pushed to the $default-branch branch
|
||||
#
|
||||
# Overview:
|
||||
#
|
||||
# 1. Authenticate to Google Cloud
|
||||
# 2. Authenticate Docker to Artifact Registry
|
||||
# 3. Build a docker container
|
||||
# 4. Publish it to Google Artifact Registry
|
||||
# 5. Deploy it to Cloud Run
|
||||
# This workflow build and push a Docker container to Google Artifact Registry
|
||||
# and deploy it on Cloud Run when a commit is pushed to the $default-branch
|
||||
# branch.
|
||||
#
|
||||
# To configure this workflow:
|
||||
#
|
||||
# 1. Ensure the required Google Cloud APIs are enabled:
|
||||
# 1. Enable the following Google Cloud APIs:
|
||||
#
|
||||
# Cloud Run run.googleapis.com
|
||||
# Artifact Registry artifactregistry.googleapis.com
|
||||
# - Artifact Registry (artifactregistry.googleapis.com)
|
||||
# - Cloud Run (run.googleapis.com)
|
||||
# - IAM Credentials API (iamcredentials.googleapis.com)
|
||||
#
|
||||
# 2. Create and configure Workload Identity Federation for GitHub (https://github.com/google-github-actions/auth#setting-up-workload-identity-federation)
|
||||
# You can learn more about enabling APIs at
|
||||
# https://support.google.com/googleapi/answer/6158841.
|
||||
#
|
||||
# 3. Ensure the required IAM permissions are granted
|
||||
# 2. Create and configure a Workload Identity Provider for GitHub:
|
||||
# https://github.com/google-github-actions/auth#preferred-direct-workload-identity-federation.
|
||||
#
|
||||
# Cloud Run
|
||||
# roles/run.admin
|
||||
# roles/iam.serviceAccountUser (to act as the Cloud Run runtime service account)
|
||||
# Depending on how you authenticate, you will need to grant an IAM principal
|
||||
# permissions on Google Cloud:
|
||||
#
|
||||
# Artifact Registry
|
||||
# roles/artifactregistry.admin (project or repository level)
|
||||
# - Artifact Registry Administrator (roles/artifactregistry.admin)
|
||||
# - Cloud Run Developer (roles/run.developer)
|
||||
#
|
||||
# NOTE: You should always follow the principle of least privilege when assigning IAM roles
|
||||
# You can learn more about setting IAM permissions at
|
||||
# https://cloud.google.com/iam/docs/manage-access-other-resources
|
||||
#
|
||||
# 4. Create GitHub secrets for WIF_PROVIDER and WIF_SERVICE_ACCOUNT
|
||||
#
|
||||
# 5. Change the values for the GAR_LOCATION, SERVICE and REGION environment variables (below).
|
||||
#
|
||||
# NOTE: To use Google Container Registry instead, replace ${{ env.GAR_LOCATION }}-docker.pkg.dev with gcr.io
|
||||
#
|
||||
# For more support on how to run this workflow, please visit https://github.com/marketplace/actions/deploy-to-cloud-run
|
||||
#
|
||||
# Further reading:
|
||||
# Cloud Run IAM permissions - https://cloud.google.com/run/docs/deploying
|
||||
# Artifact Registry IAM permissions - https://cloud.google.com/artifact-registry/docs/access-control#roles
|
||||
# Container Registry vs Artifact Registry - https://cloud.google.com/blog/products/application-development/understanding-artifact-registry-vs-container-registry
|
||||
# Principle of least privilege - https://cloud.google.com/blog/products/identity-security/dont-get-pwned-practicing-the-principle-of-least-privilege
|
||||
# 3. Change the values in the "env" block to match your values.
|
||||
|
||||
name: Build and Deploy to Cloud Run
|
||||
name: 'Build and Deploy to Cloud Run'
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ $default-branch ]
|
||||
branches:
|
||||
- '$default-branch'
|
||||
|
||||
env:
|
||||
PROJECT_ID: YOUR_PROJECT_ID # TODO: update Google Cloud project id
|
||||
GAR_LOCATION: YOUR_GAR_LOCATION # TODO: update Artifact Registry location
|
||||
SERVICE: YOUR_SERVICE_NAME # TODO: update Cloud Run service name
|
||||
REGION: YOUR_SERVICE_REGION # TODO: update Cloud Run service region
|
||||
PROJECT_ID: 'my-project' # TODO: update to your Google Cloud project ID
|
||||
REGION: 'us-central1' # TODO: update to your region
|
||||
SERVICE: 'my-service' # TODO: update to your service name
|
||||
WORKLOAD_IDENTITY_PROVIDER: 'projects/123456789/locations/global/workloadIdentityPools/my-pool/providers/my-provider' # TODO: update to your workload identity provider
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
# Add 'id-token' with the intended permissions for workload identity federation
|
||||
runs-on: 'ubuntu-latest'
|
||||
|
||||
permissions:
|
||||
contents: 'read'
|
||||
id-token: 'write'
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: 'Checkout'
|
||||
uses: 'actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332' # actions/checkout@v4
|
||||
|
||||
- name: Google Auth
|
||||
id: auth
|
||||
uses: 'google-github-actions/auth@v0'
|
||||
# Configure Workload Identity Federation and generate an access token.
|
||||
#
|
||||
# See https://github.com/google-github-actions/auth for more options,
|
||||
# including authenticating via a JSON credentials file.
|
||||
- id: 'auth'
|
||||
name: 'Authenticate to Google Cloud'
|
||||
uses: 'google-github-actions/auth@f112390a2df9932162083945e46d439060d66ec2' # google-github-actions/auth@v2
|
||||
with:
|
||||
token_format: 'access_token'
|
||||
workload_identity_provider: '${{ secrets.WIF_PROVIDER }}' # e.g. - projects/123456789/locations/global/workloadIdentityPools/my-pool/providers/my-provider
|
||||
service_account: '${{ secrets.WIF_SERVICE_ACCOUNT }}' # e.g. - [email protected]
|
||||
workload_identity_provider: '${{ env.WORKLOAD_IDENTITY_PROVIDER }}'
|
||||
|
||||
# NOTE: Alternative option - authentication via credentials json
|
||||
# - name: Google Auth
|
||||
# id: auth
|
||||
# uses: 'google-github-actions/auth@v0'
|
||||
# with:
|
||||
# credentials_json: '${{ secrets.GCP_CREDENTIALS }}''
|
||||
|
||||
# BEGIN - Docker auth and build (NOTE: If you already have a container image, these Docker steps can be omitted)
|
||||
|
||||
# Authenticate Docker to Google Cloud Artifact Registry
|
||||
- name: Docker Auth
|
||||
id: docker-auth
|
||||
uses: 'docker/login-action@v1'
|
||||
# BEGIN - Docker auth and build
|
||||
#
|
||||
# If you already have a container image, you can omit these steps.
|
||||
- name: 'Docker Auth'
|
||||
uses: 'docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567' # docker/login-action@v3
|
||||
with:
|
||||
username: 'oauth2accesstoken'
|
||||
password: '${{ steps.auth.outputs.access_token }}'
|
||||
registry: '${{ env.GAR_LOCATION }}-docker.pkg.dev'
|
||||
password: '${{ steps.auth.outputs.auth_token }}'
|
||||
registry: '${{ env.REGION }}-docker.pkg.dev'
|
||||
|
||||
- name: Build and Push Container
|
||||
- name: 'Build and Push Container'
|
||||
run: |-
|
||||
docker build -t "${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}:${{ github.sha }}" ./
|
||||
docker push "${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}:${{ github.sha }}"
|
||||
DOCKER_TAG="$${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}:${{ github.sha }}"
|
||||
docker build --tag "${DOCKER_TAG}" .
|
||||
docker push "${DOCKER_TAG}"
|
||||
- name: 'Deploy to Cloud Run'
|
||||
|
||||
# END - Docker auth and build
|
||||
# END - Docker auth and build
|
||||
|
||||
- name: Deploy to Cloud Run
|
||||
id: deploy
|
||||
uses: google-github-actions/deploy-cloudrun@v0
|
||||
uses: 'google-github-actions/deploy-cloudrun@33553064113a37d688aa6937bacbdc481580be17' # google-github-actions/deploy-cloudrun@v2
|
||||
with:
|
||||
service: ${{ env.SERVICE }}
|
||||
region: ${{ env.REGION }}
|
||||
# NOTE: If using a pre-built image, update the image name here
|
||||
image: ${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}:${{ github.sha }}
|
||||
service: '${{ env.SERVICE }}'
|
||||
region: '${{ env.REGION }}'
|
||||
# NOTE: If using a pre-built image, update the image name below:
|
||||
|
||||
# If required, use the Cloud Run url output in later steps
|
||||
- name: Show Output
|
||||
run: echo ${{ steps.deploy.outputs.url }}
|
||||
image: '${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}:${{ github.sha }}'
|
||||
# If required, use the Cloud Run URL output in later steps
|
||||
- name: 'Show output'
|
||||
run: |2-
|
||||
|
||||
echo ${{ steps.deploy.outputs.url }}
|
||||
|
||||
Reference in New Issue
Block a user