Skip to content

Commit

Permalink
[Deprecations] Resolve 1.7.0 deprecations (#5510)
Browse files Browse the repository at this point in the history
  • Loading branch information
alonmr committed May 5, 2024
1 parent f942608 commit 66af02a
Show file tree
Hide file tree
Showing 47 changed files with 141 additions and 1,797 deletions.
18 changes: 13 additions & 5 deletions dockerfiles/jupyter/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ RUN python -m pip install \
-r /tmp/requirements/extras-requirement.txt \
-r /tmp/requirements/requirement.txt

COPY --chown=$NB_UID:$NB_GID . /tmp/mlrun
RUN cd /tmp/mlrun && python -m pip install ".[complete-api]"
COPY --chown=$NB_UID:$NB_GID . $HOME/mlrun
RUN cd $HOME/mlrun && python -m pip install ".[complete-api]"

# This will usually cause a cache miss - so keep it in the last layers
ARG MLRUN_CACHE_DATE=initial
RUN git clone --branch 1.6.x https://github.com/mlrun/demos.git $HOME/demos && \
RUN git clone --branch 1.7.x https://github.com/mlrun/demos.git $HOME/demos && \
./demos/update_demos.sh --user=jovyan --path=/home/jovyan/demos --no-backup && \
cd $HOME/demos && \
./community_edition_align.sh && \
Expand All @@ -83,8 +83,16 @@ RUN tar -cvf /tmp/basehome.tar $HOME

COPY --chown=$NB_UID:$NB_GID ./dockerfiles/jupyter/mlce-start.sh /usr/local/bin/mlce-start.sh

# run the mlrun db (api) and the notebook in parallel
CMD MLRUN_ARTIFACT_PATH=$HOME/data python -m mlrun db & MLRUN_DBPATH=http://localhost:8080 start-notebook.sh \
# use tini as entrypoint to allow signal handling
# and avoid zombie processes
ENTRYPOINT ["tini", "--"]

# run the mlrun api and the notebook in parallel
CMD cd $HOME/mlrun && MLRUN_ARTIFACT_PATH=$HOME/data uvicorn server.api.main:app \
--proxy-headers \
--host="0.0.0.0" \
--log-config=server/api/uvicorn_log_config.yaml & \
MLRUN_DBPATH=http://localhost:8080 start-notebook.sh \
--ip="0.0.0.0" \
--port=8888 \
--NotebookApp.token='' \
Expand Down
105 changes: 0 additions & 105 deletions mlrun/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
from base64 import b64decode, b64encode
from os import environ, path, remove
from pprint import pprint
from subprocess import Popen
from sys import executable
from urllib.parse import urlparse

import click
import dotenv
Expand Down Expand Up @@ -827,108 +824,6 @@ def get(kind, name, selector, namespace, uid, project, tag, db, extra_args):
)


@main.command(deprecated=True)
@click.option("--port", "-p", help="port to listen on", type=int)
@click.option("--dirpath", "-d", help="database directory (dirpath)")
@click.option("--dsn", "-s", help="database dsn, e.g. sqlite:///db/mlrun.db")
@click.option("--logs-path", "-l", help="logs directory path")
@click.option("--data-volume", "-v", help="path prefix to the location of artifacts")
@click.option("--verbose", is_flag=True, help="verbose log")
@click.option("--background", "-b", is_flag=True, help="run in background process")
@click.option("--artifact-path", "-a", help="default artifact path")
@click.option(
"--update-env",
default="",
is_flag=False,
flag_value=mlrun.config.default_env_file,
help=f"update the specified mlrun .env file (if TEXT not provided defaults to {mlrun.config.default_env_file})",
)
def db(
port,
dirpath,
dsn,
logs_path,
data_volume,
verbose,
background,
artifact_path,
update_env,
):
"""Run HTTP api/database server"""
warnings.warn(
"The `mlrun db` command is deprecated in 1.5.0 and will be removed in 1.7.0, it is for internal use only.",
FutureWarning,
)
env = environ.copy()
# ignore client side .env file (so import mlrun in server will not try to connect to local/remote DB)
env["MLRUN_IGNORE_ENV_FILE"] = "true"
env["MLRUN_DBPATH"] = ""

if port is not None:
env["MLRUN_HTTPDB__PORT"] = str(port)
if dirpath is not None:
env["MLRUN_HTTPDB__DIRPATH"] = dirpath
if dsn is not None:
if dsn.startswith("sqlite://") and "check_same_thread=" not in dsn:
dsn += "?check_same_thread=false"
env["MLRUN_HTTPDB__DSN"] = dsn
if logs_path is not None:
env["MLRUN_HTTPDB__LOGS_PATH"] = logs_path
if data_volume is not None:
env["MLRUN_HTTPDB__DATA_VOLUME"] = data_volume
if verbose:
env["MLRUN_LOG_LEVEL"] = "DEBUG"
if artifact_path or "MLRUN_ARTIFACT_PATH" not in env:
if not artifact_path:
artifact_path = (
env.get("MLRUN_HTTPDB__DATA_VOLUME", "./artifacts").rstrip("/")
+ "/{{project}}"
)
env["MLRUN_ARTIFACT_PATH"] = path.realpath(path.expanduser(artifact_path))

env["MLRUN_IS_API_SERVER"] = "true"

# create the DB dir if needed
dsn = dsn or mlconf.httpdb.dsn
if dsn and dsn.startswith("sqlite:///"):
parsed = urlparse(dsn)
p = pathlib.Path(parsed.path[1:]).parent
p.mkdir(parents=True, exist_ok=True)

cmd = [executable, "-m", "server.api.main"]
pid = None
if background:
print("Starting MLRun API service in the background...")
child = Popen(
cmd,
env=env,
stdout=open("mlrun-stdout.log", "w"),
stderr=open("mlrun-stderr.log", "w"),
start_new_session=True,
)
pid = child.pid
print(
f"Background pid: {pid}, logs written to mlrun-stdout.log and mlrun-stderr.log, use:\n"
f"`kill {pid}` (linux/mac) or `taskkill /pid {pid} /t /f` (windows), to kill the mlrun service process"
)
else:
child = Popen(cmd, env=env)
returncode = child.wait()
if returncode != 0:
raise SystemExit(returncode)
if update_env:
# update mlrun client env file with the API path, so client will use the new DB
# update and PID, allow killing the correct process in a config script
filename = path.expanduser(update_env)
dotenv.set_key(
filename, "MLRUN_DBPATH", f"http://localhost:{port or 8080}", quote_mode=""
)
dotenv.set_key(filename, "MLRUN_MOCK_NUCLIO_DEPLOYMENT", "auto", quote_mode="")
if pid:
dotenv.set_key(filename, "MLRUN_SERVICE_PID", str(pid), quote_mode="")
print(f"Updated configuration in {update_env} .env file")


@main.command()
def version():
"""get mlrun version"""
Expand Down
3 changes: 1 addition & 2 deletions mlrun/artifacts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
ArtifactProducer,
artifact_types,
dict_to_artifact,
legacy_artifact_types,
)
from .model import ModelArtifact, get_model, update_model
from .plots import BokehArtifact, ChartArtifact, PlotArtifact, PlotlyArtifact
from .plots import PlotArtifact, PlotlyArtifact

0 comments on commit 66af02a

Please sign in to comment.