Skip to content

Commit

Permalink
[Core] Disable conda activate for custom docker image as runtime envi…
Browse files Browse the repository at this point in the history
…ronment (#3874)

* fix

* fix in cmd runner as well

* fix

* add comments
  • Loading branch information
cblmemo authored Aug 29, 2024
1 parent 3582637 commit bd40b93
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
5 changes: 4 additions & 1 deletion sky/backends/backend_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,9 @@ def write_cluster_config(
f'open(os.path.expanduser("{constants.SKY_REMOTE_RAY_PORT_FILE}"), "w", encoding="utf-8"))\''
)

conda_auto_activate = ('true' if to_provision.extract_docker_image() is None
else 'false')

# Use a tmp file path to avoid incomplete YAML file being re-used in the
# future.
tmp_yaml_path = yaml_path + '.tmp'
Expand Down Expand Up @@ -917,7 +920,7 @@ def write_cluster_config(

# Conda setup
'conda_installation_commands':
constants.CONDA_INSTALLATION_COMMANDS,
constants.CONDA_INSTALLATION_COMMANDS(conda_auto_activate),
# We should not use `.format`, as it contains '{}' as the bash
# syntax.
'ray_skypilot_installation_commands':
Expand Down
10 changes: 6 additions & 4 deletions sky/skylet/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@
# https://github.com/ray-project/ray/issues/31606
# We use python 3.10 to be consistent with the python version of the
# AWS's Deep Learning AMI's default conda environment.
CONDA_INSTALLATION_COMMANDS = (
# Using lambda instead of str.format() since there are multiple {} in the
# installation commands and we only want to replace some of them.
CONDA_INSTALLATION_COMMANDS = lambda conda_auto_activate: (
'which conda > /dev/null 2>&1 || '
'{ curl https://repo.anaconda.com/miniconda/Miniconda3-py310_23.11.0-2-Linux-x86_64.sh -o Miniconda3-Linux-x86_64.sh && ' # pylint: disable=line-too-long
# We do not use && for installation of conda and the following init commands
Expand All @@ -135,8 +137,8 @@
# true.
'{ bash Miniconda3-Linux-x86_64.sh -b; '
'eval "$(~/miniconda3/bin/conda shell.bash hook)" && conda init && '
'conda config --set auto_activate_base true && '
f'conda activate base; }}; }}; '
f'conda config --set auto_activate_base {conda_auto_activate} && '
'conda activate base; }; }; '
'grep "# >>> conda initialize >>>" ~/.bashrc || '
'{ conda init && source ~/.bashrc; };'
# If Python version is larger then equal to 3.12, create a new conda env
Expand All @@ -145,7 +147,7 @@
# costly to create a new conda env, and venv should be a lightweight and
# faster alternative when the python version satisfies the requirement.
'[[ $(python3 --version | cut -d " " -f 2 | cut -d "." -f 2) -ge 12 ]] && '
f'echo "Creating conda env with Python 3.10" && '
'echo "Creating conda env with Python 3.10" && '
f'conda create -y -n {SKY_REMOTE_PYTHON_ENV_NAME} python=3.10 && '
f'conda activate {SKY_REMOTE_PYTHON_ENV_NAME};'
# Create a separate conda environment for SkyPilot dependencies.
Expand Down

0 comments on commit bd40b93

Please sign in to comment.