Google Cloud Build Push Migrations During Build

Viewed 195

Currently, I have my cloudbuild setup to do:

- id: "apply migrations"
name: "gcr.io/google-appengine/exec-wrapper"
entrypoint: "bash"
args:
  [
    "-c",
    "/buildstep/execute.sh -i gcr.io/${PROJECT_ID}/${_SERVICE_NAME} -s ${PROJECT_ID}:${_REGION}:${_INSTANCE_NAME} -e RAILS_MASTER_KEY=$$RAILS_KEY -- bundle exec rails db:migrate",
  ]
secretEnv: ["RAILS_KEY"]

When building, I get the following error during the migration step:

Caused by:
Step #3 - "apply migrations": PG::ConnectionBad: could not connect to server: No such file or directory
Step #3 - "apply migrations":   Is the server running locally and accepting
Step #3 - "apply migrations":   connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

What could cause this error to occur? I am unable to find anything about the subject.

1 Answers

The error is about not being able to connect to the database, it seems that the substitutions are not working correctly, in order to correct it verify that your .env files has the correct variables and filled with the information from your instance.

If the file has the information required, try removing the --substitutions flag and replace the variables (${PROJECT_ID}, ${_SERVICE_NAME}, ${_INSTANCE_NAME} and so on) with the correct values directly into your cloudbuild.yaml file.

Related