In this lab you will learn how to implement Continuous Delivery of your application using two different services:
- GitLab provides an integrated CI/CD DevOps pipeline which makes use of Docker containers and is simple to configure.
- CodeShip is example of Software as a Service (SaaS) and integrates with GitHub via an authentication token.
Resources:
Feel free to make use of the simple authentication API in your assignment, this will allow you to focus on building the core functionality. Be aware you will need to modify it to get it to integrate into the rest of your project.
The first step you need to take is to authenticate CodeShip by creating an access token. From the top right menu choose settings:
Choose Developer settings from the left sidebar and then choose Personal access tokens.
Choose Generate new token. You will need to choose the following permissions:
- admin:public_key
- admin:repo_hook
- repo
Call the new token CodeShip and generate the token. You will then need to copy this to the clipboard.
Log into CodeShip and locate the Connected services option from the settings menu.
Switch on the GitHub enterprise option and enter the following details, substituting your university username and your access token.
You should now access the Projects menu in CodeShip and choose New Project. Make sure you choose the GitHub Enterprise link and not the GitHub icon!
Paste in the GitHub url where requested and, on the next screen select Basic project.
On the Configure your tests screen choose NodeJS from the dropdown list and delete all the commands from the list except npm install
.
Each week you will be expected to complete a series of lab activities. You will be required to reflect on these in your assignment so make sure you keep records of what you have done. This lab will include your third sprint and will bring together many of the topics already covered.
There is an example repository on GitLab
In the previous sprint you used the Pull Request mechanism to integrate code into the master branch. In this sprint you will replace this with the process of Continuous Integration. These two approaches are non-complimentary and each has its pros and cons. By the end of this sprint you will have a good understanding of these.
Your team should already have a suite of tests for both functional and non-functional requirements for each component in your project and, in this lab, you will be using these to build a Continuous Delivery Pipeline using the tools integrated into GitLab.
The restrictions are that you can only use tests that return either pass or fail and have a non-zero code on failure. This should include:
- Linters.
- Unit tests.
- Module dependency tests.
- Code duplication checks.
- Code coverage checks (if there is an option to specify thresholds).
You will need to create a .gitlab-ci.yml
file in the root directory of your project which will be detected by GitLab and run each time you push your code. These are lots of examples available for you to learn from, both in the exercises/08_ci/
directory and online. Make sure the CI Pipeline is correctly configured by pushing both good and bad code before starting your third sprint.
You will also need to configure GitLab to only allow merging if all tests have passed. In this way you can bypass the requirement for the code to be reviewed by the Scrum Master which should speed up the process of integrating code into the Master branch.
To help you configure your GitLab CI pipeline there are a couple of sample repositories you should be studying which cover most of the platforms you are developing for:
ci-nodejs shows how to build a CI and CD pipeline for a NodeJS API.
- Create a local feature branch if the task is new and push to remote.
- Rest of team pull the branch and switch to it then run existing test suites.
- Write unit tests and integration tests to define new functionality.
- Now code should be written to pass the tests making sure all the non-functional tests such as the linter and code duplication checker still pass.
- Once local tests pass:
- code should be pushed to remote (triggering CI tests).
- Code changes should be pulled from the master branch.
- Now the branch can be merged into the master branch:
- Create a pull request on GitLab.
- If all the tests have passed on both branches you can merge the code.
- Delete the feature branch if the feature is complete.
Docker Hub contains a complete Jenkins image which you can deploy to a heroku instance.