This project serves as a practical exercise to test your DevOps skills. It involves working with a sample e-commerce web application that allows users to browse and purchase kids' beds. Your task is to apply DevOps practices to containerize the application, set up CI/CD pipelines, and ensure proper validation and testing.
-
Fork the Repository
- Begin by forking this repository to your own GitHub account.
-
Ansible Automation (Same Local Machine)
- Use Ansible to automate app deployment and updates:
- Create ansible/ folder with
hostfile:[local]127.0.0.1 ansible_connection=local - install and verify basics tools for this repo e.g.
gitanddocker
- Create ansible/ folder with
- Use Ansible to automate app deployment and updates:
-
Clone and create a Separate Branch
- Clone and create a new branch named
devops-branchin your forked repository. This branch will be used for all your DevOps-related tasks.
- Clone and create a new branch named
-
Containerize the Application
- Write a
Dockerfileto containerize the e-commerce web application. Ensure that the Dockerfile is properly configured to build an image for the application. Apply best practices in Dockerfile creation, such as:- Minimizing the number of layers
- Using a small base image
- Caching dependencies effectively
- Cleaning up unnecessary files to reduce the image size
- Write a
-
Set Up Docker Compose
- Create a
docker-compose.ymlfile to deploy the application using Docker Compose. Although PostgreSQL is not used in this application, ensure that the Docker Compose setup is properly configured for the application container.
- Create a
-
Kubernetes (Local with Minikube or Kind)
- Deploy your app in a local Kubernetes cluster:
- Create:
- k8s/deployment.yaml
- k8s/service.yaml
- Start Minikube or Kind and apply:
- kubectl apply -f k8s/
- kubectl port-forward svc/ecommerce-service 8080:80
-
Deploy Using CI/CD Pipeline
- Use the
Dockerfileto deploy the application by setting up a CI/CD pipeline. This pipeline should be configured to run only for thedevops-branch, not for the master branch. - Optionally
- Create new branches named
compose-branchandk8s-branchin your forked repository. These branch will be used for all your docker compose and Kubernetes related tasks. - Use the
docker-compose.ymlto deploy the application by setting up a CI/CD pipeline. This pipeline should be configured to run only for thecompose-branch, not for the master branch. - Use the
deployment.yamlandservice.yamlto deploy the application by setting up a CI/CD pipeline. This pipeline should be configured to run only for thek8s-branch, not for the master branch.
- Create new branches named
- Use the
-
Validation and Testing
- Add necessary validation and testing in your CI/CD to confirm that the application runs correctly on a specific port. Ensure that all functionalities are working as expected and the deployment is stable.
-
Prometheus & Grafana Monitoring
- Monitor Docker containers and host system locally:
- Create monitoring/docker-compose.yml with:
- prometheus
- node_exporter
- grafana
Created an Ansible setup to automate the installation of Git and Docker on the local machine.
Files Created:
ansible/hosts- Inventory file for local connectionansible/setup.yml- Playbook to install and verify tools
Hosts file content:
[local]
127.0.0.1 ansible_connection=localCommands to run:
# Install Ansible (if not installed)
sudo apt install ansible
# Run the playbook
ansible-playbook -i ansible/hosts ansible/setup.yml
# Or run with verbose output
ansible-playbook -i ansible/hosts ansible/setup.yml -vThe playbook performs:
- Updates apt package cache
- Installs Git and verifies installation
- Installs Docker and verifies installation
Created a Dockerfile to containerize the e-commerce web application using Nginx Alpine (minimal image).
Dockerfile content:
FROM nginx:alpine
COPY . /usr/share/nginx/html/
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]Commands:
# Build the Docker image
docker build -t my-ecommerce-app .
# Run the container
docker run -d -p 8080:80 my-ecommerce-app
# Access the application at http://localhost:8080Created a docker-compose.yml file for easy deployment of the application.
docker-compose.yml content:
version: '3.8'
services:
app:
container_name: loving_wing
build: .
ports:
- "8080:80"
restart: alwaysCommands:
# Start the application
docker compose up -d --build
# View running containers
docker compose ps
# Stop the application
docker compose down
# View logs
docker compose logs -fCreated Kubernetes manifests for deploying the application in a local cluster (Minikube or Kind).
Files Created:
kubernetes/deployment.yml- Deployment with 2 replicaskubernetes/service.yml- Service to expose the application
Commands:
# Start Minikube (if using Minikube)
minikube start
# Build and load image (for Kind)
docker build -t my-ecommerce-app:latest .
kind load docker-image my-ecommerce-app:latest
# Apply Kubernetes manifests
kubectl apply -f kubernetes/
# Check pod status
kubectl get pods
# Check service status
kubectl get svc
# Port forward to access the application
kubectl port-forward svc/ecommerce-service 8080:80
# Access the application at http://localhost:8080Created three separate CI/CD pipelines for different deployment methods.
Files Created:
.github/workflows/docker-pipeline.yml- Runs ondevopsbranch.github/workflows/compose-pipeline.yml- Runs oncompose-branch.github/workflows/k8s-pipeline.yml- Runs onkubernetes-branch
Docker Pipeline (devops branch):
- Builds Docker image
- Runs container on port 8080
- Validates application is responding
Docker Compose Pipeline (compose-branch):
- Runs docker compose up
- Verifies containers are running
- Validates application on port 8080
Kubernetes Pipeline (kubernetes-branch):
- Creates Kind cluster
- Builds and loads image into cluster
- Deploys to Kubernetes
- Port forwards and validates on port 8081
Created monitoring setup using Prometheus for metrics collection and Grafana for visualization.
Files Created:
monitoring/monitoring-compose.yml- Docker Compose for monitoring stackmonitoring/prometheus.yml- Prometheus configuration
Services:
- Prometheus - Metrics collection (Port 9090)
- Node Exporter - Host metrics (Port 9100)
- Grafana - Visualization dashboard (Port 3001)
Commands:
# Navigate to monitoring directory
cd monitoring
# Start monitoring stack
docker compose -f monitoring-compose.yml up -d
# Access services:
# Prometheus: http://localhost:9090
# Grafana: http://localhost:3001 (admin/admin)
# Stop monitoring stack
docker compose -f monitoring-compose.yml downGrafana Setup:
- Login with admin/admin
- Add Prometheus data source: http://prometheus:9090
- Import Node Exporter dashboard (ID: 1860)