Skip to content
Β 
Β 

Latest commit

Β 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Multi-Environment Ticket Management Application

Complete Dockerized Deployment (Dev Backend + Prod Backend + React Frontend + MongoDB)

This project demonstrates a complete multi-environment application deployment featuring:

  • Dev Backend (Flask)
  • Prod Backend (Flask + Gunicorn)
  • Frontend (React)
  • MongoDB Database
  • Docker & Docker Compose Multi-Service Orchestration
  • Networking, Environment Handling & Service Communication

This repository fulfills the Multi-Environment Deployment Assessment requirements and includes complete troubleshooting notes.


πŸ“Œ Features

Backend (Dev)

  • Flask development server
  • Auto-reload
  • Accessible at: http://localhost:3001

Backend (Prod)

  • Flask app served using Gunicorn
  • Optimized for production
  • Accessible at: http://localhost:3002

Frontend

  • React application
  • Communicates with both dev & prod backends
  • Accessible at: http://localhost:3005

Database

  • MongoDB running as a dedicated container
  • Shared across dev and prod environments

Health Endpoints

Both environments include:

GET /health β†’ {"status":"ok"}


πŸ—‚ Folder Structure

multienv_deployment_DEEPIKA_NARENDRAN/ β”œβ”€β”€ backend β”‚ β”œβ”€β”€ dev β”‚ β”‚ β”œβ”€β”€ app.py β”‚ β”‚ β”œβ”€β”€ Dockerfile β”‚ β”‚ β”œβ”€β”€ requirements.txt β”‚ β”‚ └── templates β”‚ β”‚ └── index.html β”‚ └── prod β”‚ β”œβ”€β”€ app.py β”‚ β”œβ”€β”€ Dockerfile β”‚ β”œβ”€β”€ requirements.txt β”‚ └── templates β”‚ └── index.html β”œβ”€β”€ docker-compose.yml β”œβ”€β”€ frontend β”‚ β”œβ”€β”€ Dockerfile β”‚ β”œβ”€β”€ package.json β”‚ β”œβ”€β”€ public β”‚ β”‚ β”œβ”€β”€ favicon.ico β”‚ β”‚ β”œβ”€β”€ index.html β”‚ β”‚ β”œβ”€β”€ logo192.png β”‚ β”‚ β”œβ”€β”€ logo512.png β”‚ β”‚ β”œβ”€β”€ manifest.json β”‚ β”‚ └── robots.txt β”‚ β”œβ”€β”€ README.md β”‚ └── src β”‚ β”œβ”€β”€ App.css β”‚ β”œβ”€β”€ App.js β”‚ β”œβ”€β”€ App.test.js β”‚ β”œβ”€β”€ index.css β”‚ β”œβ”€β”€ index.js β”‚ β”œβ”€β”€ logo.svg β”‚ β”œβ”€β”€ pages β”‚ β”‚ β”œβ”€β”€ Home.css β”‚ β”‚ β”œβ”€β”€ Home.js β”‚ β”‚ β”œβ”€β”€ Tickets.css β”‚ β”‚ └── Tickets.js β”‚ └── setupTests.js β”œβ”€β”€ LICENSE β”œβ”€β”€ README.md └── submission └── submission-info.txt

🧩 System Architecture

Screenshot from 2025-11-15 22-41-47

βš™οΈ Prerequisites

Ensure your machine has:

  • Docker β‰₯ 20.x
  • Docker Compose β‰₯ v2.x
  • (Optional) Python 3.11+ for local testing

πŸš€ Deployment Steps

1️⃣ Clone the Repository

git clone https://github.com/YOUR-USERNAME/MultienvApp.git cd MultienvApp

Screenshot from 2025-11-13 23-35-06 Screenshot from 2025-11-13 23-35-06

2️⃣ 🌩 MongoDB Atlas Configuration

You are using MongoDB Atlas instead of a local Mongo container.

βœ” Step 1 --- Create MongoDB Atlas Cluster

  1. Go to https://cloud.mongodb.com
  2. Create a free/shared cluster
  3. Create a new database user
  4. Assign password
  5. Copy your connection string:

mongodb+srv://<username>:<password>@<cluster>.mongodb.net/


βœ” Step 2 --- Allow Network Access

Go to Network Access β†’ Add IP:

For development:

0.0.0.0/0 (Allow all)

image

Or more secure:

<Your IP>/32


βœ” Step 3 --- Create databases

Dev DB:

multienv_dev

Prod DB:

multienv_prod

(Atlas auto-creates databases on the first write.)


πŸ” Environment Variables (.env)

Important: DO NOT COMMIT .env FILES

Add to .gitignore:

backend/*/.env


backend/dev/.env

FLASK_DEBUG=1 PORT=3001 MONGO_URI="mongodb+srv://<username>:<password>@<cluster>.mongodb.net/multienv_dev?retryWrites=true&w=majority&appName=MultiEnvApp"

backend/prod/.env

FLASK_DEBUG=0 PORT=3002 MONGO_URI="mongodb+srv://<username>:<password>@<cluster>.mongodb.net/multienv_prod?retryWrites=true&w=majority&appName=MultiEnvApp"

image image

3️⃣ Build and Start All Services

docker compose up --build -d


4️⃣ Verify Running Containers

docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"

Expected:

multienv_dev_backend Up 0.0.0.0:3001->3001/tcp multienv_prod_backend Up 0.0.0.0:3002->3002/tcp multienv_frontend Up 0.0.0.0:3005->3000/tcp multienv_mongo Up 0.0.0.0:27017->27017/tcp

Screenshot from 2025-11-13 23-39-11 Screenshot from 2025-11-14 01-04-41

5️⃣ Test Application

Backend Health Checks

curl http://localhost:3001/health

Screenshot from 2025-11-15 23-47-57

curl http://localhost:3002/health

Screenshot from 2025-11-15 23-47-39

Frontend

Open in browser:

http://localhost:3005

Screenshot from 2025-11-14 00-10-16

Dev View

http://localhost:3005/dev

Screenshot from 2025-11-14 00-10-27

Prod View

http://localhost:3005/prod

Screenshot from 2025-11-14 00-10-38

πŸ› οΈ Full Troubleshooting Guide

(All real issues encountered during this deployment)


❌ Issue 1: Port 3000 already in use

Error:

bind: address already in use

βœ” Fix:

Changed frontend host port to 3005 in docker-compose.yml:

`ports:

  • "3005:3000"`

❌ Issue 2: Backend cannot connect to MongoDB

Mongo logs showed:

Client sent an HTTP request over a native MongoDB connection

This happened because curl http://localhost:27017 was used --- MongoDB uses binary protocol.

βœ” Fix:

Correct mongo connectivity testing:

docker run --rm -it --network multienvapp_multinet mongo:6.0 mongosh "mongodb://mongo:27017" --eval 'db.runCommand({ ping: 1 })'

Result:

{ ok: 1 }


❌ Issue 3: Backend crashed: missing MONGO_URI

ValueError: You must specify a URI or set the MONGO_URI

βœ” Fix:

Added .env files with MONGO_URI Ensured env_file: is configured for each backend service.

docker run --rm -it --network multienvapp_multinet mongo:6.0 mongosh --host mongo --eval 'db.runCommand({ ping: 1 })' { ok: 1 }


❌ Issue 4: Production backend failed to start --- gunicorn not found

exec: "gunicorn": executable file not found in $PATH

βœ” Fix:

Added gunicorn to backend/prod/requirements.txt:

gunicorn>=20.1.0

Rebuild:

docker compose build prod-backend


❌ Issue 5: 404 on /health

Backends had no /health endpoint.

βœ” Fix:

Added this route:

@app.route("/health") def health(): return jsonify({"status": "ok"}), 200


❌ Issue 6: Pylance warning --- mongo.db might be None

OptionalMemberAccess

βœ” Fix:

Added:

assert mongo.db is not None

Or:

# type: ignore


πŸ§ͺ Final Verification Checklist

Component Status Test
MongoDB βœ… running { ok: 1 }
Dev Backend βœ… running curl /health
Prod Backend βœ… running curl /health
Frontend βœ… running http://localhost:3005
API Communication βœ… working Frontend β†’ Backends β†’ Mongo
Data Persistence βœ… working add/complete/delete todos

image image image image
Screenshot from 2025-11-15 22-01-55
Screenshot from 2025-11-15 22-28-15

Deploying to Docker Hub (Recommended Method)

To deploy images professionally, use:

βœ” 1. Build images

βœ” 2. Tag images

βœ” 3. Push to Docker Hub

image
image image
image

A fully functioning multi-environment Dockerized application backed by MongoDB Atlas, with professional-grade documentation and troubleshooting.


πŸ“Œ Author

DEEPIKA NARENDRAN Project: Multi-Environment Ticket Management Application

GitHub: @JoinDeeHub

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages