#90daysofdevops journey. Today's challenge is particularly exciting as it entails creating a Jenkins Freestyle Project, an opportunity for DevOps engineers to showcase their skills and push their limits. Who's ready to dive in and make it happen? ๐
What is CI/CD?
CI or Continuous Integration is the practice of automating the integration of code changes from multiple developers into a single codebase. It is a software development practice where the developers commit their work frequently into the central code repository (Github or Stash). Then there are automated tools that build the newly committed code and do a code review, etc as required upon integration. The key goals of Continuous Integration are to find and address bugs quicker, make the process of integrating code across a team of developers easier, improve software quality and reduce the time it takes to release new feature updates.
CD or Continuous Delivery is carried out after Continuous Integration to make sure that we can release new changes to our customers quickly in an error-free way. This includes running integration and regression tests in the staging area (similar to the production environment) so that the final release is not broken in production. It ensures to automate the release process so that we have a release-ready product at all times and we can deploy our application at any point in time.
What Is a Build Job?
A Jenkins build job contains the configuration for automating a specific task or step in the application building process. These tasks include gathering dependencies, compiling, archiving, or transforming code, and testing and deploying code in different environments.
Jenkins supports several types of build jobs, such as freestyle projects, pipelines, multi-configuration projects, folders, multibranch pipelines, and organization folders.
What is Freestyle Projects ?? ๐ค
A freestyle projef project that allowsct in Jenkins is a type o you to build, test, and deploy software using a variety of different options and configurations. Here are a few tasks that you could complete when working with a freestyle project in Jenkins:
Task-01: Jenkins Freestyle Project Configuration:
Prerequisites:
Make sure Jenkins is installed and running.
Docker is installed on the machine where Jenkins is running.
Create a new Freestyle Project:
Open Jenkins and click on "New Item" in the dashboard.
Enter a project name and select "Freestyle project," then click "OK."
Build Section:
- Scroll down to the "Build" section in your project configuration.
Add a Build Step for Docker Build:
Click on "Add build step" and choose "Execute shell"
In the command box, enter the Docker build command:
docker build -t node-app:latest /home/ubuntu/projects
Save the configuration.
Add a Build Step for Docker Run:
Click on "Add build step" again and choose "Execute shell" .
Enter the Docker run command.
docker run -d -p 8080:80 --name your-app-container node-app:latest
Save the configuration.
Save and Build:
Save the project configuration.
Manually trigger a build by clicking on "Build Now" on the Jenkins dashboard.
Task-02: Jenkins Project for Multiple Containers using Docker Compose
Step 1: Prerequisites:
Docker Compose installed on the Jenkins server.
Dockerized application with a Dockerfile and a Docker Compose file available in a Git repository.
Step 2: Create a New Jenkins Project
Open Jenkins and click on "New Item" in the dashboard.
Enter a project name and select "Freestyle project," then click "OK."
Step 3: Configure the Build Section
In the project configuration, go to the "Build" section.
Add a build step by choosing "Execute shell" from the dropdown.
Enter the following command to start multiple containers using Docker Compose:
docker-compose up -d
Step 4: Set up Cleanup Step
In the same project configuration, add another build step for cleanup.
Enter the following command to stop and remove the containers:
docker-compose down
Step 5: Save and Build
Save the configuration.
Trigger a build to test the Docker Compose deployment.
Conclusion: In this blog post, we covered the step-by-step process of setting up Jenkins to automate the deployment of Docker containers. We created two Jenkins projects โ one for a single container deployment and another for multiple containers using Docker Compose. This automation streamlines the deployment process, making it more efficient and reproducible. The screenshots provided along with each step should help you set up your Jenkins projects successfully. Happy automating!