prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN 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
  ```
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `mlserver/cli/constants.py`
  Content:
  ```
  1 DockerfileName = "Dockerfile"
  2 DockerfileTemplate = """
  3 FROM continuumio/miniconda3:4.10.3 AS env-builder
  4 SHELL ["/bin/bash", "-c"]
  5 
  6 ARG MLSERVER_ENV_NAME="mlserver-custom-env" \\
  7     MLSERVER_ENV_TARBALL="./envs/base.tar.gz"
  8 
  9 RUN conda config --add channels conda-forge && \\
  10     conda install conda-pack
  11 
  12 # The `[]` character range will ensure that Docker doesn't complain if the
  13 # files don't exist:
  14 # https://stackoverflow.com/a/65138098/5015573
  15 COPY \\
  16     ./environment.ym[l] \\
  17     ./environment.yam[l] \\
  18     ./conda.ym[l] \\
  19     ./conda.yam[l] \\
  20     .
  21 RUN mkdir $(dirname $MLSERVER_ENV_TARBALL); \\
  22     for envFile in environment.yml environment.yaml conda.yml conda.yaml; do \\
  23         if [[ -f $envFile ]]; then \\
  24             conda env create \
  25                 --name $MLSERVER_ENV_NAME \\
  26                 --file $envFile; \\
  27             conda-pack \
  28                 -n $MLSERVER_ENV_NAME \\
  29                 -o $MLSERVER_ENV_TARBALL; \\
  30         fi \\
  31     done; \\
  32     chmod -R 776 $(dirname $MLSERVER_ENV_TARBALL)
  33 
  34 FROM seldonio/mlserver:{version}-slim
  35 SHELL ["/bin/bash", "-c"]
  36 
  37 # Copy all potential sources for custom environments
  38 COPY \\
  39     --chown=1000 \\
  40     --from=env-builder \\
  41     /envs/base.tar.g[z] \\
  42     ./envs/base.tar.gz
  43 COPY \\
  44     ./settings.jso[n] \\
  45     ./model-settings.jso[n] \\
  46     ./requirements.tx[t] \\
  47     .
  48 
  49 USER root
  50 # Install dependencies system-wide, to ensure that they are available for every
  51 # user
  52 RUN ./hack/build-env.sh . ./envs/base && \
  53     chown -R 1000:0 ./envs/base && \\
  54     chmod -R 776 ./envs/base
  55 USER 1000
  56 
  57 # Copy everything else
  58 COPY . .
  59 
  60 # Override MLServer's own `CMD` to activate the embedded environment
  61 # (optionally activating the hot-loaded one as well).
  62 CMD source ./hack/activate-env.sh ./envs/base.tar.gz ./envs/base && \\
  63     mlserver start $MLSERVER_MODELS_DIR
  64 """
  65 
  66 DockerignoreName = ".dockerignore"
  67 Dockerignore = """
  68 # Binaries for programs and plugins
  69 *.exe
  70 *.exe~
  71 *.dll
  72 *.so
  73 *.dylib
  74 *.pyc
  75 *.pyo
  76 *.pyd
  77 bin
  78 
  79 # Mac file system
  80 **/.DS_Store
  81 
  82 # Python dev
  83 __pycache__
  84 .Python
  85 env
  86 pip-log.txt
  87 pip-delete-this-directory.txt
  88 .mypy_cache
  89 eggs/
  90 .eggs/
  91 *.egg-info/
  92 ./pytest_cache
  93 .tox
  94 build/
  95 dist/
  96 
  97 # Notebook Checkpoints
  98 .ipynb_checkpoints
  99 
  100 .coverage
  101 .coverage.*
  102 .cache
  103 nosetests.xml
  104 coverage.xml
  105 *,cover
  106 *.log
  107 .git
  108 """
  109
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: 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 \\
  
verification_info: {"golden_diff": "diff --git a/mlserver/cli/constants.py b/mlserver/cli/constants.py\n--- a/mlserver/cli/constants.py\n+++ b/mlserver/cli/constants.py\n@@ -24,7 +24,7 @@\n             conda env create \\\n                 --name $MLSERVER_ENV_NAME \\\\\n                 --file $envFile; \\\\\n-            conda-pack \\\n+            conda-pack --ignore-missing-files \\\n                 -n $MLSERVER_ENV_NAME \\\\\n                 -o $MLSERVER_ENV_TARBALL; \\\\\n         fi \\\\\n", "issue": "Activating custom conda env in mlserver build image\nHello,\r\nI\u2019ve 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.\r\n\r\n```\r\n--> Sourcing new environment at ./envs/base/environment...\r\n\r\n--> Calling conda-unpack...\r\n\r\n--> Disabling user-installed packages...\r\n\r\nTraceback (most recent call last):\r\n\r\n  File \"/opt/mlserver/envs/base/environment/bin/mlserver\", line 8, in <module>\r\n\r\n    sys.exit(main())\r\n\r\n  File \"/usr/local/lib/python3.8/site-packages/mlserver/cli/main.py\", line 76, in main\r\n\r\n    root()\r\n\r\n  File \"/usr/local/lib/python3.8/site-packages/click/core.py\", line 1128, in __call__\r\n\r\n    return self.main(*args, **kwargs)\r\n\r\n  File \"/usr/local/lib/python3.8/site-packages/click/core.py\", line 1053, in main\r\n\r\n    rv = self.invoke(ctx)\r\n\r\n  File \"/usr/local/lib/python3.8/site-packages/click/core.py\", line 1659, in invoke\r\n\r\n    return _process_result(sub_ctx.command.invoke(sub_ctx))\r\n\r\n  File \"/usr/local/lib/python3.8/site-packages/click/core.py\", line 1395, in invoke\r\n\r\n    return ctx.invoke(self.callback, **ctx.params)\r\n\r\n  File \"/usr/local/lib/python3.8/site-packages/click/core.py\", line 754, in invoke\r\n\r\n    return __callback(*args, **kwargs)\r\n\r\n  File \"/usr/local/lib/python3.8/site-packages/mlserver/cli/main.py\", line 19, in wrapper\r\n\r\n    return asyncio.run(f(*args, **kwargs))\r\n\r\n  File \"/usr/local/lib/python3.8/asyncio/runners.py\", line 44, in run\r\n\r\n    return loop.run_until_complete(main)\r\n\r\n  File \"/usr/local/lib/python3.8/asyncio/base_events.py\", line 616, in run_until_complete\r\n\r\n    return future.result()\r\n\r\n  File \"/usr/local/lib/python3.8/site-packages/mlserver/cli/main.py\", line 40, in start\r\n\r\n    settings, models = await load_settings(folder)\r\n\r\n  File \"/usr/local/lib/python3.8/site-packages/mlserver/cli/serve.py\", line 37, in load_settings\r\n\r\n    available_models = await repository.list()\r\n\r\n  File \"/usr/local/lib/python3.8/site-packages/mlserver/repository.py\", line 37, in list\r\n\r\n    model_settings = ModelSettings()\r\n\r\n  File \"pydantic/env_settings.py\", line 36, in pydantic.env_settings.BaseSettings.__init__\r\n\r\n  File \"pydantic/main.py\", line 406, in pydantic.main.BaseModel.__init__\r\n\r\npydantic.error_wrappers.ValidationError: 1 validation error for ModelSettings\r\n\r\nimplementation\r\n\r\n  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')\r\n\r\n```\r\n\r\n- [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\r\n\r\nconda.yaml file:\r\n```\r\nchannels:\r\n- defaults\r\n- conda-forge\r\n- anaconda\r\ndependencies:\r\n- python=3.7.10\r\n- pip\r\n- gcc_linux-aarch64\r\n- gxx_linux-aarch64\r\n- pip:\r\n  - mlflow\r\n  - mlserver==0.4.0\r\n  - mlserver-mlflow==0.4.0\r\nname: conda\r\n```\n", "before_files": [{"content": "DockerfileName = \"Dockerfile\"\nDockerfileTemplate = \"\"\"\nFROM continuumio/miniconda3:4.10.3 AS env-builder\nSHELL [\"/bin/bash\", \"-c\"]\n\nARG MLSERVER_ENV_NAME=\"mlserver-custom-env\" \\\\\n    MLSERVER_ENV_TARBALL=\"./envs/base.tar.gz\"\n\nRUN conda config --add channels conda-forge && \\\\\n    conda install conda-pack\n\n# The `[]` character range will ensure that Docker doesn't complain if the\n# files don't exist:\n# https://stackoverflow.com/a/65138098/5015573\nCOPY \\\\\n    ./environment.ym[l] \\\\\n    ./environment.yam[l] \\\\\n    ./conda.ym[l] \\\\\n    ./conda.yam[l] \\\\\n    .\nRUN mkdir $(dirname $MLSERVER_ENV_TARBALL); \\\\\n    for envFile in environment.yml environment.yaml conda.yml conda.yaml; do \\\\\n        if [[ -f $envFile ]]; then \\\\\n            conda env create \\\n                --name $MLSERVER_ENV_NAME \\\\\n                --file $envFile; \\\\\n            conda-pack \\\n                -n $MLSERVER_ENV_NAME \\\\\n                -o $MLSERVER_ENV_TARBALL; \\\\\n        fi \\\\\n    done; \\\\\n    chmod -R 776 $(dirname $MLSERVER_ENV_TARBALL)\n\nFROM seldonio/mlserver:{version}-slim\nSHELL [\"/bin/bash\", \"-c\"]\n\n# Copy all potential sources for custom environments\nCOPY \\\\\n    --chown=1000 \\\\\n    --from=env-builder \\\\\n    /envs/base.tar.g[z] \\\\\n    ./envs/base.tar.gz\nCOPY \\\\\n    ./settings.jso[n] \\\\\n    ./model-settings.jso[n] \\\\\n    ./requirements.tx[t] \\\\\n    .\n\nUSER root\n# Install dependencies system-wide, to ensure that they are available for every\n# user\nRUN ./hack/build-env.sh . ./envs/base && \\\n    chown -R 1000:0 ./envs/base && \\\\\n    chmod -R 776 ./envs/base\nUSER 1000\n\n# Copy everything else\nCOPY . .\n\n# Override MLServer's own `CMD` to activate the embedded environment\n# (optionally activating the hot-loaded one as well).\nCMD source ./hack/activate-env.sh ./envs/base.tar.gz ./envs/base && \\\\\n    mlserver start $MLSERVER_MODELS_DIR\n\"\"\"\n\nDockerignoreName = \".dockerignore\"\nDockerignore = \"\"\"\n# Binaries for programs and plugins\n*.exe\n*.exe~\n*.dll\n*.so\n*.dylib\n*.pyc\n*.pyo\n*.pyd\nbin\n\n# Mac file system\n**/.DS_Store\n\n# Python dev\n__pycache__\n.Python\nenv\npip-log.txt\npip-delete-this-directory.txt\n.mypy_cache\neggs/\n.eggs/\n*.egg-info/\n./pytest_cache\n.tox\nbuild/\ndist/\n\n# Notebook Checkpoints\n.ipynb_checkpoints\n\n.coverage\n.coverage.*\n.cache\nnosetests.xml\ncoverage.xml\n*,cover\n*.log\n.git\n\"\"\"\n", "path": "mlserver/cli/constants.py"}], "after_files": [{"content": "DockerfileName = \"Dockerfile\"\nDockerfileTemplate = \"\"\"\nFROM continuumio/miniconda3:4.10.3 AS env-builder\nSHELL [\"/bin/bash\", \"-c\"]\n\nARG MLSERVER_ENV_NAME=\"mlserver-custom-env\" \\\\\n    MLSERVER_ENV_TARBALL=\"./envs/base.tar.gz\"\n\nRUN conda config --add channels conda-forge && \\\\\n    conda install conda-pack\n\n# The `[]` character range will ensure that Docker doesn't complain if the\n# files don't exist:\n# https://stackoverflow.com/a/65138098/5015573\nCOPY \\\\\n    ./environment.ym[l] \\\\\n    ./environment.yam[l] \\\\\n    ./conda.ym[l] \\\\\n    ./conda.yam[l] \\\\\n    .\nRUN mkdir $(dirname $MLSERVER_ENV_TARBALL); \\\\\n    for envFile in environment.yml environment.yaml conda.yml conda.yaml; do \\\\\n        if [[ -f $envFile ]]; then \\\\\n            conda env create \\\n                --name $MLSERVER_ENV_NAME \\\\\n                --file $envFile; \\\\\n            conda-pack --ignore-missing-files \\\n                -n $MLSERVER_ENV_NAME \\\\\n                -o $MLSERVER_ENV_TARBALL; \\\\\n        fi \\\\\n    done; \\\\\n    chmod -R 776 $(dirname $MLSERVER_ENV_TARBALL)\n\nFROM seldonio/mlserver:{version}-slim\nSHELL [\"/bin/bash\", \"-c\"]\n\n# Copy all potential sources for custom environments\nCOPY \\\\\n    --chown=1000 \\\\\n    --from=env-builder \\\\\n    /envs/base.tar.g[z] \\\\\n    ./envs/base.tar.gz\nCOPY \\\\\n    ./settings.jso[n] \\\\\n    ./model-settings.jso[n] \\\\\n    ./requirements.tx[t] \\\\\n    .\n\nUSER root\n# Install dependencies system-wide, to ensure that they are available for every\n# user\nRUN ./hack/build-env.sh . ./envs/base && \\\n    chown -R 1000:0 ./envs/base && \\\\\n    chmod -R 776 ./envs/base\nUSER 1000\n\n# Copy everything else\nCOPY . .\n\n# Override MLServer's own `CMD` to activate the embedded environment\n# (optionally activating the hot-loaded one as well).\nCMD source ./hack/activate-env.sh ./envs/base.tar.gz ./envs/base && \\\\\n    mlserver start $MLSERVER_MODELS_DIR\n\"\"\"\n\nDockerignoreName = \".dockerignore\"\nDockerignore = \"\"\"\n# Binaries for programs and plugins\n*.exe\n*.exe~\n*.dll\n*.so\n*.dylib\n*.pyc\n*.pyo\n*.pyd\nbin\n\n# Mac file system\n**/.DS_Store\n\n# Python dev\n__pycache__\n.Python\nenv\npip-log.txt\npip-delete-this-directory.txt\n.mypy_cache\neggs/\n.eggs/\n*.egg-info/\n./pytest_cache\n.tox\nbuild/\ndist/\n\n# Notebook Checkpoints\n.ipynb_checkpoints\n\n.coverage\n.coverage.*\n.cache\nnosetests.xml\ncoverage.xml\n*,cover\n*.log\n.git\n\"\"\"\n", "path": "mlserver/cli/constants.py"}]}