25 Days of Serverless – Day 16

The 25 Days of Serverless challenge for Day 16 was an important nod to CI/CD delivery of serverless solutions. The requirements include checking that submitted information adheres to the proper format (continuous integration) and the solution automatically deploys once a pull request is completed (continuous delivery).

Continuous Integration

To me, continuous integration (CI) is the bigger and more dynamic of the CI/CD holy grail. Well-executed CI requires unit tests and may include some of the following items to facilitate managing CI/CD at scale in a project:

  • feature branches
  • automatic release note compilation
  • automatic package publishing

True continuous integration is a step above implementing continuous delivery! As of the time of writing (Dec 17), only 2 of the solutions submitted include unit tests. Here’s a quick recap of what the individuals did – check out their repositories for more details!

Azure DevOps Pipeline

Niall created an Azure Function in NodeJS with an accompanying Azure DevOps Pipeline for CI/CD. Azure DevOps Pipelines are split between “Build” and “Deploy” – somewhat analogous to CI and CD. The activity that we’re focusing on is in the build section.

<p>
  In the build section, &#8220;Prepare Binaries&#8221; includes evaluation of <a rel="noreferrer noopener" aria-label="a set of tests (opens in a new tab)" href="https://github.com/nkelly75/25-days-of-serverless/blob/master/day16/Posadas/index.test.js" target="_blank">a set of tests</a>, often referred to as unit tests. These tests can look for malformed code and compare outputs for expected values.
</p>

<p>
  Kudos to Niall Kelly on a nice solution! <a rel="noreferrer noopener" aria-label="https://github.com/nkelly75/25-days-of-serverless/blob/master/day16/README.md (opens in a new tab)" href="https://github.com/nkelly75/25-days-of-serverless/blob/master/day16/README.md" target="_blank">https://github.com/nkelly75/25-days-of-serverless/blob/master/day16/README.md</a>
</p>
Niall Kelly’s CI/CD Pipeline in Azure DevOps Pipelines

GitHub Actions

Deepak created an Azure Function in Python and defined a GitHub action to run on pull request creation. The crucial step of the pull request is that it not only builds the solution, but it also runs a Python test suite called pytest with a custom set of tests.

Deepak Dhami’s CI/CD Pipeline in GitHub Actions

Deepak went the extra mile and provided an example of a pull request where the included JSON didn’t meet the formatting requirements.

<p>
  If the tests had succeeded, the GitHub actions workflow would have continued to deploy the solution &#8211; full CI/CD.
</p>

<p>
  Kudos to Deepak Dhami on a nice solution! <a href="https://github.com/DexterPOSH/25dayofserverless/pull/1/checks?check_run_id=352620562">https://github.com/DexterPOSH/25dayofserverless/pull/1/checks?check_run_id=352620562</a>
</p>

Continuous Delivery

Frankly, setting up continuous delivery with Azure Functions can be very simple from within the Azure Portal. One of the options within the Azure Portal UI for all App Services is source control integration, which ties in tightly with GitHub.

(1) Select the function

<p>
  (2) Select the &#8220;Platform features&#8221; tab
</p>

<p>
  (3) Select &#8220;Container settings&#8221; under &#8220;Code Deployment&#8221;
</p>

Azure Function Deployment Center

Kudu

<p>
  For simple/default build scenarios (including no build), the Kudu engine does a fantastic job of deploying your Azure function(s).
</p>

<p>
  The Kudu build server receives a webhook from the repository and branch of your choosing, kicks off the build, then deploys the new code.
</p>
Reviewing Previous Deployments by the Kudu Service

Azure DevOps Pipelines

<p>
  Technically in preview, Azure DevOps pipelines can be utilized for continuous deployment of Azure Functions. ADOP are ideal for complex build processes or if your unit tests are set up through the same pipeline service. <a href="#niall-kelly">Niall Kelly&#8217;s solution</a> includes continuous delivery through Azure DevOps Pipelines.
</p>

GitHub Actions

<p>
  A quick shout-out to the secret third option, <a rel="noreferrer noopener" aria-label="deploying through GitHub actions (opens in a new tab)" href="https://docs.microsoft.com/en-us/azure/azure-functions/functions-how-to-github-actions?tabs=javascript" target="_blank">deploying through GitHub actions</a>. Not a first-class citizen in the Azure Portal and requiring a bit more set up, but allowing similar flexibility to Azure DevOps Pipelines. <a href="#deepak-dhami">Deepak Dhami&#8217;s solution</a> includes continuous delivery through GitHub Actions.
</p>

CI/CD Combinations

CI/CD is an area where serverless solutions shine – the way we view a serverless solution as more compartmentalized lends to writing unit tests and the available technologies make continuous delivery a 3-click setup. Within the Microsoft framework, you can combine CI/CD solutions for Azure Functions in a few different ways to create the solution that best fits your project.

<th>
  Continuous Integration
</th>

<th>
  Continuous Delivery
</th>
<td>
  GitHub Actions
</td>

<td>
  Kudu Build Service
</td>
<td>
  GitHub Actions
</td>

<td>
  Azure DevOps Pipeline
</td>
<td>
  GitHub Actions
</td>

<td>
  GitHub Actions
</td>
<td>
  Azure DevOps Pipeline
</td>

<td>
  Azure DevOps Pipeline
</td>
1
2
3
4

With the ability to run tests through GitHub Actions, even if you already have deployments set up through another solution, you can add unit tests without disturbing a working CD solution. Unit tests are making it onto my 2020 developer’s resolutions and I’ll be able to implement them onto current projects without changing the deployment process. Thanks to solutions like Deepak’s and Niall’s I’m inspired to check out other CI/CD architectures for upcoming projects!