A comprehensive microservice application with automated CI/CD deployment using GitHub Actions, Docker, Ansible, and Jenkins integration. this is the read me file
- ποΈ Architecture
- π§ Prerequisites
- βοΈ Setup & Configuration
- π GitHub Actions Workflows
- οΏ½ Jenkins Integration
- οΏ½π¦ Docker Images & Registry
- π― Ansible Deployment
- π Monitoring & Troubleshooting
- π Access Points
- π Additional Resources
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Frontend β β Backend β β Database β
β (Nginx) β β (Flask) β β (MySQL) β
β Port: 8080 ββββββ Port: 5000 ββββββ Port: 3306 β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
- Frontend: Nginx-based web interface (Port 8081)
- Backend: Flask API server (Port 5001)
- Database: MySQL database (Port 3306)
βββββββββββββββ βββββββββββββββ βββββββββββββββ βββββββββββββββ
β GitHub β β GitHub β β Ansible β β AWS EC2 β
β Repositoryββββββ Actions ββββββ Deployment ββββββ Server β
β β β Workflow β β β β54.234.122.255β
βββββββββββββββ βββββββββββββββ βββββββββββββββ βββββββββββββββ
- Frontend: Nginx-based web interface serving admin panel
- Backend: Flask REST API with authentication and admin features
- Database: MySQL with persistent data storage
- Registry: GitHub Container Registry (GHCR) for image storage
- Deployment: Automated via Ansible on AWS EC2
# Required Software
- Docker 20.10+
- Docker Compose 2.0+
- Git 2.30+
- Python 3.8+
- Node.js 16+ (optional)
# System Requirements
- 8GB RAM minimum
- 20GB free disk space
- Ubuntu 20.04+ or macOS 10.15+# AWS EC2 Instance
- Ubuntu 24.04 LTS
- t2.medium or larger
- Security Groups: SSH (22), HTTP (80), Custom (8080, 5000)
- Elastic IP (recommended)
# GitHub Repository
- Actions enabled
- Container Registry access
- Secrets configured# Generate SSH key pair (if needed)
ssh-keygen -t rsa -b 4096 -f ~/.ssh/aws-microservice-key
# Copy public key to EC2 instance
ssh-copy-id -i ~/.ssh/aws-microservice-key.pub [email protected]
# Test connection
ssh -i ~/.ssh/aws-microservice-key [email protected]-
Get your private key content:
cat ~/.ssh/aws-microservice-key -
Add to GitHub Secrets:
- Go to Repository β Settings β Secrets and variables β Actions
- Click "New repository secret"
- Name:
SSH_PRIVATE_KEY - Value: (paste entire private key including BEGIN/END lines)
# Clone repository
git clone https://github.com/shivamsingh163248/Microservice-admin-apps.git
cd Microservice-admin-apps
# Build and run locally
docker-compose up -d
# Access services
curl http://localhost:8080 # Frontend
curl http://localhost:5000 # Backend API# Pull from GitHub Container Registry
docker pull ghcr.io/shivamsingh163248/flask_backend:latest
docker pull ghcr.io/shivamsingh163248/nginx_frontend:latest
docker pull ghcr.io/shivamsingh163248/mysql_db:latestAdd these secrets to your GitHub repository:
| Secret Name | Description | Example Value |
|---|---|---|
SSH_PRIVATE_KEY |
AWS EC2 SSH private key | -----BEGIN RSA PRIVATE KEY-----... |
GITHUB_TOKEN |
GitHub personal access token | ghp_xxxxxxxxxxxx |
GHCR_TOKEN |
GitHub Container Registry token | ghp_xxxxxxxxxxxx |
AWS_SERVER_IP |
Production server IP | 54.234.122.255 |
.github/workflows/
βββ docker-build-push.yml # Docker Hub deployment
βββ github-packages.yml # GitHub Packages deployment
βββ ansible-deploy.yml # Full CI/CD with Ansible
on:
push:
branches: [ Ansible_Workflow ]
workflow_dispatch:
inputs:
environment:
description: 'Target environment'
required: true
default: 'production'build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout code
- name: Set up Docker Buildx
- name: Login to GitHub Container Registry
- name: Build and push Docker images
- name: Update compose files with new versions
- name: Commit updated filesdeploy-with-ansible:
needs: build-and-push
runs-on: ubuntu-latest
steps:
- name: Setup SSH connection
- name: Install Ansible
- name: Run Ansible playbook
- name: Verify deployment health- Trigger: Push to
Ansible_Workflowbranch - Build: Create Docker images with version
v1.0.${{ github.run_number }} - Push: Upload images to GitHub Container Registry
- Update: Modify docker-compose files with new image versions
- Deploy: Use Ansible to deploy to AWS EC2 server
- Verify: Check application health and accessibility
For comprehensive Jenkins setup, see PULLING.md which includes:
- Freestyle Projects: Step-by-step configuration
- Pipeline Scripts: Complete Groovy pipeline
- Docker Integration: Build, push, and deploy images
- GitHub Integration: Webhook triggers and SCM polling
- Multi-environment: Dev, staging, and production deployments
pipeline {
agent any
environment {
REGISTRY = 'ghcr.io'
OWNER = 'shivamsingh163248'
BUILD_VERSION = "v1.0.${BUILD_NUMBER}"
}
stages {
stage('Build') {
steps {
sh 'docker build -t $REGISTRY/$OWNER/flask_backend:$BUILD_VERSION backend/'
}
}
stage('Deploy') {
steps {
sh 'ansible-playbook ansible/deploy-production.yml'
}
}
}
}GitHub Container Registry (ghcr.io/shivamsingh163248/)
βββ flask_backend:latest
βββ flask_backend:v1.0.X
βββ nginx_frontend:latest
βββ nginx_frontend:v1.0.X
βββ mysql_db:latest
βββ mysql_db:v1.0.X
# Base: python:3.9-slim
# Port: 5000
# Features:
# - REST API endpoints
# - MySQL database integration
# - Authentication system
# - Admin panel API# Base: nginx:alpine
# Port: 80 (mapped to 8080)
# Features:
# - Static file serving
# - Admin interface
# - Reverse proxy to backend
# - Responsive design# Base: mysql:8.0
# Port: 3306
# Features:
# - Persistent data storage
# - Admin user management
# - Database initialization scripts
# - Backup and recovery support1. System Setup β 2. Docker Installation β 3. User Configuration β 4. App Deployment β 5. Health Check
- Automated Docker Compose installation
- SSH connection reset for permissions
- GitHub Container Registry integration
- Health verification and monitoring
- Error handling and recovery
- Frontend: http://54.234.122.255:8080
- Backend: http://54.234.122.255:5000/health
- Database: Connection via backend API
- SSH Permission Denied: Check SSH key format in GitHub Secrets
- Docker Permission Error: Reset SSH connection after docker group addition
- Image Pull Failed: Verify GitHub Container Registry authentication
- Deployment Timeout: Check server resources and network connectivity
- Application URL: http://54.234.122.255:8080
- API Endpoint: http://54.234.122.255:5000
- Admin Credentials: admin/admin123
- Local Frontend: http://localhost:8080
- Local Backend: http://localhost:5000
- Local Database: localhost:3306
- PULLING.md: Complete Jenkins CI/CD integration guide
- SSH_KEY_SETUP_GUIDE.md: SSH key configuration
- DEPLOYMENT_TROUBLESHOOTING.md: Troubleshooting guide
git clone https://github.com/shivamsingh163248/Microservice-admin-apps.git
cd Microservice-admin-apps
docker-compose up -d# Push to trigger deployment
git push origin Ansible_Workflow
# Monitor progress
# GitHub β Actions β View workflow run
# Verify deployment
curl http://54.234.122.255:8080- Clone repository
- Configure GitHub Secrets (SSH_PRIVATE_KEY, GITHUB_TOKEN)
- Update inventory.ini with your server IP
- Push to Ansible_Workflow branch
- Monitor GitHub Actions workflow
- Verify application at http://your-server-ip:8080
- Check troubleshooting guides if issues occur
- Fork the repository
- Create feature branch:
git checkout -b feature/new-feature - Commit changes:
git commit -am 'Add new feature' - Push to branch:
git push origin feature/new-feature - Create Pull Request
This project is licensed under the MIT License.
- Issues: GitHub Issues
- Email: [email protected]
Last Updated: August 30, 2025
Version: 2.0
Maintainer: DevOps Team
Happy Deploying! π
#### Add Public Key to EC2
1. Copy public key content:
```bash
cat ~/.ssh/aws-microservice-key.pub
- Add to EC2 instance:
~/.ssh/authorized_keys
Go to Repository β Settings β Secrets and variables β Actions
Add the following secrets:
SSH_PRIVATE_KEY: [Your complete private key content]
Private Key Format:
-----BEGIN RSA PRIVATE KEY-----
[Your key content here]
-----END RSA PRIVATE KEY-----
Edit ansible/inventory.ini:
[webservers]
production ansible_host=YOUR_EC2_IP ansible_user=ubuntu
[webservers:vars]
ansible_python_interpreter=/usr/bin/python3
docker_compose_version=v2.21.0
ansible_ssh_common_args='-o StrictHostKeyChecking=no'Ensure these ports are open:
- Port 22: SSH access
- Port 8081: Frontend application
- Port 5001: Backend API (optional)
The repository includes three main workflows:
.github/workflows/docker-build-push.yml- Docker Hub deployment.github/workflows/github-packages.yml- GitHub Packages deployment.github/workflows/ansible-deploy.yml- Main production deployment
Push to the Ansible_Workflow branch:
git checkout Ansible_Workflow
git add .
git commit -m "Deploy new version"
git push origin Ansible_Workflow-
Build Job (2-3 minutes):
β Checkout code β Build Docker images β Push to GitHub Container Registry β Update docker-compose files β Commit version updates -
Deploy Job (3-5 minutes):
β Setup SSH connection β Install Ansible β Configure target server β Install Docker & Docker Compose β Deploy microservices β Verify deployment health
Each deployment gets an automatic version tag:
- Format:
v1.0.{BUILD_NUMBER} - Example:
v1.0.15for build #15
cd ansible
ansible-playbook -i inventory.ini deploy-production.yml# Development
docker-compose up -d
# Production
docker-compose -f docker-compose.production.yml up -dAll images are stored in GitHub Container Registry:
- Registry:
ghcr.io/shivamsingh163248 - Images:
flask_backend:v1.0.Xnginx_frontend:v1.0.Xmysql_db:v1.0.X
# Automatic versioning in GitHub Actions
IMAGE_VERSION: v1.0.${{ github.run_number }}# Build images locally
docker build -t microservice-backend ./backend
docker build -t microservice-frontend ./frontend
docker build -t microservice-database ./database
# Push to registry
docker tag microservice-backend ghcr.io/shivamsingh163248/flask_backend:latest
docker push ghcr.io/shivamsingh163248/flask_backend:latestMonitor deployment in GitHub Actions:
- Go to repository β Actions tab
- Look for "Build, Push, and Deploy Microservices"
- Check both build and deploy job status
# Test SSH connection manually
ssh -i your-key.pem ubuntu@YOUR_EC2_IP
# Check GitHub secret format
# Ensure SSH_PRIVATE_KEY includes full key with headers# On EC2 instance
sudo usermod -aG docker ubuntu
# Then logout/login or restart SSH session# Check running containers
docker ps
# Check logs
docker-compose logs backend
docker-compose logs frontend
docker-compose logs database
# Check service status
curl http://YOUR_EC2_IP:8081 # Frontend
curl http://YOUR_EC2_IP:5001/health # Backend APIAccess logs on the server:
# Application logs
cd /opt/microservice-admin-app
docker-compose logs -f
# System logs
sudo journalctl -u docker- π
DEPLOYMENT_TROUBLESHOOTING.md- Common deployment issues - π
SSH_KEY_SETUP_GUIDE.md- SSH configuration guide
- Frontend: http://YOUR_EC2_IP:8081
- Backend API: http://YOUR_EC2_IP:5001
- Health Check: http://YOUR_EC2_IP:5001/health
# Start local development
docker-compose up -d
# Access points
# Frontend: http://localhost:8081
# Backend: http://localhost:5001
# Database: localhost:3306- Admin Dashboard: User management interface
- Authentication: Login/register functionality
- Database Management: MySQL with persistent storage
- API Endpoints: RESTful backend services
main: Stable production codeAnsible_Workflow: Deployment branch (triggers CI/CD)Ansible_GithubAction_Workflow: Default branch
# Development work
git checkout main
git pull origin main
# Make changes
git checkout -b feature/new-feature
# Commit changes
# Deploy to production
git checkout Ansible_Workflow
git merge main
git push origin Ansible_Workflow # Triggers deploymentTrack deployment metrics:
- Build success rate
- Deployment frequency
- Average deployment time
- Failed deployment alerts
# Resource usage
docker stats
# Disk usage
df -h
# Memory usage
free -h
# Process monitoring
htop# Option 1: Revert to previous version
git revert HEAD
git push origin Ansible_Workflow
# Option 2: Manual rollback on server
cd /opt/microservice-admin-app
docker-compose down
# Edit docker-compose.production.yml with previous version
docker-compose up -d# Restart all services
docker-compose restart
# Full cleanup and redeploy
docker-compose down
docker system prune -a
# Trigger new deployment from GitHub- Fork the repository
- Create feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
For issues and questions:
- Check DEPLOYMENT_TROUBLESHOOTING.md
- Review GitHub Actions logs
- Check server logs:
docker-compose logs - Create GitHub issue with error details
π Happy Deploying! π