sghorbal commited on
Commit
784101f
·
1 Parent(s): 7effb2a

reduce container size

Browse files
Files changed (3) hide show
  1. Dockerfile +27 -11
  2. requirements.txt +11 -10
  3. src/model.py +11 -4
Dockerfile CHANGED
@@ -1,26 +1,42 @@
1
- FROM tiangolo/uvicorn-gunicorn:python3.11
2
-
3
- COPY ./requirements.txt /tmp/requirements.txt
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  COPY ./entrypoint.sh /tmp/entrypoint.sh
5
  COPY ./src /app/src
6
  COPY ./tests /app/tests
7
 
8
- RUN pip install --no-cache-dir -r /tmp/requirements.txt
9
-
10
  WORKDIR /app
11
 
 
12
  ENV PYTHONPATH=/app
13
 
14
- # Port to expose
15
  EXPOSE 7860
16
 
17
- # Health Check
18
  HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
19
- CMD [ "curl", "-f", "http://localhost:7860/check_health" ]
20
 
21
- # Create a non-root user 'appuser' and switch to this user
22
  RUN useradd --create-home appuser
23
  USER appuser
24
 
25
- # CMD with JSON notation
26
- CMD ["/tmp/entrypoint.sh"]
 
1
+ # ---- Build stage ----
2
+ FROM python:3.11-slim-bullseye
3
+
4
+ COPY requirements.txt .
5
+ COPY requirements-dev.txt .
6
+
7
+ ARG TEST
8
+
9
+ # Installer les dépendances
10
+ RUN pip install --upgrade pip && \
11
+ pip install --no-cache-dir -r requirements.txt && \
12
+ if [ "$TEST" = "true" ]; then \
13
+ pip install --no-cache-dir -r requirements-dev.txt; \
14
+ fi
15
+
16
+ # Installer curl pour le healthcheck
17
+ RUN apt-get update && apt-get install -y --no-install-recommends curl && \
18
+ rm -rf /var/lib/apt/lists/*
19
+
20
+ # Copier le code
21
  COPY ./entrypoint.sh /tmp/entrypoint.sh
22
  COPY ./src /app/src
23
  COPY ./tests /app/tests
24
 
 
 
25
  WORKDIR /app
26
 
27
+ # Pour que les imports soient résolus depuis /app
28
  ENV PYTHONPATH=/app
29
 
30
+ # Exposer le port
31
  EXPOSE 7860
32
 
33
+ # Healthcheck sur FastAPI
34
  HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
35
+ CMD curl -f http://localhost:7860/check_health || exit 1
36
 
37
+ # Utilisateur non-root pour la sécurité
38
  RUN useradd --create-home appuser
39
  USER appuser
40
 
41
+ # Entrypoint (par exemple pour lancer uvicorn)
42
+ CMD ["/tmp/entrypoint.sh"]
requirements.txt CHANGED
@@ -1,10 +1,11 @@
1
- python-dotenv
2
- fastapi
3
- psycopg2-binary
4
- pandas
5
- scikit-learn
6
- openpyxl
7
- xlrd >= 2.0.1
8
- mlflow
9
- boto3
10
- pytest
 
 
1
+ python-dotenv==1.1.0
2
+ fastapi==0.115.12
3
+ psycopg2-binary==2.9.10
4
+ pandas==2.2.3
5
+ scikit-learn==1.6.1
6
+ openpyxl==3.1.5
7
+ xlrd==2.0.1
8
+ mlflow-skinny==2.21.3
9
+ boto3==1.37.34
10
+ uvicorn==0.34.1
11
+ gunicorn==23.0.0
src/model.py CHANGED
@@ -276,10 +276,17 @@ def list_registered_models() -> List[Dict]:
276
  List all the registered models
277
  """
278
  # Set tracking URI to your Heroku application
279
- mlflow.set_tracking_uri(os.environ["MLFLOW_SERVER_URI"])
280
-
281
- # Return the list of registered models
282
- results = mlflow.search_registered_models()
 
 
 
 
 
 
 
283
 
284
  output = []
285
  for res in results:
 
276
  List all the registered models
277
  """
278
  # Set tracking URI to your Heroku application
279
+ tracking_uri = os.environ.get("MLFLOW_SERVER_URI")
280
+ if tracking_uri is None:
281
+ raise ValueError("MLFLOW_SERVER_URI environment variable is not set.")
282
+ print(f"MLflow tracking URI: {tracking_uri}")
283
+
284
+ client = MlflowClient(tracking_uri=tracking_uri)
285
+ # Should be:
286
+ # results = client.search_registered_models()
287
+ # but this is not working from inside the container
288
+ # so we need to use the store client to get the registered models
289
+ results = client._get_registry_client().store.search_registered_models()
290
 
291
  output = []
292
  for res in results: