Skip to content

Commit

Permalink
add files for the App Engine set up
Browse files Browse the repository at this point in the history
  • Loading branch information
RoriCremer committed Jan 29, 2025
1 parent 7c03558 commit bc75ad7
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
21 changes: 21 additions & 0 deletions mlflow/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM python:3.8-slim

# displays logs imidietly to the stream, they wont be part of the buffer
ENV PYTHONUNBUFFERED True
ENV GCP_PROJECT="783282864357"

WORKDIR /app

COPY ./requirements.txt ./requirements.txt

RUN pip install -r requirements.txt

COPY get_secret.py /app/get_secret.py
COPY entry-point.sh /app/entry-point.sh
COPY mlflow_auth.py /app/mlflow_auth.py

ENTRYPOINT ["/usr/bin/env", "bash", "/app/entry-point.sh"]

EXPOSE 8080
EXPOSE 8000/tcp
CMD [ "--backend-store-uri", "/tmp"]
8 changes: 8 additions & 0 deletions mlflow/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
service: mlflow
runtime: custom
env: flex
automatic_scaling:
min_num_instances: 1
max_num_instances: 2
beta_settings:
cloud_sql_instances: broad-ml4cvd:us-central1:broad-ml4cvd-staging-db
54 changes: 54 additions & 0 deletions mlflow/entry-point.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env bash

set -e

# Verify that all required variables are set
if [[ -z "${GCP_PROJECT}" ]]; then
echo "Error: GCP_PROJECT not set"
exit 1
fi

# Fetch secrets from Secret Manager in CGP
export MLFLOW_TRACKING_USERNAME="$(python3 /app/get_secret.py --project="${GCP_PROJECT}" --secret=mlflow_tracking_username)"
export MLFLOW_TRACKING_PASSWORD="$(python3 /app/get_secret.py --project="${GCP_PROJECT}" --secret=mlflow_tracking_password)"
export ARTIFACT_URL="$(python3 /app/get_secret.py --project="${GCP_PROJECT}" --secret=mlflow_artifact_url)"
if [[ -z "${DATABASE_URL}" ]]; then # Allow overriding for local deployment
export DATABASE_URL="$(python3 /app/get_secret.py --project="${GCP_PROJECT}" --secret=mlflow_database_url)"
fi

# Verify that all required variables are set
if [[ -z "${MLFLOW_TRACKING_USERNAME}" ]]; then
echo "Error: MLFLOW_TRACKING_USERNAME not set"
exit 1
fi

if [[ -z "${MLFLOW_TRACKING_PASSWORD}" ]]; then
echo "Error: MLFLOW_TRACKING_PASSWORD not set"
exit 1
fi

if [[ -z "${ARTIFACT_URL}" ]]; then
echo "Error: ARTIFACT_URL not set"
exit 1
fi

if [[ -z "${DATABASE_URL}" ]]; then
echo "Error: DATABASE_URL not set"
exit 1
fi

if [[ -z "${PORT}" ]]; then
export PORT=8080
fi

export WSGI_AUTH_CREDENTIALS="${MLFLOW_TRACKING_USERNAME}:${MLFLOW_TRACKING_PASSWORD}"
export _MLFLOW_SERVER_ARTIFACT_ROOT="${ARTIFACT_URL}"
export _MLFLOW_SERVER_FILE_STORE="${DATABASE_URL}"

echo "hello its me im the problem its me"
echo ${_MLFLOW_SERVER_FILE_STORE}
echo "or me"
echo ${_MLFLOW_SERVER_ARTIFACT_ROOT}

# Start MLflow and ngingx using supervisor
exec gunicorn -b "${HOST}:${PORT}" -w 4 --log-level debug --access-logfile=- --error-logfile=- --log-level=debug mlflow_auth:app
4 changes: 4 additions & 0 deletions mlflow/mlflow_auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from mlflow.server import app as mlflow_app
from wsgi_basic_auth import BasicAuth

app = BasicAuth(mlflow_app)

0 comments on commit bc75ad7

Please sign in to comment.