The Continuous Integration and Continuous Delivery pipeline or CI/CD pipeline is a whole chain of processes. Several services are sequentially included in it – Portainer, Jenkins, Docker Swarm, Ansible. How has this been done in practice? In the article, we will consider the implementation of such a chain on an example of Node JS Web Development Company.
How are goals determined?
To effectively implement the project, you first need to understand what the stakeholders expect from it – the business customer and the IT team. It is no secret that business people are trying to earn as much as possible in the shortest possible time, so they are waiting for a quick launch of the finished product on the market. Performers see other goals in front of them. The developers in the first place are not finances, but a creative approach, confirmed by a real result. The admin, in turn, strives to provide a quality service, adhering to the DevOps methodology in accordance with the principles of CI / CD (as stated in this project). Conclusion: the organization of a pipeline will help, which will cover all stages of work up to the launch of the product for final testing.
Teamwork begins with a discussion of the choice of system architecture.
We propose to dwell on its two main components:
- backend in Java (implementation using the Spring Boot framework);
- frontend on NodeJS (with an NGINX server that distributes requests between the application and the infrastructure components of the system) + ReactJS.
The technical task of the IT team at the initial stage is to prepare equipment for an efficient CI / CD pipeline, so the pipeline will look like a chain of certain operations:
- posting a developer commits to git →
- testing git of the received commit (having the correct format, comparable styling, etc.) →
- webhook mechanism of the git server will use Jenkins, then download the sources to start the pipeline.
Here is the procedure:
- compilation →
- source testing →
- building the next version of Docker images →
- their publication in a special system Artifactory →
- restarting the received product variant on the server.
If an upgrade fails, you can always roll back to a previous version.
The described solution in the form of chains of successive actions is suitable for web-based applications. It is simple and easy, understandable to each of the performers.
About installation and basic settings on the host system
While implementing the tasks set, the IT team decided to use Ansible. This made it possible to achieve maximum automation of the entire pipeline of the host system, its high-quality functioning in just three stages.
The initial one is ssh HostKeyChecking. Needed to check the ssh fingerprint of a remote configurable host. In this mode, password authorization is disabled, so several solutions are suggested:
- an ssh fingerprint is added to local cash (for example, add host_key_checking to ansible.cfg to disable the check completely, or define a special environment variable to stop the check).
- disabling HostKeyChecking.
The second stage is Inventory. Assumes a description of those hosts whose configurations need to be managed. Two formats are offered for this – either yml or ini. We chose the yml format.
The third one is Playbook. From Inventory, the final state of the hosts is described declarative in the initial format (here yml) and the complete configuration of the base system, which involves creating users, and installing Docker.
What services can be used?
One of the useful services turned out to be Jenkins CI. It is required for deployment and Continuous Integration. It is necessary to pay attention to several key points:
- each image gets its own label tag (very helpful when rolling back a failed application);
- tasks-piplans – declarative, scripted (in Groovy Script – tasks, in git – source code);
- in the Docker container, Jenkins runs the Ansible playbook code, and the password is temporarily stored on the local machine (the file for this operation is initialJenkinsAdminPassword.txt).
You can read here more interesting cases and tips.