GitHub Action部署Google App Engine遇[13]内部错误求助
问题
三个月前正常运行的GitHub Action现在无法完成部署,报错:
ERROR: (gcloud.app.deploy) Error Response: [13] An internal error occurred. Error: Process completed with exit code 1.
错误发生在「Publish app to Google App Engine」步骤,App Engine中能看到创建了新版本但无法上线完成部署。该Action已稳定运行2-2.5年,排查过部署后变更、权限均无结果。
相关配置
GitHub Action的main.yml
name: CI on: push: branches: [ master ] pull_request: branches: [ master ] jobs: deploy_app_engine: runs-on: ubuntu-latest timeout-minutes: 80 steps: - uses: actions/checkout@v1 - name: Update Google Cloud SDK run: | sudo apt-get update && sudo apt-get install -y google-cloud-sdk - name: NodeJS Init uses: actions/setup-node@v1 with: node-version: '12' - name: Cache dependencies uses: actions/cache@v2 with: path: ~/.npm key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }} restore-keys: | ${{ runner.os }}-npm- - name: Prepare NPM ENV run: | npm install npm install -g react-scripts npx browserslist@latest --update-db - name: Build Static Website run: npm run build - name: Initialize Google Cloud SDK uses: zxyle/publish-gae-action@master with: service_account_email: ${{ secrets.GCP_SA_EMAIL }} service_account_key: ${{ secrets.GCP_SA_KEY }} project_id: ${{ secrets.PROJECT_ID }} - name: Publish app to Google App Engine run: | gcloud auth activate-service-account ${{ secrets.GCP_SA_EMAIL }} --key-file=client-secret.json gcloud config set project ${{ secrets.PROJECT_ID }} pwd gcloud -q app deploy app.yaml --promote
app.yaml
runtime: nodejs12 service: default handlers: # Serve all static files with url ending with a file extension - url: /(.*\..+)$ static_files: build/\1 upload: build/(.*\..+)$ # Catch all handler to index.html - url: /.* static_files: build/index.html upload: build/index.html
调试信息
启用debug选项后,得到包含以下警告的完整日志:
Node.js 12 is no longer supported by the Node.js Foundation as of April 2022. We recommend you to upgrade to the latest version of Node.js runtime as soon as possible.
关键错误片段:
DEBUG: Operation [apps/***/operations/14779876-6eda-4628-9ea5-5ff567374e02] complete. Result: { "done": true, "error": { "code": 13, "message": "An internal error occurred." }, "metadata": { "@type": "type.googleapis.com/google.appengine.v1.OperationMetadataV1", "endTime": "2023-07-15T06:52:23.996Z", "insertTime": "2023-07-15T06:37:19.647Z", "method": "google.appengine.v1.Versions.CreateVersion", "target": "apps/***/services/default/versions/20230715t063706", "user": "***", "warning": [ "Node.js 12 is no longer supported by the Node.js Foundation as of April 2022. We recommend you to upgrade to the latest version of Node.js runtime as soon as possible." ] }, "name": "apps/***/operations/14779876-6eda-4628-9ea5-5ff567374e02" } failed. DEBUG: (gcloud.app.deploy) Error Response: [13] An internal error occurred. ...(省略Traceback内容) ERROR: (gcloud.app.deploy) Error Response: [13] An internal error occurred. Error: Process completed with exit code 1.
排查方案
优先升级Node.js版本:调试日志明确提示Node.js 12已停止支持,GCP可能已逐步停止对该版本的部署支持。将配置中所有Node.js 12的引用替换为当前支持的版本(比如Node.js 20):
- 修改main.yml中
node-version: '12'为node-version: '20' - 修改app.yaml中
runtime: nodejs12为runtime: nodejs20 - 同步更新package.json中的
engines字段(如果有),并重新生成package-lock.json
- 修改main.yml中
简化部署步骤,避免重复初始化GCP SDK:当前Action中同时使用了第三方GAE部署Action和手动执行
gcloud auth,可能导致环境冲突。去掉Initialize Google Cloud SDK步骤,改用官方GCP认证Action:- name: Authenticate to GCP uses: google-github-actions/auth@v1 with: credentials_json: ${{ secrets.GCP_SA_KEY }} - name: Set up Cloud SDK uses: google-github-actions/setup-gcloud@v1 - name: Publish app to Google App Engine run: | gcloud config set project ${{ secrets.PROJECT_ID }} gcloud -q app deploy app.yaml --promote检查GCP服务账号权限:确认服务账号拥有
App Engine Deployer和Cloud Build Editor角色,排查是否有最近的权限变更导致部署权限不足。本地模拟部署验证:在本地环境使用相同的服务账号密钥执行
gcloud app deploy命令,排除GitHub Action环境的问题。如果本地也报错,直接在GCP控制台查看对应版本的部署详情日志。清理旧版本和缓存:删除App Engine中无用的旧版本,临时注释GitHub Action中的缓存步骤,避免缓存的旧依赖或配置导致冲突。
检查GCP区域和配额:确认项目的App Engine配额(比如实例数、存储空间)未耗尽,同时检查部署区域是否有临时故障。
内容的提问来源于stack exchange,提问作者אופיר קוברמן

