While preparing for a new enterprise-grade project we had a new challenge. The project will benefit from Google Cloud Platform and will contain 500+ Google Cloud Functions as a part of serverless components.
During early meetings for our source control architecture, we decided to contain all Google Cloud Functions into single repo (Mono-Repo). The challenge was how to implement CI/CD pipeline for the functions.
I decided to take care of the issue and automate the build pipeline, my criteria were as follows:
So, to meet the criteria and accomplish the task, I wrote down the needs:
My solution was to depend on GitHub actions, which is a very good tool for CI/CD automation with a broad spectrum of flexibility. Here are the steps:
As my repo is ready, I created a new repository in our GitHub organization's account, and added it as remote to the local mono repo, then head to Actions tab to create new CI/CD action. Action triggered for each new push to the main branch, see the code
This is the core of the solution! To identify changed functions, I used git diff command. Git diff is part of Git plumbing tools. It can be used to git changed files or directories between two commits, branches, etc. So, I used git diff and piped results into a series of manipulations to get directories only, filter for directories containing func word (to follow the convention), and convert results into JSON like array of elements. The result will be like this
[“func1”, “func3”, “fun10,”, …]
GitHub actions has a nice feature called matrix that holds elements you can loop on. To this step, I used the matrix to store JSON array.
Once I have the matrix, it was easy to run google-github-actions/deploy-cloud-functions@v0.1.2 action to deploy changed functions as GitHub actions will loop through each element of the matrix and deploy it one by one.
Thank you for reading and you can read also:
CI/CD for Google Cloud Functions in a mono repo. the solution depends on GitHub actions, which is a tool for CI/CD automation with broad spectrum of flexibility
أيا كانت طبيعة عملك أو حجمه ستهتم بمعرفة ما يتضمنه المقال من شرح وتفصيل لكل ما يتعلق بالفاتورة الالكترونية
عندما تفكر في نشاطك كتسويق خدمتك البرمجية كمنتج فأدوات التسويق الالكتروني أثبتت كفاءة عالية في الحصول علي صفقات كاملة ومربحة
© 2021 Aten Technologies for Enterprise Content - All rights reserved.