Melika Kheirieh commited on
Commit
f188061
·
1 Parent(s): fec0f37

feat(docker): run FastAPI backend and Gradio UI together with healthcheck

Browse files
Files changed (1) hide show
  1. Dockerfile +18 -25
Dockerfile CHANGED
@@ -1,35 +1,28 @@
1
- # ---------- Stage 1: Builder ----------
2
- FROM python:3.12-slim AS builder
3
  WORKDIR /app
4
 
5
- # Install system deps (curl for healthcheck)
6
- RUN apt-get update && apt-get install -y --no-install-recommends curl \
7
- && rm -rf /var/lib/apt/lists/*
8
 
9
- # Install dependencies
10
  COPY requirements.txt .
11
- RUN pip install --upgrade pip \
12
- && pip install --no-cache-dir -r requirements.txt
 
13
 
14
- # ---------- Stage 2: Runtime ----------
15
- FROM python:3.12-slim AS runtime
16
- WORKDIR /app
17
-
18
- # Copy from builder
19
- COPY --from=builder /usr/local/lib/python3.12 /usr/local/lib/python3.12
20
- COPY --from=builder /usr/local/bin /usr/local/bin
21
-
22
- # Copy project files
23
  COPY . .
24
 
25
  # ---------- Metadata & Healthcheck ----------
26
- EXPOSE 7860
27
- HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
28
- CMD curl -f http://localhost:7860/ || exit 1
29
 
30
- # ---------- Run the App ----------
31
- # 👉 Gradio version
32
- # CMD ["python", "app.py"]
33
 
34
- # 👉 FastAPI version
35
- CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
 
 
1
+ # ---------- Base ----------
2
+ FROM python:3.12-slim
3
  WORKDIR /app
4
 
5
+ ENV PYTHONUNBUFFERED=1 \
6
+ PYTHONDONTWRITEBYTECODE=1 \
7
+ PIP_NO_CACHE_DIR=1
8
 
9
+ # ---------- Dependencies ----------
10
  COPY requirements.txt .
11
+ RUN apt-get update && apt-get install -y --no-install-recommends curl && \
12
+ pip install --no-cache-dir -r requirements.txt && \
13
+ rm -rf /var/lib/apt/lists/*
14
 
15
+ # ---------- Copy app ----------
 
 
 
 
 
 
 
 
16
  COPY . .
17
 
18
  # ---------- Metadata & Healthcheck ----------
19
+ LABEL org.opencontainers.image.title="nl2sql-copilot" \
20
+ org.opencontainers.image.description="NL2SQL Copilot full-stack demo (FastAPI + Gradio)" \
21
+ org.opencontainers.image.version="1.0.0"
22
 
23
+ HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
24
+ CMD curl -fs http://localhost:8000/healthz || exit 1
 
25
 
26
+ # ---------- Run both backend & frontend ----------
27
+ EXPOSE 7860 8000
28
+ CMD ["bash", "-c", "uvicorn main:app --host 0.0.0.0 --port 8000 & python app.py"]