I'm deploying django app with GCP Cloud build
service. In cloudbuild.yaml
I define step to apply migrations with gcr.io/google-appengine/exec-wrapper
tool:
- id: "apply migrations"
name: "gcr.io/google-appengine/exec-wrapper"
args:
[
"-i",
"gcr.io/$PROJECT_ID/${_SERVICE_NAME}",
"-s",
"${PROJECT_ID}:${_REGION}:${_DB_INSTANCE_NAME}",
"-e",
"GOOGLE_CLOUD_SECRETS_NAME=${_GOOGLE_CLOUD_SECRETS_NAME}",
"-e",
"DJANGO_SETTINGS_MODULE=${_DJANGO_SETTINGS_MODULE}",
"--",
"python",
"manage.py",
"migrate",
]
Everything is working fine with one "default"
database.
Then:
DATABASES = {
"default": env.db("DATABASE_URL"),
"replica": env.db("REPLICA_DATABASE_URL"),
}
When I added new mysql replica
database with name gcp-replica-2015-07-08-1508
, Cloud build
service starting failing with error:
django.db.utils.OperationalError:
(2002, "Can't connect to local MySQL server through socket
'/cloudsql/myproject-228819:us-central1:gcp-replica-2015-07-08-'
I checked my db config by printing DATABASES
variable in Cloud build
and config have correct data, but if you look on error you will notice that error returns with cut string at the end ! without -1508
If I skip this step and deploy my app with same config to Cloud Run
everything is working fine.
Service account have following roles:
Replica DB Version MySQL 5.7