DevOps Pipeline: Nginx
Here’s a structured approach to running and understanding the DevOps pipeline as described in your lab. This lab demonstrated a complete DevOps workflow, including code versioning, continuous integration, and deployment automation. I’ll outline each step and tool involved, along with tasks specific to each phase of the pipeline.
Lab Overview and Step-by-Step Instructions
Preparation and Access
Start by ensuring that each machine in the pipeline is reachable and has the necessary credentials ready for access.
Kali Machine: Used for pulling, modifying, and pushing code.
Gitlab Server:
URL: GitLab
Credentials: Username: root | Password: welcome123
Jenkins Server:
URL: Jenkins
Credentials: Username: admin | Password: welcome123
Test Server:
SSH Access: Username: tomcat | Password: password1
Reachable at: test-server
Pipeline Breakdown
The pipeline is defined as a Jenkinsfile, specifying each component’s task in a sequential flow. Each task in the pipeline corresponds to a phase in the DevOps lifecycle:
Build Phase: Compilation and packaging
Test Deployment Phase: Provisioning and deployment
Dynamic Testing Phase: Automated testing
Running the Pipeline
Let’s log into Jenkins using the credentials provided.
Once logged in we’ll see an interface like this
Here we can see that there is only one job (Nginx) available in the Jenkins instance.
Going on to the Nginx job we see that this page is for the “Pipeline Nginx” job. The pipeline is appended in front of the Job name because this is a “Pipeline” type job in which it accepts a ‘Jenkinsfile’ which has all the commands and configurations of the pipeline.
Now, let’s click on the “Configure” option to check the configuration of the Job.
The “Pipeline” section accepts Jenkinsfile directly or a source such as Gitlab where the code and Jenkinsfile are stored for the project. The code is hosted on a GitLab instance at this path “http://gitlab/root/nginx-1.18.0.git”
Now, let’s open the project on GitLab and check the Jenkinsfile to build the pipeline.
We can see that the file includes ‘stages’ that are a collection of steps, Each step performs a function which is explained below:
Jenkinsfile Stages:
Building the project : Checkout: In this stage, the git repository will be checked for updates or commits. If commits are found in the repository, the new files will be fetched from the remote repository.
Building the project : Build: In this stage, Ansible will initiate the installation of Nginx on the remote server (test server).
Selenium Testing : Build: In this stage, Jenkins will start checks on the newly deployed server to verify if the installation was successful or not.
The code for ansible (nginx.yml) and selenium (selenium_check.py) are stored in the Gitlab repository itself.
Now let’s check the ansible configuration of the Nginx installation. The nginx.yml can be found in the root directory of the project.
The Ansible configuration includes these main tasks:
Check for Existing Nginx Installation: Ensures no conflicting versions of Nginx are present.
File Transfer: Copies necessary files to the test server.
Install Nginx: Install the latest version of Nginx.
Start Nginx: Launches the Nginx service on the test server.
Each task runs sequentially, creating a reliable automation script for Nginx installation.
Once the deployment is complete, we use Selenium to validate the Nginx setup.
The selenium_
checks.py
script performs two key tests:
Check Home Page: Opens the default Nginx page and confirms it displays “Welcome to Nginx!”
Check 404 Page: Verifies that a non-existent page returns the “404 Not Found” error.
This test suite ensures that Nginx was successfully deployed and is fully operational.
Pipeline Execution
Let’s now navigate to the pipeline tab. Return to the Jenkins job page for “Nginx” and open the Pipeline tab.
Trigger the Build. Click Build Now to start the pipeline. Jenkins will automatically proceed through each stage, displaying logs for each step in real time. Monitor these logs to confirm that each task executes without issues.
The pipeline completed the execution successfully.
Now let’s check the test server.
And we can see that the default page of Nginx is displayed on the test server which means the installation of Nginx was successful
Key Takeaways
Completing this pipeline setup provides insight into several essential DevOps tools and practices:
End-to-End Pipeline Creation: From configuration management with GitLab and Ansible to automated testing with Selenium, this pipeline demonstrates an efficient DevOps workflow.
Jenkins as a CI/CD Orchestrator: Jenkins simplifies complex deployments by automating each stage in the pipeline.
Ansible for Automated Deployment: Ansible’s role in automating software deployment is critical, especially when managing configurations across multiple environments.
Selenium for Automated Testing: Selenium tests ensure each deployment is verified and ready to go live, improving reliability.
Conclusion
By following this guide, you’ve deployed a fully functional Nginx server using a Jenkins-based DevOps pipeline. This experience reinforces best practices in continuous integration and continuous deployment (CI/CD) and demonstrates how automated tools can streamline development, deployment, and testing processes.
Subscribe to my newsletter
Read articles from REHAN SAYYED directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
REHAN SAYYED
REHAN SAYYED
Passionate cybersecurity enthusiast and red teamer, exploring the depths of offensive security. From secure code reviews to red team operations, I share insights, strategies, and hands-on experiences to help others dive into the world of cyber offense. Join me as I navigate the complexities of cybersecurity on my journey to professional red teaming.