Creating a Google Function with Gitlab integration in 10 minutes!
--
Hello everyone!
I’m working in a side project and I needed to create a Google Functions for my back-end, using NodeJS, Google Cloud SQL with MySQL.
I will show you the easier way to create an integration between your Gitlab and Google Cloud Platform.
You can see my NodeJS Project example in my Github
https://github.com/massatotakaki/first-gcp-function-integration
- Let’s start creating an initial NodeJS project based on GoogleCloud Docs instructions.
https://cloud.google.com/functions/docs/first-nodejs
or clone my Github example project - Let’s create a new project on Google Cloud Platform.
Create a Service Account
Click on CREATE SERVICE ACCOUNT
Write your service account name
Grant the Roles:
-Cloud Functions Admin
-Service Account User
Click on CREATE KEY
Create a JSON file, download and save to the project root
After creation you can see your Keys.
Now your project looks like this
3. Let’s create a integration
At the root of the project, create a file named: .gitlab-ci.yml
deploy to gcloud:image: google/cloud-sdk:latestscript:- gcloud auth activate-service-account — key-file=./gcloud-service-key.json- gcloud config set project PROJECT-GCP-NAME- gcloud functions deploy FUNCTION-NAME — runtime nodejs8 — trigger-http — allow-unauthenticated