A Step-by-Step Guide to Your First DevOps Project: Automating a Simple Web Application Deployment

Ophélie - Sep 9 - - Dev Community

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.

  1. Create a GitHub Account: If you don’t already have one, sign up for GitHub.

  2. 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.
  1. Clone the Repository Locally:
  2. On your terminal, clone the repo to your local machine:
git clone https://github.com/your-username/simple-web-app.git
Enter fullscreen mode Exit fullscreen mode
  1. Add a Basic HTML File:
  2. 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>
Enter fullscreen mode Exit fullscreen mode
  • Commit and push the changes to GitHub:
git add .
git commit -m "Initial commit - added index.html"
git push origin main
Enter fullscreen mode Exit fullscreen mode

Step 2: Containerize the Application with Docker

Objective: Learn the basics of Docker by containerizing your web application.

  1. Install Docker: Follow the installation guide for Docker based on your OS.

  2. Create a Dockerfile:

  3. Inside your project directory, create a Dockerfile:

FROM nginx:alpine
COPY ./index.html /usr/share/nginx/html/index.html
Enter fullscreen mode Exit fullscreen mode
  • This will copy your index.html to the default NGINX directory inside the container.
  1. Build and Run the Docker Container:

- Build the Docker image:

docker build -t simple-web-app .
Enter fullscreen mode Exit fullscreen mode
  • Run the container:
docker run -d -p 8080:80 simple-web-app
Enter fullscreen mode Exit fullscreen mode
  • Open http://localhost:8080 in your browser. You should see your “Hello, DevOps World!” message.
  1. Push Docker Image to Docker Hub:
  2. Create a Docker Hub account and log in.
  3. 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
Enter fullscreen mode Exit fullscreen mode

Step 3: Set Up a CI/CD Pipeline with Jenkins

Objective: Automate the build and deployment of your Dockerized application using Jenkins.

  1. Install Jenkins: Follow the official Jenkins installation guide for your platform.

  2. Set Up Jenkins:

  3. Once Jenkins is up, install the “Docker” and “Git” plugins from the Jenkins dashboard.

  4. Create a new Jenkins job (Freestyle project) and configure it:

  5. Set up the Git repository by linking it to your GitHub repo.

  6. 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
Enter fullscreen mode Exit fullscreen mode
  • Add another “Build Step” to run the Docker container:
docker run -d -p 8080:80 your-dockerhub-username/simple-web-app
Enter fullscreen mode Exit fullscreen mode
  1. Trigger Build on Push:
  2. Install the “GitHub Integration Plugin” to set up a webhook.
  3. 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.

  1. Install Prometheus and Grafana:
  2. Set up a Prometheus instance to scrape metrics from your Docker container.
  3. Install Grafana for visualizing metrics.

  4. Configure Alerts:

  5. 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!

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player