/deploy-cloud-functions-example

Primary LanguagePythonApache License 2.0Apache-2.0

Cloud Functions - GitHub Actions

An example workflow that uses GitHub Actions to deploy a Hello World Python app to Cloud Funtions.

This code is intended to be an example. You will likely need to change or update values to match your setup.

Workflow description

For pushes to the main branch, this workflow will:

  1. Set up job

    • Current runner version: '2.275.1'
    • Operating System (Ubuntu 18.04.5)
    • Virtual Environment
    • Prepare workflow directory
    • Prepare all required actions
    • Getting action download info
    • Download action repository 'actions/checkout@v2'
    • Download action repository 'google-github-actions/deploy-cloud-functions@main'
  2. Checkout Github Repo

    • Run actions/checkout@v2
    • Getting Git version info
    • Initializing the repository
    • Setting up auth
    • Fetching the repository
    • Checking out the ref
  3. Run google-github-actions/deploy-cloud-functions

    • Setting project Id from $GCLOUD_PROJECT
    • Creating a function revision
    • Creating or Updating function deployment
  4. Run curl to the URL of the deployed Cloud Function service

Setup

  1. Create a new Google Cloud Project (or select an existing project) and enable the Cloud Functions APIs.

  2. Create a Google Cloud service account if one does not already exist.

  3. Add the the following Cloud IAM roles to your service account:

    • Cloud Functions Admin - allows for the creation of new functions
  4. Download a JSON service account key for the service account.

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

    • GCP_SA_KEY: the downloaded service account key

Run the workflow

  1. Add and commit your changes:

    $ git add .
    $ git commit -m "Set up GitHub workflow"
    
  2. Push to the main branch:

    $ git push -u origin main
    
  3. View the GitHub Actions Workflow by selecting the Actions tab at the top of your repository on GitHub. Then click on the Build and Deploy to Cloud Run element to see the details.