The first thing to do would be to go to the actions and look at the build log and specifically at the failed step (which most likely is going to be function deploying). Look at the error, good chance it is going to tell you what exactly went wrong.
If I had to make an educated guess, I'd say your service account doesn't have enough permissions (mine was setup with two - Cloud Functions Developer role and Service Account User) or the way you deploy the function isn't correct. I see that you are not exporting default credentials when you setup gcloud sdk, is there a reason for that?
Picture worth a thousand words - I've created a simple repo, where I have the most basic (default) python function that I deploy to GCF. Check it out, this should be enough to get you started.
UPDATE:
In case I decide to delete the repo one day, I am going to include the build yaml in here as well:
# This is a basic workflow to help you get started with Actions
name: CI
# Controls when the action 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:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- name: Set up gcloud Cloud SDK environment
# You may pin to the exact commit or the version.
# uses: google-github-actions/setup-gcloud@94337306dda8180d967a56932ceb4ddcf01edae7
uses: google-github-actions/[email protected]
with:
# Service account email address to use for authentication. This is required
# for legacy .p12 keys but can be omitted for .json keys. This is usually of
# the format <name>@<project-id>.iam.gserviceaccount.com.
service_account_email: ${{ secrets.SERVICE_ACCOUNT_EMAIL }} # optional
# Service account key to use for authentication. This should be the JSON
# formatted private key which can be exported from the Cloud Console. The
# value can be raw or base64-encoded.
service_account_key: ${{ secrets.SERVICE_ACCOUNT_KEY }} # optional
# ID of the Google Cloud project. If provided, this will configure gcloud to
# use this project ID by default for commands. Individual commands can still
# override the project using the --project flag which takes precedence.
project_id: ${{ secrets.PROJECT_ID }} # optional
# Export the provided credentials as Google Default Application Credentials.
# This will make the credentials available to later steps via the
# GOOGLE_APPLICATION_CREDENTIALS environment variable. Future steps that
# consume Default Application Credentials will automatically detect and use
# these credentials.
export_default_credentials: true # optional
# Runs a single command using the runners shell
- name: Deploy the function
run: gcloud functions deploy myfunc --trigger-http --runtime=python39
Answer from jabbson on Stack OverflowGithub actions to google cloud run takes about 7 mins. Is that normal?
Github Actions | google cloud authentication - Stack Overflow
google-github-actions/auth@v2 Cannot Parse Google Service Account Key From Secret Manager
Google Sheets credentials in GitHub Actions Environment
Videos
I've recently been working on a new set of composable GitHub actions to run the open source Infracost project in CI/CD pipelines. For AWS, I see users using https://github.com/aws-actions/configure-aws-credentials to setup their creds (Terraform then uses those).
How do Google cloud users setup their creds with GitHub Actions? Do people usually just use the env variables that the Terraform docs suggests? Does anyone use https://github.com/google-github-actions/auth with Terraform?
Hi everyone, am new to ci/cd and am trying to automate a deployment of an api (written in nodejs) and deploy it as a Google Cloud Run upon a commit made to GitHub "main" branch.
Currently am using the below script for the requirement and running on GitHub Actions. However it seems to be taking approximately 7 mins in total (3.5 mins to 'setup Google Cloud SDK' & 3.5 min to 'build and push container' ) for the workflow to complete running.
Am wondering if that is normal or is there anyway to reduce the time taken to run it?
jobs: deploy: runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Google Cloud SDK
uses: google-github-actions/setup-gcloud@v0.2.1
with:
project_id: ${{ secrets.GCP_PROJECT_ID }}
service_account_key: ${{ secrets.GCP_SA_KEY }}
export_default_credentials: true
- name: Authorize Docker push
run: gcloud auth configure-docker
- name: Build and Push Container
run: |-
gcloud builds submit --gcs-log-dir $BUILD_LOGS_BUCKET --tag gcr.io/$PROJECT_ID/$SERVICE_NAME:${{ github.sha }}
- name: Deploy to Cloud Run
run: |-
gcloud run deploy $SERVICE_NAME \
--region $REGION \
--image gcr.io/$PROJECT_ID/$SERVICE_NAME:${{ github.sha }} \
--platform managed \
--allow-unauthenticated