Hi all,
What I'm trying to do is to configure a pipeline that would connect to postgresql google cloud instance, and run django migrations.
I experimented a bit, and so far I wasn't very successful.
I can use the google/cloud-sdk image to connect to the instance, and it seems to be runing fine using those commands:
-step:
image: google/cloud-sdk
script:
- echo $GOOGLE_CLIENT_SECRET > ./gcloud-api-key.json
- gcloud auth activate-service-account --key-file gcloud-api-key.json
- gcloud config set project $CLOUDSDK_CORE_PROJECT
- apt-get install wget
- wget https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 -O cloud_sql_proxy
- chmod +x cloud_sql_proxy
- ./cloud_sql_proxy -instances="[$DEV_GCP_DB_INSTANCE]"=tcp:5432
However if I run this as a step, it won't help much because it run as a server:
<span>+ ./cloud_sql_proxy -instances="[$DEV_GCP_DB_INSTANCE]"=tcp:5432<br>2018/11/20 00:21:38 current FDs rlimit set to 1048576, wanted limit is 8500. Nothing to do here.<br>2018/11/20 00:21:38 Listening on 127.0.0.1:5432 for [test-django-pg:europe-west1:test-django-db]<br>2018/11/20 00:21:38 Ready for new connections<br><br><br></span>
<span>So I need to run it as a service. I tried multiple solutions but so far I was unlucky.</span>
<span>Here's the last one:</span>
<span> branches:<br> dev:<br> - step:<br> image: python:3.6.2<br> caches:<br> - pip<br> script:<br> - pip install -r requirements.txt <br> - python monsite/manage.py migrate <br><br>definitions:<br> services: <br> cloudsql:<br> image: google/cloud-sdk<br> command: <br> - echo $GOOGLE_CLIENT_SECRET > ./gcloud-api-key.json <br> - gcloud auth activate-service-account --key-file gcloud-api-key.json<br> - gcloud config set project $CLOUDSDK_CORE_PROJECT<br> - apt-get install wget<br> - wget https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 -O cloud_sql_proxy<br> - chmod +x cloud_sql_proxy<br> - ./cloud_sql_proxy -instances="[$DEV_GCP_DB_INSTANCE]"=tcp:5432<br> restart: always</span>
I also tried using the image: gcr.io/cloudsql-docker/gce-proxy:1.13 but this image requires a credential file to be passed as an argument to cloud_sql_proxy and I wasn't able to do it.
Any help welcome !
Thanks