使用 GitHub 操作部署 Google Cloud:功能无法上传 zip 文件:无法加载默认凭据错误

问题描述 投票:0回答:1

我想使用 GitHub Actions 部署 Google Cloud Function。 已经使用 gitlab CI/CD 成功完成了此操作,现在想在 GitHub Actions 上做同样的事情。

我更改了参数名称,因此它们不应该成为问题:

  • 源到source_dir
  • my_env_vars 到环境变量等

我的代码:

name: CI Workflow

on:
  push:
    branches:
      - main

jobs:

  deploy-gloud-functions_new:
    runs-on: ubuntu-latest
    steps:
    
      - uses: actions/checkout@v3
  
      - name: Setup GCP Service Account
        uses: google-github-actions/setup-gcloud@main
        with:
          project_id: "cicdtest-421422"
          service_account_key: ${{ secrets.GCP_ACCOUNT_KEY }}       
        
      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: 3.11

      - name: Install dependencies
        run: pip install -r requirements.txt
    
      - name: deploy cloud function
        id: deploy
        uses: google-github-actions/deploy-cloud-functions@main
        with:
          name: generate_weather_summary
          runtime: python310
          project_id: "cicdtest-421422"
          entry_point: generate_weather_summary
          region: europe-west1
          source_dir: .
          event_trigger_type: topic weather-topic
          memory: 512MB
          environment_variables: "API_KEY=${{ secrets.API_KEY }},SLACK_TOKEN=${{ secrets.SLACK_TOKEN }}"

错误:

Run google-github-actions/deploy-cloud-functions@main
  with:
    name: generate_weather_summary
    runtime: python310
    project_id: cicdtest-421422
    entry_point: generate_weather_summary
    region: europe-west1
    source_dir: .
    event_trigger_type: topic weather-topic
    memory: 512MB
    environment_variables: API_KEY=***,SLACK_TOKEN=***
    universe: googleapis.com
    environment: GEN_2
    all_traffic_on_latest_revision: true
    ingress_settings: ALLOW_ALL
    service_timeout: 60s
    vpc_connector_egress_settings: PRIVATE_RANGES_ONLY
    event_trigger_retry: true
  env:
    CLOUDSDK_METRICS_ENVIRONMENT: github-actions-setup-gcloud
    CLOUDSDK_METRICS_ENVIRONMENT_VERSION: 2.1.0
    pythonLocation: /opt/hostedtoolcache/Python/3.11.9/x64
    PKG_CONFIG_PATH: /opt/hostedtoolcache/Python/3.11.9/x64/lib/pkgconfig
    Python_ROOT_DIR: /opt/hostedtoolcache/Python/3.11.9/x64
    Python2_ROOT_DIR: /opt/hostedtoolcache/Python/3.11.9/x64
    Python3_ROOT_DIR: /opt/hostedtoolcache/Python/3.11.9/x64
    LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.11.9/x64/lib
Created zip file from '.' at '/tmp/cfsrc-0ae0bbd4b761ae3f1003cd51.zip'
Error: google-github-actions/deploy-cloud-functions failed with: failed to upload zip file: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information.
python google-cloud-platform google-cloud-functions github-actions
1个回答
0
投票

使用前需要向Google云进行身份验证

google-github-actions/deploy-cloud-functions@main

例如:

- uses: 'google-github-actions/auth@v2'
  with:
   credentials_json: '${{ secrets.GOOGLE_CREDENTIALS }}' # Replace with the name of your GitHub Actions secret
© www.soinside.com 2019 - 2024. All rights reserved.