问题描述
gcloud beta运行部署曾经可以正常工作,但是现在我遇到了一个错误:
gcloud beta run deploy used to work but now I'm getting an error:
$ gcloud beta run deploy $PROJECT --image $IMAGE_NAME --platform=managed --region us-central1 --project $PROJECT --add-cloudsql-instances $PROJECT-db
...
DONE
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ID CREATE_TIME DURATION SOURCE IMAGES STATUS
abcdefj-higj-lmnopquer-uvw-xyz 2019-06-29T13:59:07+00:00 1M4S gs://$PROJECT_cloudbuild/source/XYZ123.96-aae829d50a2e43a29dce44d1f93bafbc.tgz gcr.io/$PROJECT/$PROJECT (+1 more) SUCCESS
API [sql-component.googleapis.com] not enabled on project
[$PROJECT]. Would you like to enable and retry (this will take a
few minutes)? (y/N)? y
Enabling service [sql-component.googleapis.com] on project [$PROJECT]...
ERROR: (gcloud.beta.run.deploy) INVALID_ARGUMENT: Invalid operation name operations/noop.DONE_OPERATION, refers to an already DONE operation
我已经从控制台检查了API,同时启用了Cloud SQL Admin和Cloud SQL API.我还尝试禁用它们,然后再次运行deploy命令,但无济于事.
I've checked the APIs from the console, both Cloud SQL Admin and Cloud SQL APIs are enabled. I've also tried disabling them and run the deploy command again, but to no avail.
更多信息:
-
SQL Server实例是同一项目的一部分.将--add-cloudsql-instances参数更改为连接名称($ PROJECT:$ REGION:$ SQLNAME)无效
The SQL server instance is part of the same project. Changing the --add-cloudsql-instances parameter to the connection name ($PROJECT:$REGION:$SQLNAME) has no effect
手动启用服务器无效:gcloud服务启用sql-component.googleapis.com --project XXX
Manually enabling the server has no effect: gcloud services enable sql-component.googleapis.com --project XXX
删除--add-cloudsql-instances参数,服务器将成功部署.
Removing the --add-cloudsql-instances parameter and the server deploys successfully.
这有效:gcloud sql connect $ PROJECTDB --user = root --quiet#注意:($ PROJECTDB)与上面的--add-cloudsql-instances参数相同
This works: gcloud sql connect $PROJECTDB --user=root --quiet# NOTE: ($PROJECTDB) is the same parameter as --add-cloudsql-instances above
推荐答案
此问题有两个问题:
- 启用API服务.我建议在运行Cloud Run部署之前启用服务,因为这可能需要比Cloud Run允许的时间更长的时间.首先运行此命令:
gcloud服务启用sql-component.googleapis.com
- Cloud SQL连接名称不正确.指定正确的名称会有所帮助.
Cloud SQL连接名称的格式为:$ PROJECT:$ REGION:$ GCP_SQL_NAME.
The format of the Cloud SQL connection name is: $PROJECT:$REGION:$GCP_SQL_NAME.
示例: development-123456:us-central1:mysqldb
此命令将返回有关Cloud SQL实例的信息,包括连接名称:
This command will return information about the Cloud SQL instance including the connection name:
gcloud sql实例描述< instance_name>
注意.Cloud Run具有几个用于指定要附加的Cloud SQL实例的命令.
Note. Cloud Run has several commands for specifying the Cloud SQL instance to attach.
-add-cloudsql-instances
-此选项附加指定的连接名称.
--add-cloudsql-instances
- This option appends the specified connection name.
-set-cloudsql-instances
-此选项替换当前的Cloud SQL连接名称.
--set-cloudsql-instances
- This option replaces the current Cloud SQL connection name.
如果您不打算将新版本部署到Cloud Run,则不必使用-add-cloudsql-instances
选项,因为该值将持续存在.我更喜欢使用-set-cloudsql-instances
选项明确指定Cloud SQL实例.
If you are not deploying a new version to Cloud Run, it is not necessary to use the --add-cloudsql-instances
option as the value persists. I prefer to use the --set-cloudsql-instances
option to clearly specify the Cloud SQL instances.
Cloud Run支持多个Cloud SQL实例.您可以添加多个连接名称.
Cloud Run supports multiple Cloud SQL instances. You can have add more than one connection name.
这篇关于成功上传映像后,gcloud beta运行部署失败,无法启用API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!