Automating Docker Tasks with Jenkins Freestyle Projects
Day 23 & 24: Jenkins Freestyle Project for DevOps Engineers
Introduction
Continuous Integration and Continuous Deployment (CI/CD) are integral practices in modern software development. In this comprehensive tutorial, we'll delve into the fundamentals of CI/CD, explore the concept of a build job, and master the creation of Jenkins Freestyle Projects to automate Docker tasks. Whether you're a novice or an experienced developer, this guide aims to demystify the process and empower you to streamline your development workflow effectively.
Understanding CI/CD ๐
CI/CD involves automating the process of integrating code changes and deploying applications. By continuously integrating new code and deploying it seamlessly, CI/CD promotes efficiency, reliability, and faster delivery of software.
What is a Build Job? ๐๏ธ
Jenkins Freestyle Projects provide a user-friendly and flexible approach to configuring build jobs. These projects allow developers to set up automation tasks without the need for extensive scripting, making them an ideal starting point for CI/CD beginners.
Exploring Freestyle Projects ๐จ
Jenkins Freestyle Projects are user-friendly and flexible, making them an excellent starting point for CI/CD beginners. These projects allow you to configure build jobs without needing extensive scripting.
For the tasks that follow, I have used the below projects:
Task-01: Building and Running Docker Containers ๐ณ
Step 1: Create an Agent for Your App ๐ต๏ธโโ๏ธ
In Jenkins, go to "Manage Jenkins" > "Manage Nodes and Clouds."
Click "New Node" to create a new agent. Give it a name, choose "Permanent Agent," and configure the necessary settings.
Step 2: Configure a Freestyle Project โ๏ธ
Create a new Freestyle Project and specify the agent you created as the execution environment.
Step 3: Add Build Steps ๐ ๏ธ
In the project configuration, navigate to the "Build" section.
Click on "Add build step" and choose "Execute shell" (for Unix-based systems) or "Execute Windows batch command" (for Windows).
For the "Command," enter
docker build -t your-app-image .
to build your Docker image.Add a second build step by clicking "Add build step" again. Choose "Execute shell" or "Execute Windows batch command," and enter
docker run -d -p 8001:8001 your-app-image
to run your Docker container.
Step 4: Save and Build ๐พ
Save your project configuration.
Trigger a build by clicking "Build Now" on the project dashboard.
Jenkins will now execute the specified build steps, creating a Docker image and running a container for your app.
Step 5: Manual Browser Testing ๐
Open your preferred web browser.
Navigate to
http://localhost:8080
to access your Todo App manually.
Task-02: Docker Compose Automation ๐ค
Step 1: Create a Jenkins Project ๐๏ธ
Create a new Freestyle Project following the steps above.
Step 2: Configure Build Steps โ๏ธ
Under the "Build" section, click "Add build step" and choose "Execute shell" or "Execute Windows batch command."
Enter the command
docker-compose -f path/to/your/docker-compose-file.yml up -d
to start multiple containers defined in your Docker Compose file.Add a cleanup step by clicking "Add build step" again. Choose "Execute shell" or "Execute Windows batch command," and enter
docker-compose -f path/to/your/docker-compose-file.yml down
to stop and remove containers.
Step 3: Save and Run ๐พ
Save your project configuration.
Trigger a build to see Jenkins automating the deployment of your Docker Compose application.
Step 4: Manual Browser Testing for Two-Tier Flask App ๐
Open your preferred web browser.
Navigate to
http://localhost:8080
to access your Two-Tier Flask App manually.
With these detailed steps, even beginners can successfully set up Jenkins Freestyle Projects for Docker automation. Remember, practice is key, so feel free to experiment with different configurations to enhance your CI/CD skills.
Happy Learning! ๐