0

I have a Github organization where I store repositories.

All repositories are programmed in Python. I want to use Github actions in order to push the code that I have in a repository to Google Cloud Functions.

I have a simple flask API with a single route that I want to deploy on Google Cloud Functions.

main.py

import os

from flask import Flask, send_from_directory
from flask_cors import CORS

from src.api.my_route import my_route

app = Flask(__name__)

cors = CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type'


# Routes
@app.route('/api/my_route', methods=['GET'])
def __my_route():
    return my_route()


# - Main start ----------------------------------------------------------------
if __name__ == "__main__":
    # Start app
    _port = 5001
    app.run(debug=True, host="0.0.0.0", port=_port)

my_route.py

def my_route():
    return {
               "message": "This is my route",
               "data": None,
               "error": "OK"
           }, 200

In order to do this I have done the following:

1. Create a Goolge Console Project here:

https://console.cloud.google.com/welcome

And notet the "Project ID" from that site.

2. Created workload identity pool:

gcloud iam workload-identity-pools create "engineering-pool" --project="engineering-infra" --location="global" --display-name="engineering pool"

3. Created workload identity pool provider:

gcloud iam workload-identity-pools providers create-oidc "github-provider" --project="engineering-infra" --location="global" --workload-identity-pool="engineering-pool" --display-name="Github provider" --attribute-mapping="google.subject=assertion.sub,attribute.actor=assertion.actor,attribute.aud=assertion.aud" --issuer-uri="https://token.actions.githubusercontent.com"

4. Updated IAM policy for serviceAccount:

gcloud iam service-accounts add-iam-policy-binding "[email protected]" --project="engineering-infra" --role="roles/iam.workloadIdentityUser" --member="principalSet://iam.googleapis.com/projects/XXXXXXXX/locations/global/workloadIdentityPools/engineering-pool/attribute.repository/my-org/my-repo"

Generated a yaml file inside my Github repository:

.github/workflows/google-cloudfunction-docker.yaml

jobs:
  job_id:
    runs-on: ubuntu-latest
    permissions:
      contents: 'read'
      id-token: 'write'

    steps:
    - uses: actions/checkout@v3

    - id: auth
      uses: google-github-actions/auth@v0
      with:
        workload_identity_provider: 'projects/XXX/locations/global/workloadIdentityPools/engineering-pool/providers/my-provider'
        service_account: '[email protected]'

    - id: 'deploy'
      uses: 'google-github-actions/deploy-cloud-functions@v0'
      with:
        name: 'my-flask-api'
        runtime: 'python3.10'

    # Example of using the output
    - id: 'test'
      run: 'curl "${{ steps.deploy.outputs.url }}"'

Github Actions gives the following error:

Error: .github#L1
No event triggers defined in `on`

1 Answer 1

1

From your shared yaml and the error message, looks like you are missing a trigger action e.g:

on: push
Sign up to request clarification or add additional context in comments.

2 Comments

Where should the on: push be?
The on: push should go outside and preferably before defining jobs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.