Skip to content

Commit 7861026

Browse files
committed
Add Mlflow to docker compose setup
Also add a test command to show communication between the django web server and the new Mlflow service.
1 parent f8030fc commit 7861026

6 files changed

Lines changed: 54 additions & 0 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from django.conf import settings
2+
from django.contrib.auth.models import User
3+
import djclick as click
4+
from mlflow import MlflowClient
5+
6+
7+
@click.option(
8+
'--username',
9+
type=click.STRING,
10+
required=True,
11+
help='superuser username for mlflow experiment creation',
12+
)
13+
@click.option('--name', type=click.STRING, required=True, help='a name for the mlflow experiment')
14+
@click.option(
15+
'--description',
16+
type=click.STRING,
17+
required=False,
18+
help='a description for the mlflow experiment',
19+
)
20+
@click.command()
21+
def command(username, name, description: str | None = None):
22+
if username:
23+
user = User.objects.get(username=username)
24+
else:
25+
first_user = User.objects.first()
26+
if first_user:
27+
user = user
28+
29+
if user:
30+
mlflow_client = MlflowClient(tracking_uri=settings.MLFLOW_ENDPOINT)
31+
32+
experiment_tags = {
33+
'project-name': 'batsai',
34+
}
35+
if description:
36+
experiment_tags['mlflow.note.content'] = description
37+
38+
mlflow_client.create_experiment(name=name, tags=experiment_tags)

bats_ai/settings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ class DevelopmentConfiguration(BatsAiMixin, DevelopmentBaseConfiguration):
8181
MINIO_STORAGE_MEDIA_USE_PRESIGNED = True
8282
MINIO_STORAGE_MEDIA_URL = 'http://127.0.0.1:9000/django-storage'
8383

84+
MLFLOW_ENDPOINT = values.Value('http://localhost:5000')
85+
8486

8587
class TestingConfiguration(BatsAiMixin, TestingBaseConfiguration):
8688
pass

dev/.env.docker-compose

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ DOCKER_MINIO_PORT=9000
1313
DOCKER_MINIO_CONSOLE_PORT=9001
1414
APPLICATION_CLIENT_ID=HSJWFZ2cIpWQOvNyCXyStV9hiOd7DfWeBOCzo4pP # Application Identification
1515
NABAT_API_URL=https://api.sciencebase.gov/nabat-graphql/graphql
16+
DJANGO_MLFLOW_ENDPOINT=mlflow:5000

dev/.env.docker-compose-native

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ DJANGO_MINIO_STORAGE_SECRET_KEY=minioSecretKey
77
DJANGO_STORAGE_BUCKET_NAME=django-storage
88
APPLICATION_CLIENT_ID=HSJWFZ2cIpWQOvNyCXyStV9hiOd7DfWeBOCzo4pP # Application Identification
99
NABAT_API_URL=https://api.sciencebase.gov/nabat-graphql/graphql
10+
DJANGO_MLFLOW_ENDPOINT=http://localhost:5000

docker-compose.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ services:
3131
volumes:
3232
- minio:/data
3333

34+
mlflow:
35+
image: ghcr.io/mlflow/mlflow:latest
36+
ports:
37+
- "5000:5000"
38+
environment:
39+
- MLFLOW_S3_ENDPOINT_URL=http://minio:9000
40+
- AWS_ACCESS_KEY=${DJANGO_MINIO_STORAGE_ACCESS_KEY:-minioAccessKey}
41+
- AWS_SECRET_ACCESS_KEY=${DJANGO_DATABASE_PASSWORD:-minioSecretKey}
42+
command: mlflow server --host 0.0.0.0 --port 5000 --backend-store-uri postgresql://postgres:postgres@postgres:5432/mlflow --artifacts-destination s3://bucket
43+
3444
volumes:
3545
postgres:
3646
sourcedb:

setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@
7171
# guano metadata
7272
'guano',
7373
'django_celery_results',
74+
# ML Ops
75+
'mlflow',
7476
],
7577
extras_require={
7678
'dev': [

0 commit comments

Comments
 (0)