How do I correctly setup Gitlab CI for Google cloud with SQL

10/13/2019

I want to setup Gitlab CI to automatically test and deploy my Node.js project to google cloud kubernetes engine. I also want to be able connect to my google cloud sql instance.

Im currently working with Gitlab auto devops. I have connected my kubernetes cluster in gitlab and installed Helm, Ingress, Cert-Manager and Prometheus.

After a bit of reseach i found out, that i have to deploy a Cloud SQL Proxy to be able to access the sql instance from my Node.js server.

My Dockerfile configuraton:

FROM node:10.16.3

# Intsall Google Cloud SQL Proxy
RUN wget https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 -O cloud_sql_proxy
RUN chmod +x cloud_sql_proxy
RUN ./cloud_sql_proxy -instances=myProject:zone:name=tcp:3306

# Node
WORKDIR /usr/src/app

ARG NODE_ENV
ENV NODE_ENV $NODE_ENV

COPY package.json /usr/src/app/
RUN npm config set "@fortawesome:registry" https://npm.fontawesome.com/
RUN npm config set "//npm.fontawesome.com/:_authToken" KEY
RUN npm install

COPY . /usr/src/app 

EXPOSE 5000
CMD [ "npm", "start" ]

But this fails while building:

2019/10/13 11:48:38 current FDs rlimit set to 1048576, wanted limit is 8500. Nothing to do here.
2019/10/13 11:48:40 error checking scopes: *url.Error Get http://x.x.x.x/computeMetadata/v1/instance/service-accounts/default/scopes: dial tcp x.x.x.x:80: i/o timeout | Get http://x.x.x.x/computeMetadata/v1/instance/service-accounts/default/scopes: dial tcp x.x.x.x:80: i/o timeout
The command '/bin/sh -c ./cloud_sql_proxy -instances=myProject:zone:name=tcp:3306' returned a non-zero code: 1

Why does this error occure?

Do i have to write my own .gitlab-ci.yml configuration to handle such a common scenario?

If so are there any templates for this usecase, because all i find is just for manually deploying apps with docker to GKE with SQL?

-- Gonios
gitlab-ci
google-kubernetes-engine
kubernetes

0 Answers