Building microservices through Event Driven Architecture part11: Continuous Integration
This tutorial is the 11th part of a series : Building microservices through Event Driven Architecture.
The previous step is about building microservices through Event Driven Architecture part10: Run Unit tests inside a docker container : https://logcorner.com/building-microservices-through-event-driven-architecture-part11-run-unit-tests-inside-a-docker-container/
In this tutorial, I will show how to setup a docker continuous integration to build and run unit tests inside a docker container.
Because I will run the micro services in containers using kubernetes, unit tests, integration tests, continuous integration and continuous delivery will be done with docker images and containers.
Create an Azure Devops project
The code source of the project I am going to build is in github https://github.com/logcorner/LogCorner.EduSync.Speech.Command
So I have at least 2 solutions to setup an azure devops continuous integration using the concerned git repository :
- I can import the code source to azure devops and use Azure Repos Git, In this way the code source will be imported on azure devops
- I can also use the repository in Github, the code source remains on github
I will show how to setup the 2 solutions but in this tutorial, I will use the second solution.
Create project
Go to https://dev.azure.com/ and create an account or sign in if you have already an account
Then create a new project in my case I name it LogCorner.EduSync.Speech.Command
I make the visibility as public because it is a demo, use git version control option and scrum
Create an Azure Devops Pipeline
Select source code
Solution 1 : Import the github code source
Select Repos on the left side, and click on files and then click on import
Go to your github account and copy the url of the repository to import https://github.com/logcorner/LogCorner.EduSync.Speech.Command.git
Then I will create a personnal access token , because gihub will use it to authorize access to the repository.
To create a personnal access token (PAT), select settings, then select Developper settings
Click on Personal Acces token, click on New personal access token, give it a name and select the scope
For the scope I have selected repo, it is enough the setup and run the build
Paste the github repository url and the PAT on the azure devops popup window , give a username and click import
The code source should be imported on azure devops as follow
Solution 2 : use github as code source
For this option, you have to create a build pipeline first and choose github as selected source, github will ask me to setup a trusted connection using OAuth.
Select Pipelines on the left side and click on Create Pipeline
Select Github , give a connection name anc click on authorize
It will prompt for your github credentials
Accept and then select the repository to build and the branch and click on continue.
Here I have selected logcorner/LogCorner.EduSync.Speech.Command and the master branch.
Create the pipelines tasks
I have used the classic editor and created an Empty pipeline
Build Task
For the build task , I use a docker-compose task, I have to the run Docker-compose build command using the files :
- docker-compose.yml
- docker-compose.override.yml
- docker-compose-unit-tests.yml
- docker-compose.override-unit-tests.yml
Here is the yaml for this build task
The yaml file for this task is located here : LogCorner.EduSync.Command\src\CICD\BuilTask.yml
Run Unit Test Task
For the run unit tests task , I use a docker-compose task, I have to the run Docker-compose up command using the files :
- docker-compose.yml
- docker-compose.override.yml
- docker-compose-unit-tests.yml
- docker-compose.override-unit-tests.yml
Here is the yaml code for the run unit tests task
LogCorner.EduSync.Command\src\CICD\PublishTestResultTask.yml
I use one docker-compose task to run the unit tests of 4 projects, so one project unit tests may failed while the others succeeded.
The easiest way I found is to make the task pass even if a test failed and then make the publish tests result task failed if a test failed.
Another solution is to create a run unit test task for each project and use the run a specific service image action instead of run a docker-compose command
The yaml file for this task is located here : LogCorner.EduSync.Command\src\CICD\RunUnitTestTask.yml
Publish Test result Task
Here is the yaml file for the Publish Test Results task
The yaml file for this task is here : LogCorner.EduSync.Command\src\CICD\PublishTestResultTask.yml
Run Build
To test the build configuration, I can trigger a new build
Build Logs
Test results
Code source is available here : https://github.com/logcorner/LogCorner.EduSync.Speech.Command/tree/Feature/DevOps
The azure devops project is here https://logcorner.visualstudio.com/LogCorner.EduSync.Speech.Command
Thanks for reading, if you have any feedback, feel free to post it
Regards