From 40b74704e78130ae9e525dbfc5bb697d69914fb9 Mon Sep 17 00:00:00 2001 From: Jamitz Date: Tue, 6 Jan 2026 12:51:40 +0000 Subject: [PATCH] Added docker support --- backend/Dockerfile | 13 ++++++++++++- compose.yaml | 40 ++++++++++++++++++++++++++++++++++++++++ frontend/Dockerfile | 15 +++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 compose.yaml create mode 100644 frontend/Dockerfile diff --git a/backend/Dockerfile b/backend/Dockerfile index 35429bc..449ba1d 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,10 +1,21 @@ +# backend/Dockerfile FROM python:3.11-slim +# 1️⃣ Set a deterministic working directory WORKDIR /app +# 2️⃣ Copy only the dependency list first – this lets Docker cache the layer COPY requirements.txt . + +# 3️⃣ Install Python deps (no cache to keep the image small) RUN pip install --no-cache-dir -r requirements.txt +# 4️⃣ Now copy the actual source code COPY ./app ./app -CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"] +# 5️⃣ Expose the port FastAPI will listen on (optional but nice for docs) +EXPOSE 8000 + +# 6️⃣ Run uvicorn with hot‑reload for local development. +# In production you’d drop the `--reload` flag. +CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"] diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..0b2d8f3 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,40 @@ +version: "3.9" + +services: + api: + build: + context: ./backend + ports: + - "8000:8000" + volumes: + - ./backend:/app # live‑code sync for reload + # env_file: .env # optional, keep secrets out of repo + # depends_on: + # - db # if you have a DB service + + ui: + build: + context: ./frontend + target: builder # use the builder stage for dev + command: npm run dev -- --host 0.0.0.0 --port 5173 + ports: + - "5173:5173" + volumes: + - ./frontend:/app + environment: + - VITE_API_URL=http://localhost:8000 + depends_on: + - api + + # Example DB (Postgres) – optional + # db: + # image: postgres:16-alpine + # environment: + # POSTGRES_USER: demo + # POSTGRES_PASSWORD: demo + # POSTGRES_DB: demo + # volumes: + # - pgdata:/var/lib/postgresql/data + +# volumes: +# pgdata: diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 0000000..0122e99 --- /dev/null +++ b/frontend/Dockerfile @@ -0,0 +1,15 @@ +# frontend/Dockerfile +FROM node:20-alpine AS builder + +WORKDIR /app +COPY package*.json ./ +RUN npm ci # clean install, respects lockfile + +COPY . . +RUN npm run build # produces ./dist + +# ---- Runtime image (optional) ---- +FROM nginx:stable-alpine +COPY --from=builder /app/dist /usr/share/nginx/html +EXPOSE 80 +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file