Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gcloud beta run deploy fails after sucessfully uploading image, fails to enable API

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

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.

More info:

  1. 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

  2. Manually enabling the server has no effect: gcloud services enable sql-component.googleapis.com --project XXX

  3. Removing the --add-cloudsql-instances parameter and the server deploys successfully.

  4. This works: gcloud sql connect $PROJECTDB --user=root --quiet # NOTE: ($PROJECTDB) is the same parameter as --add-cloudsql-instances above

like image 498
Matt Wlazlo Avatar asked Jun 29 '19 14:06

Matt Wlazlo


2 Answers

There seems to be a bug in gcloud v253.0.0 when deploying deploy Cloud Run services with Cloud SQL instances (requires Gmail log-in).

Once I downgraded to gcloud v251.0.0, I got rid of the "API [sql-component.googleapis.com] not enabled" error message and was able to deploy Cloud Run services with Cloud SQL instances again.

$ gcloud components update --version 251.0.0

UPDATE, July 17, 2019: The issue is fixed in Cloud SDK 254.0.0. If you upgrade to the latest version now, deploying Cloud Run services with Cloud SQL instances should work:

$ gcloud components update
like image 139
Martin Omander Avatar answered Oct 01 '22 03:10

Martin Omander


For this problem there were two issues:

  1. Enabling API services. I recommend enabling services prior to running Cloud Run deploy as this can take longer than Cloud Run might allow. Run this command first: gcloud services enable sql-component.googleapis.com
  2. The Cloud SQL connection name was incorrect. Specifying the correct name helps.

The format of the Cloud SQL connection name is: $PROJECT:$REGION:$GCP_SQL_NAME.

Example: development-123456:us-central1:mysqldb

This command will return information about the Cloud SQL instance including the connection name:

gcloud sql instances describe <instance_name>

Note. Cloud Run has several commands for specifying the Cloud SQL instance to attach.

--add-cloudsql-instances - This option appends the specified connection name.

--set-cloudsql-instances - This option replaces the current Cloud SQL connection name.

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 supports multiple Cloud SQL instances. You can have add more than one connection name.

like image 31
John Hanley Avatar answered Oct 01 '22 02:10

John Hanley