Code Monkey home page Code Monkey logo

preview-cloudrun's Introduction

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.

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

name: cloudrun

on:
  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_NAME

jobs:
  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

preview-cloudrun's People

Contributors

knanao avatar dependabot[bot] avatar

Stargazers

 avatar Arvind avatar Naoto Ono avatar Akinori Yamada avatar  avatar nghialv avatar yutsuki miyashita avatar

Watchers

 avatar

Forkers

ohkai

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.