0

I have an gcloud app configured to use the Cloud SQL instance in app.yaml:

beta_settings:
  cloud_sql_instances: <instance-name>

After I deploy the app, /cloudsql/<instance-name> is available and it is possible to connect to the database through the socket file.

In order to migrate the database schema with each deployment I need a deployment command in Dockerfile:

RUN yarn run sequelize db:migrate

However the /cloudsql is not available when Dockerfile is executed.

RUN ls /cloudsql leads to ls: /cloudsql: No such file or directory.

What is a way to make /cloudsql available in this context? Is there other best practice to migrate the database in gcloud deployment?

Bogdan Gusiev
  • 8,027
  • 16
  • 61
  • 81
  • Make use of entrypoint in dockerfile that will execute some init script that has db migration commands. – mchawre Jul 04 '19 at 16:53
  • something similar to this https://stackoverflow.com/a/56875494/6790948 – mchawre Jul 04 '19 at 16:54
  • It is not a good idea to do this in Dockerfile startup scripts. Each time your app "cold-starts" the startup scripts run. Initializing databases should be performed independently of your containers and in a controlled consisted method. – John Hanley Jul 04 '19 at 17:18

1 Answers1

0

Performing database migrations with Django on Google App Engine and Cloud SQL. It has a free tier that is sufficient for most small businesses and hobby websites, and is very easy to deploy and maintain. Some of those websites are written in Django, a recommended Python web framework.

manage.py migrate command against your App Engine Standard instance, with a Cloud SQL database

There is a solution/workaround: you can connect to Cloud SQL from your local machine and execute the manage.py migrate on your local machine but have the changes be made to your cloud instance.

To do this, you need to add your Cloud SQL database to your settings file. Your production instance is probably using sockets, but from your local machine you need to use the IP adress:

https://medium.com/@mrdatainsight/performing-database-migrations-with-django-on-google-app-engine-and-cloud-sql-c7fd298581b4