Hello everyone 👋, Welcome back to our blog series Microservices. Today, In this blog we shift our focus to CI from regular development. What does CI mean & how does it help us? Let's get those questions answered.

Continuous Integration

As defined in Google, Continuous integration (CI) is the practice of automating the integration of code changes from multiple contributors into a single software project. It's a primary DevOps best practice, allowing developers to frequently merge code changes into a central repository where builds and tests then run.

What is Continuous Integration? | PagerDuty
Continuous Integration

It's common that, there would be multiple developers working on different features in their own branches and pushing it to master at one stage. We need to make sure, our central branch in the repo is completely deployable i.e. resulting in a successful build.

To automate this process, we will now look at GitHub Actions.

Integrating GitHub Actions with our Microservice repo

You might already know that, we maintain our code on our GitHub organization. Here's the link to the repo, if you're new here. So let's integrate our repository with GitHub Actions to have our own CI pipeline.

Before that, Here's how GitHub defines their feature.

GitHub Actions now supports CI/CD, free for public repositories

GitHub Actions makes it easy to automate all your software workflows, now with world-class CI/CD. Build, test, and deploy your code right from GitHub. Make code reviews, branch management, and issue triaging work the way you want.

GitHub

Creating GitHub workflow

In order to invoke actions of GitHub, we need to create a special folder called .github in our repository. Then create a folder called workflows, and add the following content to ci.yaml file.

name: Build Docker Image.    # Trigger workflow on push to master branch  on:    push:      branches: [ master ]    jobs:    build:      name: Build Docker Image      # uses ubuntu to build the image      runs-on: ubuntu-latest      # checkout code from master      steps:      - name: Checkout        uses: actions/checkout@v2        with:          fetch-depth: '0'      # Build the Docker image on a push to master      - name: Build Docker Image        run:          docker build -t microservice .

The above workflow follows GitHub syntax, and to be precise our CI workflow runs on every push to master, and tries to build a docker image out of our code base.

If the build is successful, it means that a docker build on our repo is successful, and is ready to deploy. Once you push this workflow to one of your repos, GitHub automatically triggers the workflow and you can see this running in your Actions tab.

GitHub Action

The workflow will run on every commit that is pushed to master branch, and the run will be named after your commit message.

You can see that the current code in our repo results in a successful build. This way, GitHub actions helps us in making our CI pipelines seamless and automatic. The example we have shown here, is a very simple example of leveraging the vast abilities of GitHub actions. Check out the documentation to know more.

That's it for this blog, we will meet very soon in our next blog, where we will add CD (Continuous deployment) to this pipeline using Azure Container registry & Azure App Services. So, stay tuned. Until then, stay safe. Cheers ✌


This free site is ad-supported. Learn more