-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Official MLflow docker image support - slim & full version #11669
Open
JMLizano
wants to merge
11
commits into
mlflow:master
Choose a base branch
from
JMLizano:improve-docker
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
112c79c
first working version
998e3c3
Better naming for docker tests directory
a34e113
Add readme
ae19fe5
Remove unnecessary script
a10d1b2
using --no-cache-dir since --no-cache seems to not exist (but it works?)
5458e12
Add backend store dependencies to extras
50e8ad1
Update push image pipeline
c6b4853
Update docker docs
f0d7dba
More details for docker docs
674f196
README details
161d36b
No need to rebuild and pull every time a test run
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
FROM python:3.10-slim-bullseye | ||
ARG VERSION | ||
RUN pip install --upgrade pip && \ | ||
pip install --no-cache mlflow[extras,databricks,gateway,genai,sqlserver,aliyun-oss]==$VERSION | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't include |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
FROM python:3.10-slim-bullseye | ||
|
||
WORKDIR /app | ||
ADD . /app | ||
|
||
RUN pip install --upgrade pip && pip install --no-cache-dir -e .[extras,databricks,gateway,genai,sqlserver,aliyun-oss] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# mlflow docker image | ||
|
||
## Image variants | ||
|
||
### mlflow:\<version\> | ||
|
||
This image contains mlflow plus all extra dependencies. It is intended to support "out of the box" all mlflow integrations. | ||
|
||
Use this image if you just want to quickly have a working instance of mlflow, or if you don't want to bother rolling out your own image. | ||
|
||
### mlflow:\<version\>-slim | ||
|
||
This image only contains the core mlflow dependencies, so most of the integrations (ie. backend stores databases, | ||
artifact stores, etc.) will not work. | ||
|
||
Use this image if you don't need any integration, or as the base image in case you want to have full control over | ||
the extra dependencies installed. | ||
|
||
# Testing | ||
|
||
The [testcontainers](https://testcontainers.com/) package is used to the test the different integrations, for each one there | ||
is a Docker Compose file. So far the following integrations are tested: | ||
|
||
Backend store: | ||
|
||
- MySQL | ||
- PostgreSQL | ||
- MSSQL | ||
|
||
Artifact store: | ||
|
||
- Amazon S3 (through the [minio](https://hub.docker.com/r/minio/minio) image) | ||
- Azure Blob Storage (throug the [Azurite](https://hub.docker.com/_/microsoft-azure-storage-azurite) image) | ||
- Google Cloud Storage (through the [fake-gcs-server](https://github.com/fsouza/fake-gcs-server) image) | ||
|
||
## Executing the tests | ||
|
||
Make sure that you install all required dependencies first. | ||
|
||
```bash | ||
# mlflow, from a release | ||
$ pip install -U mlflow | ||
# or in editable mode | ||
$ pip install -e . | ||
# testcontaienrs & pytest | ||
$ pip install -U testcontainers<4 pytest | ||
``` | ||
|
||
Ensure [Docker](https://www.docker.com/) is installed. You will also need `docker-compose`, make sure to install | ||
[docker-compose v1](https://docs.docker.com/compose/install/standalone/), since `testcontainers` only supports Compose v2 | ||
from version 4.0 onwards, which is available only for Python 3.9+. | ||
|
||
Once you have all the dependencies you can execute the tests (from within `docker` folder): | ||
|
||
```bash | ||
# Execute all tests | ||
pytest | ||
# Execute a specific test | ||
pytest -k 'test_backend_and_artifact_store_integration[docker-compose.aws-test.yaml]' | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
version: "2.4" | ||
|
||
services: | ||
minio: | ||
container_name: mlflow-aws-test-storage | ||
image: minio/minio | ||
entrypoint: sh | ||
command: -c 'mkdir -p /data/mlflow && minio server /data --console-address ":9001"' | ||
environment: | ||
MINIO_ROOT_USER: minioadmin | ||
MINIO_ROOT_PASSWORD: minioadmin | ||
expose: | ||
- 9000 | ||
- 9001 | ||
|
||
mlflow: | ||
container_name: mlflow-aws-test | ||
image: mlflow-integration-test | ||
build: | ||
context: ../.. | ||
dockerfile: docker/Dockerfile.full.dev | ||
command: "mlflow server --artifacts-destination=s3://mlflow/ --host=0.0.0.0 --port=5000" | ||
environment: | ||
MLFLOW_S3_ENDPOINT_URL: http://minio:9000 | ||
AWS_ACCESS_KEY_ID: minioadmin | ||
AWS_SECRET_ACCESS_KEY: minioadmin | ||
ports: | ||
- "5000:5000" | ||
depends_on: | ||
- minio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
version: "2.4" | ||
|
||
services: | ||
azurite: | ||
image: mcr.microsoft.com/azure-storage/azurite | ||
container_name: mlflow-azure-test-storage | ||
command: azurite --blobHost 0.0.0.0 --queueHost 0.0.0.0 --loose --skipApiVersionCheck | ||
environment: | ||
AZURITE_ACCOUNTS: devstoreaccount1:Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw== | ||
expose: | ||
- 10000 | ||
- 10001 | ||
|
||
azurite-init: | ||
image: mcr.microsoft.com/azure-cli | ||
container_name: azurite-init | ||
command: az storage container create --name mlflow | ||
environment: | ||
AZURE_STORAGE_CONNECTION_STRING: DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://azurite:10000/devstoreaccount1;QueueEndpoint=http://azurite:10001/devstoreaccount1 | ||
depends_on: | ||
- azurite | ||
|
||
mlflow: | ||
container_name: mlflow-azure-test | ||
image: mlflow-integration-test | ||
build: | ||
context: ../.. | ||
dockerfile: docker/Dockerfile.full.dev | ||
command: "mlflow server --artifacts-destination=wasbs://mlflow@devstoreaccount1.blob.core.windows.net --host=0.0.0.0 --port=5000" | ||
environment: | ||
AZURE_STORAGE_CONNECTION_STRING: DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://azurite:10000/devstoreaccount1;QueueEndpoint=http://azurite:10001/devstoreaccount1 | ||
ports: | ||
- "5000:5000" | ||
depends_on: | ||
- azurite-init | ||
- azurite |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
version: "2.4" | ||
|
||
services: | ||
gcs: | ||
container_name: mlflow-gcp-test-storage | ||
image: fsouza/fake-gcs-server | ||
entrypoint: sh -c "mkdir -p /data/mlflow && /bin/fake-gcs-server -data /data -scheme http" | ||
expose: | ||
- 4443 | ||
|
||
mlflow: | ||
container_name: mlflow-gcp-test | ||
image: mlflow-integration-test | ||
build: | ||
context: ../.. | ||
dockerfile: docker/Dockerfile.full.dev | ||
command: "mlflow server --artifacts-destination=gs://mlflow/ --host=0.0.0.0 --port=5000" | ||
environment: | ||
GOOGLE_CLOUD_PROJECT: mlflow | ||
STORAGE_EMULATOR_HOST: http://gcs:4443 | ||
ports: | ||
- "5000:5000" | ||
depends_on: | ||
- gcs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
version: "2.4" | ||
|
||
services: | ||
mssql: | ||
image: mcr.microsoft.com/mssql/server | ||
container_name: mlflow-mssql-test-db | ||
environment: | ||
MSSQL_SA_PASSWORD: StrongPassword! | ||
ACCEPT_EULA: "Y" | ||
expose: | ||
- 1433 | ||
|
||
mlflow: | ||
container_name: mlflow-mssql-test | ||
image: mlflow-integration-test | ||
build: | ||
context: ../.. | ||
dockerfile: docker/Dockerfile.full.dev | ||
command: "mlflow server --backend-store-uri=mssql+pymssql://sa:StrongPassword!@mssql:1433 --host=0.0.0.0 --port=5000" | ||
ports: | ||
- "5000:5000" | ||
depends_on: | ||
- mssql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
version: "2.4" | ||
|
||
services: | ||
mysql: | ||
image: "mysql" | ||
container_name: mlflow-mysql-test-db | ||
environment: | ||
MYSQL_ROOT_PASSWORD: password | ||
MYSQL_DATABASE: mlflow | ||
MYSQL_USER: mlflow | ||
MYSQL_PASSWORD: password | ||
MYSQL_TCP_PORT: 3306 | ||
expose: | ||
- 3306 | ||
|
||
mlflow: | ||
container_name: mlflow-mysql-test | ||
image: mlflow-integration-test | ||
build: | ||
context: ../.. | ||
dockerfile: docker/Dockerfile.full.dev | ||
command: "mlflow server --backend-store-uri=mysql+pymysql://mlflow:password@mysql:3306/mlflow --host=0.0.0.0 --port=5000" | ||
ports: | ||
- "5000:5000" | ||
depends_on: | ||
- mysql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
version: "2.4" | ||
|
||
services: | ||
postgres: | ||
image: "postgres" | ||
container_name: mlflow-pg-test-db | ||
environment: | ||
POSTGRES_PASSWORD: postgres | ||
POSTGRES_USER: postgres | ||
expose: | ||
- 5432 | ||
|
||
mlflow: | ||
container_name: mlflow-pg-test | ||
image: mlflow-integration-test | ||
build: | ||
context: ../.. | ||
dockerfile: docker/Dockerfile.full.dev | ||
command: "mlflow server --backend-store-uri=postgresql:// --host=0.0.0.0 --port=5000" | ||
environment: | ||
PGHOST: postgres | ||
PGPORT: 5432 | ||
PGDATABASE: postgres | ||
PGUSER: postgres | ||
PGPASSWORD: postgres | ||
ports: | ||
- "5000:5000" | ||
depends_on: | ||
- postgres |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import os | ||
|
||
import pytest | ||
from testcontainers.compose import DockerCompose | ||
|
||
import mlflow | ||
from mlflow.tracking.client import MlflowClient | ||
|
||
|
||
class TestModel(mlflow.pyfunc.PythonModel): | ||
def load_context(self, context): | ||
pass | ||
|
||
def predict(self, context, model_input, params=None): | ||
pass | ||
|
||
|
||
_COMPOSE_FILE_LIST = [ | ||
"docker-compose.aws-test.yaml", | ||
"docker-compose.azure-test.yaml", | ||
"docker-compose.gcp-test.yaml", | ||
"docker-compose.mssql-test.yaml", | ||
"docker-compose.mysql-test.yaml", | ||
"docker-compose.postgres-test.yaml", | ||
] | ||
|
||
|
||
def create_experiment_and_register_model(base_url: str): | ||
experiment_name = "integration-test-experiment" | ||
model_name = "integration-test-model" | ||
mlflow.set_tracking_uri(base_url) | ||
mlflow.set_experiment(experiment_name) | ||
experiment = mlflow.get_experiment_by_name(experiment_name) | ||
test_model = TestModel() | ||
with mlflow.start_run(experiment_id=experiment.experiment_id) as run: | ||
mlflow.log_params({"param": 1}) | ||
mlflow.log_metric("metric", 1.0) | ||
mlflow.pyfunc.log_model("model", python_model=test_model) | ||
model_uri = f"runs:/{run.info.run_id}/model" | ||
mlflow.register_model(model_uri, model_name, tags={"status": "ready"}) | ||
client = MlflowClient() | ||
client.set_registered_model_alias(model_name, "champion", "1") | ||
|
||
|
||
@pytest.mark.parametrize("compose_file_name", _COMPOSE_FILE_LIST) | ||
def test_backend_and_artifact_store_integration(compose_file_name): | ||
with DockerCompose( | ||
filepath=os.path.dirname(os.path.abspath(__file__)), compose_file_name=[compose_file_name] | ||
) as compose: | ||
mlflow_host = compose.get_service_host("mlflow", 5000) | ||
mlflow_port = compose.get_service_port("mlflow", 5000) | ||
base_url = f"http://{mlflow_host}:{mlflow_port}" | ||
compose.wait_for(base_url) | ||
create_experiment_and_register_model(base_url) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be awesome to get this merged. See:
Maybe @harupy or @dbczumar or @BenWilson2 could triage? Thanks!