Repository: SeldonIO/MLServer

Issue:
Activating custom conda env in mlserver build image
Hello,
I’ve encountered an issue when using `mlserver build ...` with `1.1.0dev` where the custom conda environment is not activated. The image builds and all packages are present in the image. However, when starting the image it crashes on `mlserver start` calling what seems to be native Python 3.8 rather than the conda installed python.

```
--> Sourcing new environment at ./envs/base/environment...

--> Calling conda-unpack...

--> Disabling user-installed packages...

Traceback (most recent call last):

  File "/opt/mlserver/envs/base/environment/bin/mlserver", line 8, in <module>

    sys.exit(main())

  File "/usr/local/lib/python3.8/site-packages/mlserver/cli/main.py", line 76, in main

    root()

  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1128, in __call__

    return self.main(*args, **kwargs)

  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1053, in main

    rv = self.invoke(ctx)

  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1659, in invoke

    return _process_result(sub_ctx.command.invoke(sub_ctx))

  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1395, in invoke

    return ctx.invoke(self.callback, **ctx.params)

  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 754, in invoke

    return __callback(*args, **kwargs)

  File "/usr/local/lib/python3.8/site-packages/mlserver/cli/main.py", line 19, in wrapper

    return asyncio.run(f(*args, **kwargs))

  File "/usr/local/lib/python3.8/asyncio/runners.py", line 44, in run

    return loop.run_until_complete(main)

  File "/usr/local/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete

    return future.result()

  File "/usr/local/lib/python3.8/site-packages/mlserver/cli/main.py", line 40, in start

    settings, models = await load_settings(folder)

  File "/usr/local/lib/python3.8/site-packages/mlserver/cli/serve.py", line 37, in load_settings

    available_models = await repository.list()

  File "/usr/local/lib/python3.8/site-packages/mlserver/repository.py", line 37, in list

    model_settings = ModelSettings()

  File "pydantic/env_settings.py", line 36, in pydantic.env_settings.BaseSettings.__init__

  File "pydantic/main.py", line 406, in pydantic.main.BaseModel.__init__

pydantic.error_wrappers.ValidationError: 1 validation error for ModelSettings

implementation

  ensure this value contains valid import path or valid callable: No module named 'mlserver_mlflow' (type=type_error.pyobject; error_message=No module named 'mlserver_mlflow')

```

- [x] manually removing final CMD line in Dockerfile and starting interactive container. Running `./hack/activate-env.sh ./envs/base.tar.gz ./envs/base && mlserver start $MLSERVER_MODELS_DIR` successfully launches the service

conda.yaml file:
```
channels:
- defaults
- conda-forge
- anaconda
dependencies:
- python=3.7.10
- pip
- gcc_linux-aarch64
- gxx_linux-aarch64
- pip:
  - mlflow
  - mlserver==0.4.0
  - mlserver-mlflow==0.4.0
name: conda
```


Discussion:

Resolving patch:
diff --git a/mlserver/cli/constants.py b/mlserver/cli/constants.py
--- a/mlserver/cli/constants.py
+++ b/mlserver/cli/constants.py
@@ -24,7 +24,7 @@
             conda env create \
                 --name $MLSERVER_ENV_NAME \\
                 --file $envFile; \\
-            conda-pack \
+            conda-pack --ignore-missing-files \
                 -n $MLSERVER_ENV_NAME \\
                 -o $MLSERVER_ENV_TARBALL; \\
         fi \\


Test patch: