This repository contains the main DevOps project with a coffee delivery service.
VCL Machines:
- VCL 1: 152.7.178.184 (Routing and DNS)
- VCL 2: 152.7.178.106 (Primary server with auto-deployment)
- VCL 3: 152.7.178.91 (Cold standby server with DB replication)
High Availability Features:
- ✅ Automatic deployment to VCL2 on merge to
mainbranch - ✅ Database replication from VCL2 to VCL3 every 2 minutes
- ✅ Auto-sync
devbranch after PR merge tomain - ✅ Linting and testing in CI/CD pipeline
Run the coffee project with PostgreSQL database using Docker:
cd coffee_project
docker-compose up -dThis starts:
- Coffee app on http://localhost:3000
- PostgreSQL database on port 5432
# Get available coffees
curl http://localhost:3000/coffees
# Place an order
curl -X POST http://localhost:3000/order \
-H "Content-Type: application/json" \
-d '{"coffeeId": 1, "quantity": 2}'docker-compose downAutomatic database replication runs every 2 minutes to keep VCL3 in sync with VCL2.
Setup on VCL2:
# Quick setup
cd ~/devops-project
chmod +x scripts/setup-replication.sh
./scripts/setup-replication.sh
# Follow the prompts to complete setupDetailed Documentation:
Monitor Replication:
# View replication logs
tail -f /var/log/coffee-replication/replicate.log
# Check replication status (if using systemd)
systemctl status coffee-replication.timerIf VCL2 fails, activate VCL3:
# On VCL3
cd ~/devops-project/coffee_project
docker-compose up -d
# Verify
curl http://localhost:3000/coffeesThen update DNS/routing on VCL1 to point traffic to VCL3.
This project uses PostgreSQL for the coffee_project service. The app reads the connection from the DATABASE_URL environment variable. If DATABASE_URL is not set, the project defaults to:
postgresql://postgres:postgres@localhost:5432/coffee_dev
Quick start (Docker)
- Start a local Postgres container:
docker run --name coffee-pg -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=coffee_dev -p 5432:5432 -d postgres:15- Install dependencies and run the migration to create tables and seed the coffee catalogue:
cd coffee_project
npm install
npm run migrate- Start the service:
npm start
# or run in a detached screen session:
screen -S coffee -dm sh -c 'npm start'Using an existing / hosted database
If you have a hosted Postgres instance, set DATABASE_URL before running the migrate script or starting the server:
export DATABASE_URL='postgresql://USER:PASSWORD@HOST:PORT/DBNAME'
npm run migrate
npm startCI (GitHub Actions) notes
If you run tests or migrations in GitHub Actions, start a Postgres service in the job and set DATABASE_URL to point to the service. Example snippet for a job in .github/workflows/*.yml:
services:
postgres:
image: postgres:15
env:
POSTGRES_DB: coffee_test
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports: ['5432:5432']
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/coffee_testCleanup
To stop and remove the local docker container:
docker stop coffee-pg && docker rm coffee-pgQuestions or different DB?
If you'd prefer a different database (MySQL, MongoDB, etc.) I can adapt the code and migration script — tell me which one and I'll implement the change.
The project uses GitHub Actions to automatically deploy to VCL 2 when code is merged to main.
- When a PR is merged to
main, the deployment workflow triggers - The workflow (running on the self-hosted runner on VCL 1) SSHs into VCL 2
- Pulls the latest code from the
mainbranch - Stops old Docker containers
- Rebuilds and starts new containers with the updated code
- The app becomes accessible at http://152.7.178.106:3000
On VCL 2 (152.7.178.106):
- Docker and Docker Compose installed
- Project cloned at
~/devops-project - SSH access configured for GitHub Actions
GitHub Repository Secrets (required):
VCL2_SSH_PRIVATE_KEY- SSH private key for accessing VCL 2VCL2_SSH_KNOWN_HOSTS- (optional) Host key for VCL 2
- Generate a dedicated SSH key pair:
ssh-keygen -t ed25519 -C "github-actions-deploy" -f ~/.ssh/github_actions_deploy_key- Copy the public key to VCL 2:
ssh-copy-id -i ~/.ssh/github_actions_deploy_key.pub [email protected]- Add the private key to GitHub Secrets:
# Copy the private key
cat ~/.ssh/github_actions_deploy_key
# Go to: Repository Settings → Secrets and variables → Actions
# Create secret: VCL2_SSH_PRIVATE_KEY
# Paste the entire private key content (including BEGIN/END lines)- (Optional) Add known hosts:
ssh-keyscan -H 152.7.178.106
# Add as secret: VCL2_SSH_KNOWN_HOSTSIf you need to deploy manually:
ssh [email protected]
cd ~/devops-project
git pull origin main
cd coffee_project
docker-compose down
docker-compose up -d --buildOnce deployed, the coffee delivery service is accessible at:
Test endpoints:
# Get available coffees
curl http://152.7.178.106:3000/coffees
# Place an order
curl -X POST http://152.7.178.106:3000/order \
-H "Content-Type: application/json" \
-d '{"coffeeId": 1, "quantity": 2}'
# View all orders
curl http://152.7.178.106:3000/orders