Spaces:
Sleeping
Sleeping
Melika Kheirieh
commited on
Commit
·
c21b5e2
1
Parent(s):
260d5c1
ops(docker): add stdlib healthcheck, OCI labels, and .dockerignore
Browse files- Dockerfile +16 -8
Dockerfile
CHANGED
|
@@ -8,7 +8,7 @@ ENV PIP_NO_CACHE_DIR=1 \
|
|
| 8 |
WORKDIR /build
|
| 9 |
|
| 10 |
# If you truly need to compile deps, keep build-essential.
|
| 11 |
-
# If you use psycopg[binary], you can
|
| 12 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 13 |
build-essential \
|
| 14 |
&& rm -rf /var/lib/apt/lists/*
|
|
@@ -26,7 +26,8 @@ FROM python:3.12-slim AS runtime
|
|
| 26 |
|
| 27 |
ENV PIP_NO_CACHE_DIR=1 \
|
| 28 |
PYTHONDONTWRITEBYTECODE=1 \
|
| 29 |
-
PYTHONUNBUFFERED=1
|
|
|
|
| 30 |
|
| 31 |
WORKDIR /app
|
| 32 |
|
|
@@ -44,10 +45,17 @@ RUN pip install --no-cache-dir --find-links=/wheels -r requirements.txt && \
|
|
| 44 |
# Copy the actual application code
|
| 45 |
COPY . .
|
| 46 |
|
| 47 |
-
#
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
# Drop privileges
|
| 53 |
USER appuser
|
|
@@ -55,5 +63,5 @@ USER appuser
|
|
| 55 |
EXPOSE 8000
|
| 56 |
|
| 57 |
# Start FastAPI with Uvicorn
|
| 58 |
-
#
|
| 59 |
-
CMD ["
|
|
|
|
| 8 |
WORKDIR /build
|
| 9 |
|
| 10 |
# If you truly need to compile deps, keep build-essential.
|
| 11 |
+
# If you use psycopg[binary], you can safely drop libpq-dev.
|
| 12 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 13 |
build-essential \
|
| 14 |
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
| 26 |
|
| 27 |
ENV PIP_NO_CACHE_DIR=1 \
|
| 28 |
PYTHONDONTWRITEBYTECODE=1 \
|
| 29 |
+
PYTHONUNBUFFERED=1 \
|
| 30 |
+
PYTHONPATH=/app
|
| 31 |
|
| 32 |
WORKDIR /app
|
| 33 |
|
|
|
|
| 45 |
# Copy the actual application code
|
| 46 |
COPY . .
|
| 47 |
|
| 48 |
+
# ---------- Metadata & Healthcheck ----------
|
| 49 |
+
LABEL org.opencontainers.image.title="nl2sql-copilot" \
|
| 50 |
+
org.opencontainers.image.description="Modular Text-to-SQL Copilot (FastAPI)" \
|
| 51 |
+
org.opencontainers.image.source="https://github.com/melika-kheirieh/nl2sql-copilot" \
|
| 52 |
+
org.opencontainers.image.authors="melika.kheirieh" \
|
| 53 |
+
org.opencontainers.image.licenses="MIT"
|
| 54 |
+
|
| 55 |
+
# Lightweight healthcheck (no curl)
|
| 56 |
+
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
|
| 57 |
+
CMD python -c "import urllib.request, sys; \
|
| 58 |
+
sys.exit(0) if urllib.request.urlopen('http://127.0.0.1:8000/healthz', timeout=2).getcode() == 200 else sys.exit(1)"
|
| 59 |
|
| 60 |
# Drop privileges
|
| 61 |
USER appuser
|
|
|
|
| 63 |
EXPOSE 8000
|
| 64 |
|
| 65 |
# Start FastAPI with Uvicorn
|
| 66 |
+
# (UVICORN_WORKERS can be overridden at runtime)
|
| 67 |
+
CMD ["sh", "-c", "uvicorn app.main:app --host 0.0.0.0 --port 8000 --proxy-headers --workers ${UVICORN_WORKERS:-1}"]
|