You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

将Flask应用Docker镜像上传至GCP Artifact Registry遇412错误求助

解决gcloud builds submit报错:'us' violates constraint 'constraints/gcp.resourceLocations'

问题分析

你指定了--region=europe-north1但仍触发us区域的约束错误,原因是Cloud Build默认会使用us区域的GCS存储桶暂存构建源文件,而你的项目通过组织策略(constraints/gcp.resourceLocations)禁止了us区域的资源创建。

直接解决方案

修改构建命令,显式指定同区域的GCS存储桶用于暂存源文件:

gcloud builds submit --region=europe-north1 --gcs-source-staging-dir gs://sindre-dev-439512_cloudbuild_europe-north1/source --tag europe-north1-docker.pkg.dev/sindre-dev-439512/docker-repo/finnreka-gke .

注:如果存储桶不存在,Cloud Build会自动创建它,确保该存储桶位于europe-north1区域。

额外检查步骤

  1. 验证项目资源位置约束
    查看项目的组织策略,确认europe-north1在允许的资源位置列表中:

    gcloud resource-manager org-policies list --project=sindre-dev-439512 | grep constraints/gcp.resourceLocations
    

    若该约束存在但未包含europe-north1,需要联系组织管理员更新策略添加该区域。

  2. 优化Dockerfile
    你的Dockerfile中重复安装了Flask和gunicorn(requirements.txt已包含),可删除冗余行缩小镜像体积:

    # 移除这一行,无需重复安装
    # RUN pip install Flask gunicorn
    
  3. Kubernetes配置验证
    你的deployment.yaml和service.yaml配置无误,镜像地址正确指向Artifact Registry中的仓库,部署前确保GKE集群也位于europe-north1区域。

内容的提问来源于stack exchange,提问作者Europa

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 18:05:14