Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/knanao/preview-cloudrun
A GitHub Action for deploying preview environments per PR to Google Cloud Run.
https://github.com/knanao/preview-cloudrun
Last synced: 15 days ago
JSON representation
A GitHub Action for deploying preview environments per PR to Google Cloud Run.
- Host: GitHub
- URL: https://github.com/knanao/preview-cloudrun
- Owner: knanao
- License: apache-2.0
- Created: 2023-03-28T09:05:56.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-03-03T07:14:08.000Z (8 months ago)
- Last Synced: 2024-10-17T23:12:57.401Z (20 days ago)
- Language: TypeScript
- Size: 1.52 MB
- Stars: 7
- Watchers: 1
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# preview-cloudrun
A GitHub Action for deploying preview revisions per a PR to Google Cloud Run. This action deploys a new revision with zero traffic and creates a comment which shows the revision URLs to the PR.![](/assets/preview-cloudrun.png)
# Prerequisites
- This action requires Google Cloud credentials that are authorized to access the secrets being requested.
- This action doesn't support building and pushing container images by itself, hence it's necessary to push the image which you want to review before using this action.
- If Cloud Run services do not exist yet, please finish a first deployment in some way.# Usage
```yaml
name: cloudrunon:
pull_request:
branches:
- main
types: [opened, synchronize, reopened, labeled, closed]env:
TRIGGER_LABEL: cloudrun-preview
REGISTRY: REGISTRY_NAME
REGION: SERVICE_REGION
DOCKERFILE_PATH: DOCKERFILE_PATH
SERVICE: SERVICE_NAMEjobs:
preview:
if: ${{ contains(github.event.pull_request.labels.*.name, env.TRIGGER_LABEL) }}
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
pull-requests: write
issues: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0- name: Google Auth
id: auth
uses: google-github-actions/auth@v1
with:
workload_identity_provider: ${{ secrets.WIF_PROVIDER }}
service_account: ${{ secrets.WIF_SERVICE_ACCOUNT }}# If you want to use GAR or Docker Hub instead of GCR, please update this.
# https://github.com/docker/login-action
- name: Login to GCR
uses: docker/login-action@49ed152c8eca782a232dede0303416e8f356c37b #v2.0.0
with:
registry: ${{ env.REGISTRY }}
username: oauth2accesstoken
password: ${{ steps.auth.outputs.access_token }}- name: Git Tags
id: tag
run: echo version=$(git describe --tags --always --dirty --abbrev=7) >> $GITHUB_OUTPUT- name: Build and Push Image
uses: docker/build-push-action@v4
with:
push: true
context: .
file: ${{ env.DOCKERFILE_PATH }}
tags: ${{ env.REGISTRY }}:${{ steps.tag.outputs.version }}- name: Preview Cloud Run Deployment
uses: knanao/preview-cloudrun@v1
with:
service: ${{ env.SERVICE }}
image: ${{ env.REGISTRY }}:${{ steps.tag.outputs.version }}
token: ${{ secrets.GITHUB_TOKEN }}
```# Inputs
| Name | Description | Required | Default Value |
|---------------------------------|--------------------------------------------------------------------------------|:--------:|:----------------------------------------------------:|
| project | ID of the Google Cloud project in which to deploy the service. | no | the value computed from the environment |
| region | Region in which the service is and to deploy the service. | no | us-central1 |
| service | Name of the Cloud Run service. | yes | |
| revision | Name of the Cloud Run revision. | no | ${SERVICE_NAME}-${TAG_VERSION}-${COMMIT_HASH} |
| image | Fully-qualified name of the container image to deploy. | yes | |
| tag | Traffic tag to assign to the newly-created revision. | no | pr-${PULL_REQUEST_NUMBER} |
| gcloud_version | Version of the gcloud CLI to use. | no | latest |
| token | Secret of GITHUB_TOKEN. This is used for creating a coments to PRs. | yes | |