如何通过GitHub Action部署第二代Google Cloud Functions
切换到Google Cloud Functions第二代部署的操作步骤
一、更新GitHub Action部署配置
修改你的.github/workflows/google-cloud-function.yaml文件,完成以下核心调整:
- 升级部署Action版本:将旧版
google-github-actions/deploy-cloud-functions@v0替换为支持第二代函数的稳定版本(推荐使用@v2) - 指定第二代函数标识:在部署步骤的
with参数中添加generation: 2,明确部署第二代函数 - 同步升级关联Action(可选):将身份验证、代码检出的Action也升级到最新版,提升稳定性
修改后的完整配置示例:
# This is a basic workflow to help you get started with Actions name: CD # Controls when the workflow 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: deploy: runs-on: ubuntu-latest permissions: contents: "read" id-token: "write" steps: - name: checkout repo uses: "actions/checkout@v4" - id: "auth" name: "Authenticate to Google Cloud" uses: "google-github-actions/auth@v2" with: workload_identity_provider: "projects/12345/locations/global/workloadIdentityPools/gh-pool/providers/gh-provider" service_account: "github-actions-service-account@PROJECT.iam.gserviceaccount.com" - id: "deploy" uses: "google-github-actions/deploy-cloud-functions@v2" with: name: "myapp" runtime: "python310" region: "europe-west1" entry_point: "main" timeout: 540 service_account_email: PROJECT@appspot.gserviceaccount.com ingress_settings: ALLOW_ALL max_instances: 1 generation: 2 # 核心:指定部署第二代函数 # 可选:添加第二代专属参数,比如CPU/内存配置 # cpu: 1 # memory: 256Mi # Example of using the output - id: "test" run: 'curl "${{ steps.deploy.outputs.url }}"'
二、初始化设置无需额外修改
你现有初始化配置中的工作负载身份池关联、服务账号权限绑定步骤完全兼容第二代函数,无需调整。若后续出现权限报错,可确认服务账号是否已拥有roles/cloudfunctions.developer角色(原有配置通常已包含该权限)。
内容的提问来源于stack exchange,提问作者Europa
相关产品推荐
相关产品推荐

