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 Jenkins Freestyle Project?
Jenkins freestyle project is an configuration and options based project which will allows you to build,test, and deploy the application with automation by selecting the required configuration based on the requirement following are the some of the available in the freestyle project.
Building and testing code
Packaging applications
Deploying applications to production servers
Running reports
Task-01
create a agent for your app. ( which you deployed from docker in earlier task)
Create a new Jenkins freestyle project for your app.
In the "Build" section of the project, add a build step to run the "docker build" command to build the image for the container.
Add a second step to run the "docker run" command to start a container using the image created in step 3.
For public repositories no credentials are required
Console output after making changes to docker file
Docker build image and running container
Browsing web application in local browser to see if container is running or not
Validating docker container status in local machine
Task-02
Create Jenkins project to run "docker-compose up -d" command to start the multiple containers defined in the compose file (Hint- use day-19 Application & Database docker-compose file)
Set up a cleanup step in the Jenkins project to run "docker-compose down" command to stop and remove the containers defined in the compose file.
container status in local machine
Bring container down
We will modify build configuration by modifying command
We were able to bring up and down container in our build configuration in jenkins free style project
How Did I fix authentication issue?
I also faced authentication issue using github, as the ssh key was configured in another server and I didnt want to use token, so I used below steps to copy my ssh key from old server to new server
How to connect to GitHub from more than 1 server using same key
Copy SSH Key from Old Server If you want to reuse the SSH key from the first server:
On Old Server, copy the key:
scp ~/.ssh/id_rsa* new_server:/home/your_user/.ssh/
On New Server, set the correct permissions:
chmod 600 ~/.ssh/id_rsa
chmod 644 ~/.ssh/id_rsa.pub
Command to add jenkins user to docker
sudo usermod -aG docker jenkins
Code repository:
Static website : https://github.com/rk237/staticwebsite
Multi-container : https://github.com/rk237/multi-container-docker