A Step-by-Step Guide to Your First DevOps Project: Automating a Simple Web Application Deployment
DevOps is the bridge between software development and IT operations, emphasizing collaboration, automation, and continuous improvement. For beginners, diving into DevOps can seem daunting. But don’t worry — this guide will walk you through a simple project to give you hands-on experience with basic DevOps concepts.
In this tutorial, you’ll learn how to:
- Set up a version control system using GitHub
- Use a CI/CD pipeline to automate deployments
- Deploy a simple web application using Docker and Jenkins
- Monitor and manage your application post-deployment
By the end, you’ll have a functional understanding of DevOps practices.
Step 1: Set Up Version Control with GitHub
Objective: Learn the basics of Git and GitHub by setting up a repository for your project.
Create a GitHub Account: If you don’t already have one, sign up for GitHub.
Create a New Repository:
Go to your GitHub dashboard.
- Click the “New” button to create a new repository.
- Name it
simple-web-app
. - Choose a license (MIT, for instance).
Initialize with a
README.md
file.Clone the Repository Locally:
- On your terminal, clone the repo to your local machine:
git clone https://github.com/your-username/simple-web-app.git
- Add a Basic HTML File:
- Create an
index.html
file with some basic HTML content:
<!DOCTYPE html>
<html>
<head>
<title>Simple Web App</title>
</head>
<body>
<h1>Hello, DevOps World!</h1>
</body>
</html>
- Commit and push the changes to GitHub:
git add .
git commit -m "Initial commit - added index.html"
git push origin main
Step 2: Containerize the Application with Docker
Objective: Learn the basics of Docker by containerizing your web application.
Install Docker: Follow the installation guide for Docker based on your OS.
Create a Dockerfile:
- Inside your project directory, create a
Dockerfile
:
FROM nginx:alpine
COPY ./index.html /usr/share/nginx/html/index.html
This will copy your
index.html
to the default NGINX directory inside the container.Build and Run the Docker Container:
- Build the Docker image:
docker build -t simple-web-app .
Run the container:
docker run -d -p 8080:80 simple-web-app
Open
http://localhost:8080
in your browser. You should see your “Hello, DevOps World!” message.Push Docker Image to Docker Hub:
- Create a Docker Hub account and log in.
- Tag and push your Docker image:
docker tag simple-web-app your-dockerhub-username/simple-web-app
docker push your-dockerhub-username/simple-web-app
Step 3: Set Up a CI/CD Pipeline with Jenkins
Objective: Automate the build and deployment of your Dockerized application using Jenkins.
Install Jenkins: Follow the official Jenkins installation guide for your platform.
Set Up Jenkins:
- Once Jenkins is up, install the “Docker” and “Git” plugins from the Jenkins dashboard.
- Create a new Jenkins job (Freestyle project) and configure it:
- Set up the Git repository by linking it to your GitHub repo.
- Add a “Build Step” to build the Docker image:
docker build -t simple-web-app .
docker tag simple-web-app your-dockerhub-username/simple-web-app
docker push your-dockerhub-username/simple-web-app
- Add another “Build Step” to run the Docker container:
docker run -d -p 8080:80 your-dockerhub-username/simple-web-app
- Trigger Build on Push:
- Install the “GitHub Integration Plugin” to set up a webhook.
- Configure GitHub to trigger a build in Jenkins whenever new code is pushed.
Step 4: Monitor Your Application
Objective: Set up basic monitoring to ensure your application is running smoothly.
- Install Prometheus and Grafana:
- Set up a Prometheus instance to scrape metrics from your Docker container.
Install Grafana for visualizing metrics.
Configure Alerts:
- Set up alerts in Prometheus to notify you via email or Slack if the application goes down.
Conclusion:
In this project, you’ve gone through the complete DevOps lifecycle for a simple web application. You’ve learned how to use Git for version control, Docker for containerization, Jenkins for CI/CD, and Prometheus and Grafana for monitoring. This is just the beginning — DevOps is a vast field, and as you continue, you’ll encounter more advanced tools and practices. Keep building and automating! Feel free to share your thoughts and experiences in the comments section below. Happy DevOps-ing!