From 53f6125577a4886f99dcb82b5ef9027f827f57d7 Mon Sep 17 00:00:00 2001 From: anshjaiswal12 Date: Mon, 20 Apr 2026 04:50:19 +0530 Subject: [PATCH] Add Docker Compose setup for full-stack local development --- .dockerignore | 13 +++++++++++++ Dockerfile | 29 +++++++++++++++++++++++++++++ README.md | 19 +++++++++++++++++++ docker-compose.yml | 33 +++++++++++++++++++++++++++++++++ frontend/.dockerignore | 6 ++++++ frontend/Dockerfile | 17 +++++++++++++++++ frontend/vite.config.ts | 2 +- 7 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 frontend/.dockerignore create mode 100644 frontend/Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..f543577 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,13 @@ +venv +__pycache__ +*.pyc +*.pyo +.env +.git +.github +node_modules +dist +build +.pytest_cache +*.log +.DS_Store diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b180c7a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ +FROM python:3.10-slim + +WORKDIR /app + +# Install system dependencies +RUN apt-get update && apt-get install -y \ + build-essential \ + && rm -rf /var/lib/apt/lists/* + +# Copy requirements +COPY requirements.txt . + +# Install Python dependencies +RUN pip install --no-cache-dir -r requirements.txt + +# Copy source code +COPY . . + +# Install project in editable mode so climatevision module is available +RUN pip install -e . + +EXPOSE 8000 + +# Set environment variable to ensure python output is not buffered +ENV PYTHONUNBUFFERED=1 +ENV OMP_NUM_THREADS=1 + +# Run the FastAPI server +CMD ["uvicorn", "climatevision.api.main:app", "--host", "0.0.0.0", "--port", "8000"] diff --git a/README.md b/README.md index bafd9b8..708985d 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,25 @@ pip install -r requirements.txt ## Quickstart +### Docker Compose (Recommended) + +The easiest way to run the full stack is using Docker Compose: + +1. Copy the environment variables: + ```bash + cp .env.example .env + cp frontend/.env.example frontend/.env + ``` +2. Start the environment: + ```bash + docker-compose up -d --build # or docker compose up -d --build + ``` +3. Access the application: + - Frontend: [http://localhost:5173](http://localhost:5173) (or `http://localhost:3000`) + - Backend API Docs: [http://localhost:8000/docs](http://localhost:8000/docs) + +### Manual Setup + **Start the API server:** ```bash diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..0426fc0 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,33 @@ +version: "3.8" + +services: + backend: + build: + context: . + dockerfile: Dockerfile + ports: + - "8000:8000" + volumes: + - .:/app + environment: + - PYTHONUNBUFFERED=1 + env_file: + - .env + restart: unless-stopped + + frontend: + build: + context: ./frontend + dockerfile: Dockerfile + ports: + - "5173:5173" + # Expose on 3000 as well in case it's overridden + - "3000:3000" + volumes: + - ./frontend:/app + - /app/node_modules + environment: + - BACKEND_URL=http://backend:8000 + depends_on: + - backend + restart: unless-stopped diff --git a/frontend/.dockerignore b/frontend/.dockerignore new file mode 100644 index 0000000..a9d308a --- /dev/null +++ b/frontend/.dockerignore @@ -0,0 +1,6 @@ +node_modules +dist +build +.env +.DS_Store +*.log diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 0000000..37c83ac --- /dev/null +++ b/frontend/Dockerfile @@ -0,0 +1,17 @@ +FROM node:18-alpine + +WORKDIR /app + +# Copy package files +COPY package.json package-lock.json* ./ + +# Install dependencies +RUN npm install + +# Copy source code +COPY . . + +EXPOSE 5173 3000 + +# Run dev server and bind to all network interfaces +CMD ["npm", "run", "dev", "--", "--host", "0.0.0.0"] diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index fe50f31..25cef78 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -8,7 +8,7 @@ export default defineConfig({ strictPort: true, proxy: { '/api': { - target: 'http://127.0.0.1:8000', + target: process.env.BACKEND_URL || 'http://127.0.0.1:8000', changeOrigin: true, }, },