I investigated this question on StackOverflow but unfortunately to me nothing helps.
I have cloudbuild.yaml
file
steps:
- name: 'node:14.16.0'
entrypoint: 'yarn'
id: yarn-install
args: ['install']
waitFor: ["-"]
- name: gcr.io/cloud-builders/yarn
id: proxy-install
entrypoint: sh
args:
- "-c"
- "wget https://storage.googleapis.com/cloudsql-proxy/v1.23.0/cloud_sql_proxy.linux.amd64 -O /workspace/cloud_sql_proxy && chmod +x /workspace/cloud_sql_proxy"
waitFor: ["-"]
- id: migrate
name: gcr.io/cloud-builders/yarn
env:
- NODE_ENV=$_NODE_ENV
- DB_NAME=$_DB_NAME
- DB_USER=$_DB_USER
- DB_PASSWORD=MY_FAKE_PASSWORD
- CLOUD_SQL_CONNECTION_NAME=$_CLOUD_SQL_CONNECTION_NAME
entrypoint: sh
args:
- "-c"
- "(./workspace/cloud_sql_proxy -dir=/workspace -instances=$_CLOUD_SQL_CONNECTION_NAME & sleep 2) && yarn run knex migrate:latest"
timeout: "1200s"
waitFor: ["yarn-install", "proxy-install"]
I want to connect to my Cloud SQL database to apply schema migration by using yarn run knex migrate:latest
.
But it fails on the migrate step
Logs from Cloud Build
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
at PipeConnectWrap.afterConnect [as oncomplete] (net.js:1145:16)
Error: connect ENOENT /cloudsql/project:us-east1:project-posgresql1/.s.PGSQL.5432
Using environment: production
Working directory changed to /workspace/src/infrastructure/knex
Requiring external module ts-node/register
$ ./node_modules/knex/bin/cli.js --knexfile=./src/infrastructure/knex/knex.config.ts migrate:latest --env production migrate:latest
yarn run v1.22.5
sh: 1: ./workspace/cloud_sql_proxy: not found
Already have image (with digest): gcr.io/cloud-builders/yarn
I don't know how to debug it correctly... Could you help me to find the root cause of the problem?
P.S.
...@cloudbuild.gserviceaccount.com has the following roles
- Cloud Build Service Account
- Cloud SQL Client
- Service Account User
- Cloud Run Admin
- Secret Manager Secret Accessor
P.S.S knex is a JavaScript query builder for SQL-like databases