Similar to this issue. (I will describe the link in more detail below)
Problem: When running my Google Cloud Build I get an error stating:
django.db.utils.OperationalError: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/cloudsql/sample-kubernetes-268320:us-west1:cloud-build-staging/.s.PGSQL.3306"
I am following the solution posted here by collaborator. They provide a sample cloudbuild.yaml that I followed closely without any luck.
Working cloudbuild.yaml
steps:
- id: proxy-install
name: alpine:3.10
entrypoint: sh
args:
- -c
- 'wget -O /workspace/cloud_sql_proxy https://storage.googleapis.com/cloudsql-proxy/v1.16/cloud_sql_proxy.linux.386 && chmod +x /workspace/cloud_sql_proxy'
waitFor: ['-']
- id: execute-with-proxy
name: python:3.7
timeout: 100s
entrypoint: sh
args:
- -c
- '(/workspace/cloud_sql_proxy -dir=/workspace -instances=[INSTANCE_CONNECTION_NAME] & sleep 2) && (pip install -r requirements.txt && python test_sql.py)'
waitFor: ['proxy-install']
My cloudbuild.yaml
steps:
- id: proxy-install
name: alpine:3.10
entrypoint: sh
args:
- -c
- 'wget -O /workspace/cloud_sql_proxy https://storage.googleapis.com/cloudsql-proxy/v1.16/cloud_sql_proxy.linux.386 && chmod +x /workspace/cloud_sql_proxy'
waitFor: ['-']
- id: Test
name: 'python:3.7.6-buster'
env:
- "CLOUDBUILD_TEST=True"
timeout: 100s
entrypoint: /bin/sh
args:
- -c
- '(/workspace/cloud_sql_proxy -dir=/workspace -instances=sample-kubernetes-268320:us-west1:cloud-build-staging & sleep 2) && (pip install -r requirements.txt && cd fastestfollowup && python3 manage.py test)'
waitFor: ['proxy-install']
Steps I've taken to debug this:
- I have added the Cloud Build Service as the Cloud SQL Admin
- I have ensured my instance name is correct through using
gcloud sqlinstances describe cloud-build-staging
and copying the "connectionname"
Edit: I changed my cloudbuild.yaml file from
args:
- -c
- '(/workspace/cloud_sql_proxy -dir=/workspace -instances=sample-kubernetes-268320:us-west1:cloud-build-staging & sleep 2) && (pip install -r requirements.txt && cd fastestfollowup && python3 manage.py test)'
to:
args:
- -c
- '(/workspace/cloud_sql_proxy -dir=/cloudsql -instances=sample-kubernetes-268320:us-west1:cloud-build-staging & sleep 2) && (pip install -r requirements.txt && cd fastestfollowup && python3 manage.py test)'
With no effect.