add autoencoder and dockerize
This commit is contained in:
parent
39d1b34dd6
commit
2f06e5364c
8 changed files with 65 additions and 29 deletions
|
|
@ -1,20 +1,17 @@
|
|||
# Dockerfile.mlflow-server
|
||||
# Runs a local MLflow tracking server with the repository's model registry and artifacts.
|
||||
FROM python:3.11-slim
|
||||
|
||||
FROM python:3.13-slim
|
||||
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
# Install uv
|
||||
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv
|
||||
WORKDIR /app
|
||||
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
curl \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
# Create a virtual environment and install mlflow inside it
|
||||
RUN uv venv /app/.venv && \
|
||||
uv pip install --python /app/.venv mlflow
|
||||
|
||||
RUN pip install --no-cache-dir mlflow==3.14.0 sqlalchemy
|
||||
# Add the virtual environment to the PATH so the mlflow command is recognized
|
||||
ENV PATH="/app/.venv/bin:$PATH"
|
||||
|
||||
COPY mlflow.db /app/mlflow.db
|
||||
COPY mlartifacts /app/mlartifacts
|
||||
EXPOSE 8000
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
CMD ["mlflow", "server", "--backend-store-uri", "sqlite:///app/mlflow.db", "--default-artifact-root", "file:///app/mlartifacts", "--host", "0.0.0.0", "--port", "8080", "--workers", "1"]
|
||||
# Start the server
|
||||
CMD ["mlflow", "server", "--host", "0.0.0.0", "--port", "8000", "--backend-store-uri", "sqlite:///mlflow.db", "--default-artifact-root", "./mlartifacts"]
|
||||
|
|
@ -1,22 +1,29 @@
|
|||
# Dockerfile.model-serve
|
||||
# Builds a container that serves an MLflow registry model by name and version.
|
||||
|
||||
FROM python:3.13-slim
|
||||
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
FROM astral/uv:python3.12-bookworm-slim
|
||||
# Install uv
|
||||
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv
|
||||
WORKDIR /app
|
||||
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
curl \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
# Copy dependency files first to leverage Docker layer caching
|
||||
COPY pyproject.toml uv.lock ./
|
||||
|
||||
RUN pip install --no-cache-dir mlflow==3.14.0
|
||||
# Create a virtual environment and sync dependencies
|
||||
# --no-dev ensures testing/formatting tools aren't installed in production
|
||||
RUN uv venv && uv sync --frozen --no-dev
|
||||
|
||||
ARG MODEL_NAME=IsolationForest_Anomaly_Detector
|
||||
ARG MODEL_VERSION=6
|
||||
ENV MODEL_NAME=${MODEL_NAME}
|
||||
ENV MODEL_VERSION=${MODEL_VERSION}
|
||||
# Put the venv in the system PATH so we don't need to manually activate it
|
||||
ENV PATH="/app/.venv/bin:$PATH"
|
||||
|
||||
# Copy the rest of the project
|
||||
COPY . .
|
||||
|
||||
# Set the environment variable for the model as requested
|
||||
ENV MODEL_URI="models:/Autoencoder_Anomaly_Detector/2"
|
||||
|
||||
# The tracking URI where this container will fetch the model.
|
||||
# (Set this to the MLflow server's hostname/IP at runtime, e.g., via Docker Compose)
|
||||
ENV MLFLOW_TRACKING_URI="http://localhost:8000"
|
||||
|
||||
EXPOSE 5001
|
||||
|
||||
CMD ["sh", "-c", "mlflow models serve -m \"models:/$MODEL_NAME/$MODEL_VERSION\" --host 0.0.0.0 --port 5001 --env-manager local"]
|
||||
# Serve the model using the environment variable
|
||||
CMD mlflow models serve -m "$MODEL_URI" --host 0.0.0.0 --port 5001 --env-manager local
|
||||
32
docker-compose.yml
Normal file
32
docker-compose.yml
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
services:
|
||||
mlflow-server:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile.mlflow-server
|
||||
ports:
|
||||
- "8000:8000"
|
||||
volumes:
|
||||
# Mount the database file and artifacts directory to persist them
|
||||
- ./mlflow.db:/app/mlflow.db
|
||||
- ./mlartifacts:/app/mlartifacts
|
||||
restart: unless-stopped
|
||||
|
||||
model-serve:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile.model-serve
|
||||
ports:
|
||||
- "5001:5001"
|
||||
environment:
|
||||
# Points to the service name defined above, not localhost
|
||||
- MLFLOW_TRACKING_URI=http://mlflow-server:8000
|
||||
# You can override this at runtime: docker compose run -e MODEL_URI="..." model-serve
|
||||
- MODEL_URI=${MODEL_URI:-models:/Autoencoder_Anomaly_Detector/2}
|
||||
volumes:
|
||||
# Crucial: Since MLflow is using a local disk artifact store,
|
||||
# the server passes local file paths back to the client.
|
||||
# The serving container must have access to the exact same artifact paths.
|
||||
- ./mlartifacts:/app/mlartifacts
|
||||
depends_on:
|
||||
- mlflow-server
|
||||
restart: unless-stopped
|
||||
Loading…
Add table
Reference in a new issue