首页 > 解决方案 > 使用 Github 操作部署 Google 云功能:无法读取“https://github.com”的用户名

问题描述

我正在尝试通过 GitHub Actions 设置 CICD 管道;目标是在主分支发生更改后立即触发功能部署。

以下是我的 dedicated.yaml 代码:

name: Deploy Function
# https://sourcery.ai/blog/github-actions/
on:
  push:
    branches:
      - main
jobs:
  quality:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@master
      - uses: actions/setup-python@v2
        with:
          python-version: 3.9
      - name: install quality dependencies
        run: pip install -e ".[quality]"

      - name: check code quality
        run: make quality

  test:
    runs-on: ubuntu-latest
    needs: quality
    steps:
      - uses: actions/checkout@master
      - uses: actions/setup-python@v2
        with:
          python-version: 3.9
      - name: install testing dependencies
        run: pip install -e ".[testing]"
      - name: run unit-test
        run: make test

  build:
    runs-on: ubuntu-latest
    # It breaks the pipeline if any of them is not passed
    # Comment here and on top to exclude
    needs: [quality, test]
    env:
      PROJECTID: my_project_id

    steps:
      - uses: actions/checkout@master
      - uses: actions/setup-python@v2
        with:
          python-version: 3.9

      - name: Set up Cloud SDK
        uses: google-github-actions/setup-gcloud@master
        with:
          # base46encoded json file for service account
          service_account_key: ${{ secrets.PRODUCTION_FUNCTION_KEY }}
          export_default_credentials: true

      - name: install testing dependencies
        run: make install-prod

      - name: extract requirements
        run: python -m pip freeze > src/requirements.txt
    
      - name: deploy function
        working-directory: src
        run: |
          gcloud functions deploy my_function \
          --runtime=python39 \
          --trigger-http \
          --project ${{ env.PROJECTID }} \
          --set-env-vars CSF_DISCOUNT_BUCKET=csf-discount \
          --entry-point=predict \
          --region=europe-west3 \
          --max_instances=5 \
          --memory=1024MB

本质上,我的主 GitHub 存储库中有一个“src”存储库,其中包含我的函数的完整源代码。

但是,在运行时,以下错误会停止部署(“my_”替换真实姓名):

Cloning https://github.com/my_organization/my_function_repo (to revision 990f313e622a7d485896e8c99f63501b603a50dd) to ./src/my_function_repo
  Running command git clone -q https://github.com/my_organization/my_function_repo /workspace/src/my_function_repo
  fatal: could not read Username for 'https://github.com': No such device or address

WARNING: Discarding git+https://github.com/my_organization/(...) . Command errored out with exit status 128: git clone -q https://github.com/my_organization/my_function_repo /workspace/src/my_function_repo Check the logs for full command output.
Collecting cachetools==4.2.2
  Downloading cachetools-4.2.2-py3-none-any.whl (11 kB)
Collecting DateTime==4.3
  Downloading DateTime-4.3-py2.py3-none-any.whl (60 kB)
ERROR: Could not find a version that satisfies the requirement my_function_repo (unavailable) (from versions: none)
ERROR: No matching distribution found for my_function_repo (unavailable); Error ID: c84b3231 

我该如何解决这个问题并完成部署?

标签: yamlgithub-actions

解决方案


推荐阅读