0

I have an app that uses mysql database. The database used by the app is also in Google Cloud. I have a Google Cloud Build task that listen to pushes in a specific branch and will update the app but I have issue automating the db update procedure. If the db update procedure is excluded the app will be built and deployed successfully and works. I have tried to find a solution but wasn't able to (it seems I always seems to struggle to find all the info I need related to GPC and AWS).

I have tried to attach the update script to the composer post-install-cmd event but I got "build": Fatal error: Uncaught PDOException: SQLSTATE[HY000] [2002] No such file or directory in. The connection to the db can't be established. This indicates that the composer install is executed in a different environment.

The other option that I consider is to add additional steps to the Cloud Build procedure to execute composer install and after this execute the db update script. The question is will this work or again I will hit a dead end?

I saw multiple posts downloading cloud_sql_proxy or using gcr.io/google-appengine/exec-wrapper but this will mean that I will need different configuration.

What is the best practice to update the db when building and deploying to Google App Engine? Any suggestions or refers to documentation, tutorials and discussions would be helpful.

botzko
  • 630
  • 3
  • 8
  • Have a look at these stackoverflow [link1](https://stackoverflow.com/q/65325867/18265702) & [link2](https://stackoverflow.com/q/63824604/18265702) – Sandeep Vokkareni May 11 '23 at 10:37

1 Answers1

0

I end up with the following step:

- id: 'Update the DB'
  name: 'eu.gcr.io/local-pier-382211/cloud_sql_proxy:1.0.0'
  env:
    - 'DB_HOST=127.0.0.1'
    - 'DB_NAME=$_DB_NAME'
    - 'DB_USER=$_DB_USER'
  secretEnv: ['DB_PASS']
  script: |
    #!/usr/bin/env bash
    /usr/local/bin/cloud-sql-proxy local-pier-382211:europe-west6:database &
    /usr/local/bin/composer install
    ./bin/db-update.sh

Just remember to add a step after this to clear the cache files that have been generated or to exclude the cache dir from any further steps and deployments. The issues is that the db configuration is different on the Cloud Build and the App Engine. (App Engine uses unix socket instead of host).

botzko
  • 630
  • 3
  • 8