From 748e048d4f7106689c997f4508e4cb20ce7079a6 Mon Sep 17 00:00:00 2001 From: ujain1999 <43496188+ujain1999@users.noreply.github.com> Date: Sat, 28 Mar 2026 03:00:52 +0530 Subject: [PATCH 1/2] Dockerize --- nginx/nginx.conf | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 nginx/nginx.conf diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 0000000..5d45c2d --- /dev/null +++ b/nginx/nginx.conf @@ -0,0 +1,29 @@ +server { + listen 80; + root /usr/share/nginx/html; + index index.html; + + location / { + try_files $uri $uri/ /index.html; + } + + location /api/ { + proxy_pass http://backend:8000/; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_cache_bypass $http_upgrade; + } + + location /ws/ { + rewrite ^/ws(/.*)$ $1 break; + proxy_pass http://backend:8000; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + } +} From 239219fcb16338c1d6ff415ff3af4cb7c248f96f Mon Sep 17 00:00:00 2001 From: ujain1999 <43496188+ujain1999@users.noreply.github.com> Date: Sat, 28 Mar 2026 03:02:51 +0530 Subject: [PATCH 2/2] Add Dockerfile and docker-compose --- .env.docker | 2 ++ Dockerfile | 22 +++++++++++++++++++++ backend/Dockerfile | 14 +++++++++++++ docker-compose.yml | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 87 insertions(+) create mode 100644 .env.docker create mode 100644 Dockerfile create mode 100644 backend/Dockerfile create mode 100644 docker-compose.yml diff --git a/.env.docker b/.env.docker new file mode 100644 index 0000000..246f6c5 --- /dev/null +++ b/.env.docker @@ -0,0 +1,2 @@ +VITE_API_URL=/api +VITE_WS_URL=/ws diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ffeeaa6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM node:20-alpine AS builder + +WORKDIR /app + +COPY package*.json ./ +RUN npm ci + +COPY . . + +# Use Docker environment variables +RUN cp .env.docker .env || true + +RUN npm run build + +FROM nginx:alpine + +COPY --from=builder /app/dist /usr/share/nginx/html +COPY nginx/nginx.conf /etc/nginx/conf.d/default.conf + +EXPOSE 80 + +CMD ["nginx", "-g", "daemon off;"] diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 0000000..00bb9b1 --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,14 @@ +FROM python:3.14-slim + +WORKDIR /app + +RUN pip install uv + +COPY pyproject.toml uv.lock ./ +RUN uv sync --no-dev + +COPY . . + +EXPOSE 8000 + +CMD ["uv", "run", "python", "main.py"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..7bf6635 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,49 @@ +version: '3.8' + +services: + db: + image: postgres:14-alpine + environment: + POSTGRES_USER: crowdsource_dj + POSTGRES_PASSWORD: crowdsource_dj + POSTGRES_DB: crowdsource_dj + volumes: + - postgres_data:/var/lib/postgresql/data + ports: + - "5432:5432" + healthcheck: + test: ["CMD-SHELL", "pg_isready -U crowdsource_dj"] + interval: 5s + timeout: 5s + retries: 5 + + backend: + build: + context: ./backend + dockerfile: Dockerfile + ports: + - "8000:8000" + environment: + DATABASE_URL: postgresql://crowdsource_dj:crowdsource_dj@db:5432/crowdsource_dj + SECRET_KEY: dev-secret-key-change-in-production + ALGORITHM: HS256 + ACCESS_TOKEN_EXPIRE_MINUTES: 30 + HOST: 0.0.0.0 + PORT: 8000 + DEBUG: "true" + ALLOWED_ORIGINS: '["http://localhost", "http://localhost:80"]' + depends_on: + db: + condition: service_healthy + + frontend: + build: + context: . + dockerfile: Dockerfile + ports: + - "80:80" + depends_on: + - backend + +volumes: + postgres_data: