Skip to content

ThanhTamSys/cloud_migration_3tier_app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚀 Cloud Migration & 3-Tier Web Application

Build & Validate CI

A complete 3-Tier web application architecture containerized with Docker Compose, plus a one-command automated deployment script (deploy.sh) for migrating to a production Linux cloud server (GCP, AWS, Azure, DigitalOcean).

Portfolio goal: Demonstrate cloud migration skills, Docker networking, multi-tier architecture design, and CI/CD-ready deployment automation.


🌟 Architecture Overview

Internet
    │
    ▼
┌─────────────────────────────────────────┐
│  Tier 1: Nginx (Reverse Proxy)          │
│  Port 80 — serves static files +        │
│  proxies /api/* → Flask                 │
└──────────────────┬──────────────────────┘
                   │
                   ▼
┌─────────────────────────────────────────┐
│  Tier 2: Flask Application Server       │
│  Port 5000 (internal) — REST API        │
│  Connects to PostgreSQL via SQLAlchemy  │
└──────────────────┬──────────────────────┘
                   │
                   ▼
┌─────────────────────────────────────────┐
│  Tier 3: PostgreSQL Database            │
│  Port 5432 (internal only)              │
│  Persistent volume — survives restarts  │
└─────────────────────────────────────────┘

🛠️ Requirements

Local development:

Cloud deployment:

  • A Linux VPS (Ubuntu 20.04+) with SSH access
  • SSH key pair configured

🚀 Quick Start (Local)

# 1. Copy environment template
cp .env.example .env

# 2. Start all 3 tiers
docker compose up -d --build

# 3. Access the application
# Frontend: http://localhost
# API Health: http://localhost/api/health
# API Items:  http://localhost/api/items

☁️ One-Command Cloud Deployment

chmod +x deploy.sh
./deploy.sh <YOUR_SERVER_IP> <SSH_USER>

# Example:
./deploy.sh 34.126.120.50 ubuntu

What deploy.sh does automatically:

  1. rsync — copies project files to the remote server
  2. Installs Docker if not already present
  3. Runs docker compose up -d --build on the server
  4. Performs HTTP health check on /api/health
  5. Reports success or failure with the public URL

📡 API Endpoints

Method Endpoint Description
GET / Nginx-served frontend landing page
GET /api/health Health check — returns {"status": "ok"}
GET /api/items List all items from PostgreSQL
POST /api/items Create a new item {"name": "..."}

📁 Project Structure

16_cloud_migration_3tier_app/
├── .github/workflows/ci.yml    # Build validation CI
├── app/
│   ├── app.py                  # Flask API server
│   ├── requirements.txt
│   └── Dockerfile
├── nginx/
│   ├── nginx.conf              # Reverse proxy config
│   └── html/
│       └── index.html          # Landing page
├── db/
│   └── init.sql                # PostgreSQL schema + seed
├── docker-compose.yml          # 3-tier orchestration
├── deploy.sh                   # One-command cloud deploy
├── .env.example                # Environment variables template
└── README_VI.md                # Vietnamese documentation

⚙️ Environment Variables

cp .env.example .env
Variable Default Description
POSTGRES_DB appdb Database name
POSTGRES_USER appuser DB username
POSTGRES_PASSWORD (set in .env) DB password — never hardcode
FLASK_ENV production Flask environment

🔒 Security Notes

  • Database credentials are loaded via .env — never committed to Git
  • Database port (5432) is not exposed externally — internal Docker network only
  • Nginx acts as the only public-facing entry point

About

3-tier web app (Nginx→Flask→PostgreSQL) with one-command cloud deploy script for GCP/AWS/DO.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages