【问题标题】:Deploy Google cloud Function on Github actions在 Github 操作上部署 Google Cloud Function
【发布时间】:2021-07-29 22:41:49
【问题描述】:

我的代码在我的 repo 的一个文件夹中。目的是将代码(main.py)部署到谷歌云并同步我的代码。我在 Google Cloud Platform 上创建了一个函数和一个帐户服务。我还为 EMAIL 和 PRIVATE KEY(帐户服务)创建了机密,并为 ID PROJECT 创建了机密。但我有一个错误:

你有解决办法吗?

Error

【问题讨论】:

    标签: google-cloud-platform google-cloud-functions github-actions


    【解决方案1】:

    要做的第一件事是转到操作并查看构建日志,特别是失败的步骤(很可能是功能部署)。查看错误,它很有可能会告诉您到底出了什么问题。

    如果我不得不做出有根据的猜测,我会说您的服务帐户没有足够的权限(我的设置有两个 - 云功能开发人员角色和服务帐户用户)或者您部署功能的方式是'正确。我看到您在设置 gcloud sdk 时没有导出默认凭据,这是有原因的吗?

    图片价值一千字 - 我创建了一个简单的repo,其中我拥有部署到 GCF 的最基本(默认)python 函数。看看吧,这应该足以让您入门。

    更新:
    如果有一天我决定删除 repo,我也会在此处包含构建 yaml:

    # 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/setup-gcloud@v0.2.0
            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
    

    【讨论】:

    • 感谢您的帮助!。我已经在我的服务帐户上添加了角色 Cloud Functions 开发人员角色和服务帐户用户。但是我可以为 Google 使用无服务器方法吗?它工作与否?我是谷歌云的初学者。
    • imgur.com/17GS13K 我的 Github 操作日志。我不知道错误的 JSON 格式是什么秘密。 ://
    • 应该是整个json文件的内容
    • 谢谢,我解决了这个问题。但是,我可以使用 YML 无服务器解决方案吗?使用 --source 选项,我无法使用存储库中 main.py 文件中的代码。 imgur.com/ou6T2Om
    猜你喜欢
    • 1970-01-01
    • 2017-03-10
    • 2017-08-04
    • 2021-10-17
    • 2022-11-16
    • 2021-06-29
    • 2020-03-01
    • 1970-01-01
    • 2019-08-22
    相关资源
    最近更新 更多