Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] Disable conda activate for custom docker image as runtime environment #3874

Merged
merged 5 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion sky/provision/docker_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ def docker_start_cmds(
'--cap-add=SYS_ADMIN',
'--device=/dev/fuse',
'--security-opt=apparmor:unconfined',
'--entrypoint=/bin/bash',
image,
'bash',
]
return ' '.join(docker_run)

Expand Down
8 changes: 4 additions & 4 deletions sky/skylet/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
# 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 = (
CONDA_INSTALLATION_COMMANDS = lambda conda_auto_activate: (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Can we just use .format for this purpose? Having a lambda function in the constants.py is a bit weird.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually tried, but .format does not work for those {} in the installation commands..

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, in that case, let's have a comment here for why we use lambda function here. : )

'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 +135,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 +145,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
2 changes: 1 addition & 1 deletion sky/skylet/providers/command_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ def docker_start_cmds(
'--cap-add=SYS_ADMIN',
'--device=/dev/fuse',
'--security-opt=apparmor:unconfined',
'--entrypoint=/bin/bash',
image,
'bash',
]
return ' '.join(docker_run)

Expand Down
Loading