I am using Github Action in order to deploy Google Functions. How can I use the second generation, instead of the first generation?
This is my code:
.github/workflows/google-cloud-function.yaml
# This is a basic workflow to help you get started with Actions
name: CD
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [main]
pull_request:
branches: [main]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: "read"
id-token: "write"
steps:
- name: checkout repo
uses: actions/checkout@v2
- id: "auth"
name: "Authenticate to Google Cloud"
uses: "google-github-actions/auth@v0"
with:
workload_identity_provider: "projects/12345/locations/global/workloadIdentityPools/gh-pool/providers/gh-provider"
service_account: "github-actions-service-account@PROJECT.iam.gserviceaccount.com"
- id: "deploy"
uses: "google-github-actions/deploy-cloud-functions@v0"
with:
name: "myapp"
runtime: "python310"
region: "europe-west1"
entry_point: "main"
timeout: 540
service_account_email: PROJECT@appspot.gserviceaccount.com
ingress_settings: ALLOW_ALL
max_instances: 1
# Example of using the output
- id: "test"
run: 'curl "${{ steps.deploy.outputs.url }}"'
This is how I set it up to be deployed everytime I push changes to Github:
Powershell:
$GITHUB_REPO="ORGANIZATION/{YOUR-REPO-NAME}"
$PROJECT_ID="PROJECT"
$SERVICE_ACCOUNT="github-actions-service-account"
$WORKLOAD_IDENTITY_POOL="gh-pool"
$WORKLOAD_IDENTITY_PROVIDER="gh-provider"
Project ID
gcloud config set project $PROJECT_ID
Get ID:
gcloud iam workload-identity-pools describe $WORKLOAD_IDENTITY_POOL --location="global" --format="value(name)"
--> projects/XXXX/locations/global/workloadIdentityPools/gh-pool
$WORKLOAD_IDENTITY_POOL_ID="projects/XXXX/locations/global/workloadIdentityPools/gh-pool"
Connect repository:
gcloud iam service-accounts add-iam-policy-binding $SERVICE_ACCOUNT@$PROJECT_ID.iam.gserviceaccount.com --role="roles/iam.workloadIdentityUser" --member="principalSet://iam.googleapis.com/${WORKLOAD_IDENTITY_POOL_ID}/attribute.repository/${GITHUB_REPO}"
I think currently it is not possible to deploy a 2nd Gen cloud function with a Github Action. There is already request raised for this at github which is mentioned like below.
GitHub Actions only to deploy cloud function 1st gen. We do not currently support Cloud Functions gen2. If you need support for gen2, you can use the setup-gcloud action and run a
gcloudcommand manually.
you may also add your concern in that github issue which is still open, you can follow that issue for updates and further progress can be tracked there.
As community member mentioned the workaround in below comment you can use this until the feature is available
There is a thread on pull request #357 where another user has included their workaround setup-gcloud job configuration.