title: Issue connecting to Database during Google Cloud Build process
body: <p>Similar to <a href="https://stackoverflow.com/questions/52352103/run-node-js-database-migrations-on-google-cloud-sql-during-google-cloud-build">this issue.</a> (I will describe the link in more detail below)</p>
  
  <p>Problem:
  When running my Google Cloud Build I get an error stating:</p>
  
  <pre><code>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"
  </code></pre>
  
  <p>I am following the solution <a href="https://github.com/GoogleCloudPlatform/cloudsql-proxy/issues/317#issuecomment-543392502" rel="nofollow noreferrer">posted here</a> by collaborator. They provide a sample cloudbuild.yaml that I followed closely without any luck.</p>
  
  <p>Working cloudbuild.yaml</p>
  
  <pre><code>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 &amp;&amp;  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] &amp; sleep 2) &amp;&amp; (pip install -r requirements.txt &amp;&amp; python test_sql.py)'
      waitFor: ['proxy-install']
  </code></pre>
  
  <p>My cloudbuild.yaml</p>
  
  <pre><code>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 &amp;&amp;  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 &amp; sleep 2) &amp;&amp; (pip install -r requirements.txt &amp;&amp; cd fastestfollowup &amp;&amp; python3 manage.py test)'
      waitFor: ['proxy-install']
  </code></pre>
  
  <p>Steps I've taken to debug this:</p>
  
  <ol>
  <li>I have added the Cloud Build Service as the Cloud SQL Admin</li>
  <li>I have ensured my instance name is correct through using <code>gcloud sqlinstances describe cloud-build-staging</code> and copying the "connectionname"</li>
  </ol>
  
  <p>Edit:
  I changed my cloudbuild.yaml file from</p>
  
  <pre><code>    args:
        - -c
        - '(/workspace/cloud_sql_proxy -dir=/workspace -instances=sample-kubernetes-268320:us-west1:cloud-build-staging &amp; sleep 2) &amp;&amp; (pip install -r requirements.txt &amp;&amp; cd fastestfollowup &amp;&amp; python3 manage.py test)'
  </code></pre>
  
  <p>to:</p>
  
  <pre><code>    args:
        - -c
        - '(/workspace/cloud_sql_proxy -dir=/cloudsql -instances=sample-kubernetes-268320:us-west1:cloud-build-staging &amp; sleep 2) &amp;&amp; (pip install -r requirements.txt &amp;&amp; cd fastestfollowup &amp;&amp; python3 manage.py test)'
  </code></pre>
  
  <p>With no effect.</p>