Skip to content

Commit

Permalink
Refactor Docker setup for API and Streamlit services
Browse files Browse the repository at this point in the history
- Updated docker-compose.yml to use new Dockerfiles for API and Streamlit services.
- Created Dockerfile.apipredict for the API service with necessary dependencies and configurations.
- Created Dockerfile.streamlit for the Streamlit service, including installation of requirements.
- Adjusted volume paths in docker-compose.yml.
  • Loading branch information
mikhaelbenilouz committed Dec 1, 2024
1 parent 51c0f67 commit ccabc36
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
13 changes: 8 additions & 5 deletions app/api/predict/Dockerfile → app/Dockerfile.apipredict
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@ WORKDIR /app
COPY ./app/api/predict/requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY ./app/api/predict /app
COPY ./ml/models /app
COPY ./app/api/predict /app/src
COPY ./ml/models/model.pkl /app/model.pkl

ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PYTHONPATH=/app
PYTHONUNBUFFERED=1 \
PYTHONPATH=/app/src

RUN adduser --disabled-password --gecos "" appuser
RUN chown -R appuser:appuser /app

USER appuser

EXPOSE 8000

CMD ["python", "-m", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
# TODO remove hot reloading for production
CMD ["python", "-m", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]

HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8000/health || exit 1
2 changes: 1 addition & 1 deletion app/streamlit/Dockerfile → app/Dockerfile.streamlit
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM python:3.12-slim

WORKDIR /app

COPY . /app
COPY ./streamlit /app

RUN pip install --no-cache-dir -r requirements.txt

Expand Down
10 changes: 4 additions & 6 deletions app/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@ services:
api-predict:
build:
context: ..
dockerfile: app/api/predict/Dockerfile
image: api-predict
dockerfile: app/Dockerfile.apipredict
container_name: api-predict
ports:
- "8002:8000"
volumes:
- ./api/predict:/app/predict # TODO remove for production
- ./api/predict:/app/src # TODO remove for production
environment:
MLFLOW_TRACKING_URI: ${MLFLOW_TRACKING_URI}
networks:
- backend

streamlit:
build:
context: streamlit
dockerfile: Dockerfile
image: streamlit
context: .
dockerfile: Dockerfile.streamlit
container_name: streamlit
ports:
- "8501:8501"
Expand Down

0 comments on commit ccabc36

Please sign in to comment.