sethmcknight commited on
Commit
1858e78
·
1 Parent(s): ffd8fdb

refactor: update Dockerfile and requirements for improved dependency management and build efficiency

Browse files
Files changed (4) hide show
  1. Dockerfile +27 -22
  2. constraints.txt +17 -0
  3. dev-requirements.txt +15 -6
  4. requirements.txt +4 -14
Dockerfile CHANGED
@@ -1,32 +1,37 @@
1
  # Use an official Python runtime as a parent image
2
- FROM python:3.10-slim
 
 
 
 
3
 
4
- # Set the working directory in the container
5
  WORKDIR /app
6
 
7
- # Copy the dependencies file to the working directory
8
- COPY requirements.txt .
 
 
9
 
10
- # Install any needed packages specified in requirements.txt
11
- RUN pip install --no-cache-dir -r requirements.txt
12
- # Copy only application source (avoid copying dev files)
13
- COPY app.py /app/app.py
14
- COPY templates /app/templates
15
- COPY static /app/static
16
- # Copy the application package so `import src` works inside the container
17
- COPY src /app/src
18
- # Copy persisted data (e.g., chroma DB) so the container can access it if present
19
- COPY data /app/data
20
- # COPY the scripts directory so runtime init scripts (e.g. init_pgvector.py) exist
21
- COPY scripts /app/scripts
22
 
23
- COPY run.sh /app/run.sh
 
 
 
 
 
 
 
24
 
25
- # Make run.sh (and optionally the init script) executable
26
- RUN chmod +x /app/run.sh
27
- RUN chmod +x /app/scripts/init_pgvector.py || true
28
 
29
- # Expose port 10000
30
  EXPOSE 10000
31
- # Default entrypoint uses run.sh which starts gunicorn with configurable workers
32
  CMD ["/app/run.sh"]
 
 
 
 
 
 
1
  # Use an official Python runtime as a parent image
2
+ FROM python:3.10-slim AS base
3
+ ENV PYTHONDONTWRITEBYTECODE=1 \
4
+ PYTHONUNBUFFERED=1 \
5
+ PIP_NO_CACHE_DIR=1 \
6
+ PIP_DISABLE_PIP_VERSION_CHECK=1
7
 
 
8
  WORKDIR /app
9
 
10
+ # Install build essentials only if needed for wheels (kept minimal)
11
+ RUN apt-get update && apt-get install -y --no-install-recommends \
12
+ build-essential \
13
+ && rm -rf /var/lib/apt/lists/*
14
 
15
+ COPY constraints.txt requirements.txt ./
16
+ RUN python -m pip install --upgrade pip setuptools wheel \
17
+ && pip install --no-cache-dir -r requirements.txt -c constraints.txt --only-binary=:all: || \
18
+ pip install --no-cache-dir -r requirements.txt -c constraints.txt
 
 
 
 
 
 
 
 
19
 
20
+ # Application source
21
+ COPY app.py ./app.py
22
+ COPY templates ./templates
23
+ COPY static ./static
24
+ COPY src ./src
25
+ COPY data ./data
26
+ COPY scripts ./scripts
27
+ COPY run.sh ./run.sh
28
 
29
+ RUN chmod +x run.sh && chmod +x scripts/init_pgvector.py || true
 
 
30
 
 
31
  EXPOSE 10000
 
32
  CMD ["/app/run.sh"]
33
+
34
+ # Optional dev stage for local tooling (not used in final image)
35
+ FROM base AS dev
36
+ COPY dev-requirements.txt ./dev-requirements.txt
37
+ RUN pip install --no-cache-dir -r dev-requirements.txt -c constraints.txt || true
constraints.txt ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Pinned runtime dependency constraints (generated manually)
2
+ Flask==3.0.3
3
+ Werkzeug==3.0.3
4
+ itsdangerous==2.2.0
5
+ Jinja2==3.1.4
6
+ click==8.1.7
7
+ gunicorn==22.0.0
8
+ numpy==1.26.4
9
+ requests==2.32.3
10
+ urllib3==2.2.2
11
+ idna==3.7
12
+ certifi==2024.7.4
13
+ charset-normalizer==3.3.2
14
+ psycopg2-binary==2.9.7
15
+ optimum==1.22.0
16
+ onnxruntime==1.18.1
17
+ psutil==5.9.0
dev-requirements.txt CHANGED
@@ -1,6 +1,15 @@
1
- pre-commit==3.5.0
2
- black>=25.0.0
3
- isort==5.13.0
4
- flake8==6.1.0
5
- psutil
6
- psycopg2-binary==2.9.7
 
 
 
 
 
 
 
 
 
 
1
+ -r requirements.txt
2
+
3
+ # Core dev tooling
4
+ pre-commit==3.7.1
5
+ black==24.8.0
6
+ isort==5.13.2
7
+ flake8==7.1.0
8
+ pytest==8.2.2
9
+
10
+ # Optional heavy packages used only for experimentation or legacy paths
11
+ chromadb==0.4.24
12
+ sentence-transformers==2.7.0
13
+
14
+ # Keep psutil available for local diagnostics even if disabled in production
15
+ psutil==5.9.0
requirements.txt CHANGED
@@ -1,20 +1,10 @@
1
- # Core web framework
2
  Flask==3.0.3
3
  gunicorn==22.0.0
4
-
5
- # Vector database and embeddings
6
- chromadb==0.4.24
7
- sentence-transformers==2.7.0
8
- optimum[onnxruntime]
9
  psycopg2-binary==2.9.7
10
-
11
- # Core dependencies (pinned for reproducibility, Python 3.12 compatible)
12
  numpy==1.26.4
13
  requests==2.32.3
 
 
 
14
 
15
- # Optional: Add psutil for better memory monitoring in production
16
- # Uncomment if you want detailed memory metrics
17
- # psutil==5.9.0
18
-
19
- psutil
20
- pytest
 
 
1
  Flask==3.0.3
2
  gunicorn==22.0.0
 
 
 
 
 
3
  psycopg2-binary==2.9.7
 
 
4
  numpy==1.26.4
5
  requests==2.32.3
6
+ optimum[onnxruntime]==1.22.0
7
+ onnxruntime==1.18.1
8
+ psutil==5.9.0
9
 
10
+ # Runtime-only requirements. Development and test tools are in dev-requirements.txt