The world’s leading publication for data science, AI, and ML professionals.

Setting up continuous integration on Cloud Function

No more spending time with integration when using cloud functions

Photo by sarah Mahmuda on Unsplash
Photo by sarah Mahmuda on Unsplash

Introduction

Integration is the process of taking your changes and pushing it to the application. It can be done in lots of ways, like changing the code directly in the application and restarting it or through a process called continuous integration. Continuous integration is when you make the integration process automatic. It can be done connecting your application to your source repository. Doing it in this way, you can set up your code to be integrated when you merge with the master/main branch. When using google cloud functions, is really simple and it is made through Google Source Repositories.

Google Source Repositories

Cloud Source Repositories is a google solution for code storage, management, and tracking. It’s like git hub, but created by google. In GSR, it is possible to track a git hub repository and integrate it to functions. Let’s check. First, access google console and at CI/CD subgroup on the lateral bar, click in source repositories. Click in Get Started and so in Create repository. After it, this modal should appear:

Click on Connect external repository and then in continue.

Select your project name and your git provider. In my case it is My First Project and Git Hub.

Click in Connect to GitHub. A github page will appear. Put your GH credentials and authorize the connection.

After it, click in Authorize Google Cloud Platform. Now you should be able to see your repo on GSR, like the figure below:

Google Cloud Functions

Now go to google cloud functions, open or create your function (check out my last article https://towardsdatascience.com/deploying-python-functions-with-google-cloud-functions-557517865ba7 on this subject if you have any doubts on creating a cloud function and testing it)

Open your function, click next and change the source code to cloud repository.

  • Type the name of your repository in repository (google, please, provide us a drop down in next versions).
  • Select branch or tag. If branch, put the name of the deploy branch. In general we use the master branch to do so.
  • In directory with source code, put your directory path. Here, there is a tip. If the folder which holds the .py file that contains your entry point is in the foder example_folder, put /example_folder.

After it, choose deploy and the continuous integration is done. Be happy and go spend your time with funny things instead of integrating code by hand.

Conclusions

Making integrations by hand are tasks time consuming. The possibility of automatic integration saves time. Doing it in google cloud functions is easy. It is just necessary to set up cloud repositories (connect it to your git provider, like github and bitbucket). Using these tooling enables us to just commit and then integrate. It makes the deployment process simpler and helps us to delivery our functionalities in less time. See you in the next article!

References

[1] https://cloud.google.com/source-repositories

[2] https://towardsdatascience.com/deploying-python-functions-with-google-cloud-functions-557517865ba7


Written By

Topics:

Related Articles