Skip to content

Commit

Permalink
update image generation to use uv
Browse files Browse the repository at this point in the history
  • Loading branch information
cg505 committed Nov 23, 2024
1 parent 204d979 commit 4b85424
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 35 deletions.
11 changes: 6 additions & 5 deletions Dockerfile_k8s
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ ENV HOME /home/sky
WORKDIR /home/sky

# Install skypilot dependencies
RUN conda init && export PIP_DISABLE_PIP_VERSION_CHECK=1 && \
python3 -m venv ~/skypilot-runtime && \
PYTHON_EXEC=$(echo ~/skypilot-runtime)/bin/python && \
$PYTHON_EXEC -m pip install 'skypilot-nightly[remote,kubernetes]' 'ray[default]==2.9.3' 'pycryptodome==3.12.0' && \
$PYTHON_EXEC -m pip uninstall skypilot-nightly -y && \
RUN curl -LsSf https://astral.sh/uv/install.sh | UV_INSTALL_DIR=$HOME/.local/bin sh && \
export PATH=$PATH:$HOME/.local/bin && \
conda init && uv venv --seed ~/skypilot-runtime && \
UV_PIP_EXEC="env VIRTUAL_ENV=$(echo ~/skypilot-runtime) uv pip" && \
$UV_PIP_EXEC install 'skypilot-nightly[remote,kubernetes]' 'ray[default]==2.9.3' 'pycryptodome==3.12.0' && \
$UV_PIP_EXEC uninstall skypilot-nightly && \
curl -LO "https://dl.k8s.io/release/v1.28.11/bin/linux/amd64/kubectl" && \
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl && \
echo 'export PATH="$PATH:$HOME/.local/bin"' >> ~/.bashrc
Expand Down
11 changes: 6 additions & 5 deletions Dockerfile_k8s_gpu
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ RUN curl https://repo.anaconda.com/miniconda/Miniconda3-py310_23.11.0-2-Linux-x8
eval "$(~/miniconda3/bin/conda shell.bash hook)" && conda init && conda config --set auto_activate_base true && conda activate base && \
grep "# >>> conda initialize >>>" ~/.bashrc || { conda init && source ~/.bashrc; } && \
rm Miniconda3-Linux-x86_64.sh && \
export PIP_DISABLE_PIP_VERSION_CHECK=1 && \
python3 -m venv ~/skypilot-runtime && \
PYTHON_EXEC=$(echo ~/skypilot-runtime)/bin/python && \
$PYTHON_EXEC -m pip install 'skypilot-nightly[remote,kubernetes]' 'ray[default]==2.9.3' 'pycryptodome==3.12.0' && \
$PYTHON_EXEC -m pip uninstall skypilot-nightly -y && \
curl -LsSf https://astral.sh/uv/install.sh | UV_INSTALL_DIR=$HOME/.local/bin sh && \
export PATH=$PATH:$HOME/.local/bin && \
uv venv --seed ~/skypilot-runtime && \
UV_PIP_EXEC="env VIRTUAL_ENV=$(echo ~/skypilot-runtime) uv pip" && \
$UV_PIP_EXEC install 'skypilot-nightly[remote,kubernetes]' 'ray[default]==2.9.3' 'pycryptodome==3.12.0' && \
$UV_PIP_EXEC uninstall skypilot-nightly && \
curl -LO "https://dl.k8s.io/release/v1.28.11/bin/linux/amd64/kubectl" && \
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl && \
echo 'export PATH="$PATH:$HOME/.local/bin"' >> ~/.bashrc
Expand Down
14 changes: 7 additions & 7 deletions docs/source/reference/kubernetes/kubernetes-getting-started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ FAQs
* **Are autoscaling Kubernetes clusters supported?**

To run on autoscaling clusters, set the :code:`provision_timeout` key in :code:`~/.sky/config.yaml` to a large value to give enough time for the cluster autoscaler to provision new nodes.
This will direct SkyPilot to wait for the cluster to scale up before failing over to the next candidate resource (e.g., next cloud).
This will direct SkyPilot to wait for the cluster to scale up before failing over to the next candidate resource (e.g., next cloud).

If you are using GPUs in a scale-to-zero setting, you should also set the :code:`autoscaler` key to the autoscaler type of your cluster. More details in :ref:`config-yaml`.

Expand Down Expand Up @@ -344,12 +344,12 @@ FAQs
eval "$(~/miniconda3/bin/conda shell.bash hook)" && conda init && conda config --set auto_activate_base true && conda activate base && \
grep "# >>> conda initialize >>>" ~/.bashrc || { conda init && source ~/.bashrc; } && \
rm Miniconda3-Linux-x86_64.sh && \
export PIP_DISABLE_PIP_VERSION_CHECK=1 && \
python3 -m venv ~/skypilot-runtime && \
PYTHON_EXEC=$(echo ~/skypilot-runtime)/bin/python && \
$PYTHON_EXEC -m pip install 'skypilot-nightly[remote,kubernetes]' 'ray[default]==2.9.3' 'pycryptodome==3.12.0' && \
$PYTHON_EXEC -m pip uninstall skypilot-nightly -y && \
curl -LsSf https://astral.sh/uv/install.sh | UV_INSTALL_DIR=$HOME/.local/bin sh && \
export PATH=$PATH:$HOME/.local/bin && \
uv venv --seed ~/skypilot-runtime && \
UV_PIP_EXEC="env VIRTUAL_ENV=$(echo ~/skypilot-runtime) uv pip" && \
$UV_PIP_EXEC install 'skypilot-nightly[remote,kubernetes]' 'ray[default]==2.9.3' 'pycryptodome==3.12.0' && \
$UV_PIP_EXEC uninstall skypilot-nightly && \
curl -LO "https://dl.k8s.io/release/v1.28.11/bin/linux/amd64/kubectl" && \
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl && \
echo 'export PATH="$PATH:$HOME/.local/bin"' >> ~/.bashrc
5 changes: 3 additions & 2 deletions sky/clouds/service_catalog/images/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ You only need to do this once.
```bash
packer init plugins.pkr.hcl
```
3. Setup cloud credentials
4. `cd sky/clouds/service_catalog/images`
3. Check that docker buildx is installed: `docker buildx` should show a help page. buildx is installed with Docker Desktop but you may have to install separately on Linux.
4. Setup cloud credentials
5. `cd sky/clouds/service_catalog/images`

## Generate Images
FYI time to packer build images:
Expand Down
9 changes: 9 additions & 0 deletions sky/clouds/service_catalog/images/plugins.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,12 @@ packer {
}
}
}

packer {
required_plugins {
azure = {
source = "github.com/hashicorp/azure"
version = "~> 2"
}
}
}
25 changes: 14 additions & 11 deletions sky/clouds/service_catalog/images/provisioners/skypilot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,36 +32,39 @@ conda init
conda config --set auto_activate_base true
conda activate base

# Conda, Python
# Install uv
curl -LsSf https://astral.sh/uv/install.sh | UV_INSTALL_DIR=$HOME/.local/bin sh
export PATH=$PATH:$HOME/.local/bin

# Set up Conda, uv, Python
echo "Creating conda env with Python 3.10"
conda create -y -n skypilot-runtime python=3.10
conda activate skypilot-runtime
export PIP_DISABLE_PIP_VERSION_CHECK=1
echo PATH=$PATH
python3 -m venv ~/skypilot-runtime
uv venv --seed ~/skypilot-runtime
PYTHON_EXEC=$(echo ~/skypilot-runtime)/bin/python
UV_EXEC_PIP="env VIRTUAL_ENV=$(echo ~/skypilot-runtime) uv pip"

# Install SkyPilot
$PYTHON_EXEC -m pip install "skypilot-nightly[remote]"
$UV_EXEC_PIP install "skypilot-nightly[remote]"

# Install Ray
RAY_ADDRESS=127.0.0.1:6380
$PYTHON_EXEC -m pip install --exists-action w -U "ray[default]==2.9.3"
export PATH=$PATH:$HOME/.local/bin
$UV_EXEC_PIP install -U "ray[default]==2.9.3"
source ~/skypilot-runtime/bin/activate
which ray > ~/.sky/ray_path || exit 1
$PYTHON_EXEC -m pip list | grep "ray " | grep 2.9.3 2>&1 > /dev/null && {
$UV_EXEC_PIP list | grep "ray " | grep 2.9.3 2>&1 > /dev/null && {
$PYTHON_EXEC -c "from sky.skylet.ray_patches import patch; patch()" || exit 1
}

# Install cloud dependencies
if [ "$CLOUD" = "azure" ]; then
$PYTHON_EXEC -m pip install "skypilot-nightly[azure]"
$UV_EXEC_PIP install "skypilot-nightly[azure]"
elif [ "$CLOUD" = "gcp" ]; then
# We don't have to install the google-cloud-sdk since it is installed by default in GCP machines.
$PYTHON_EXEC -m pip install "skypilot-nightly[gcp]"
$UV_EXEC_PIP install "skypilot-nightly[gcp]"
elif [ "$CLOUD" = "aws" ]; then
$PYTHON_EXEC -m pip install "skypilot-nightly[aws]"
$UV_EXEC_PIP install "skypilot-nightly[aws]"
else
echo "Error: Unknown cloud $CLOUD so not installing any cloud dependencies."
fi
Expand All @@ -81,5 +84,5 @@ sudo systemctl disable jupyter > /dev/null 2>&1 || true

# Cleanup
# Remove SkyPilot in OS image because when user sky launch we will install whatever version of SkyPilot user has on their local machine.
$PYTHON_EXEC -m pip uninstall "skypilot-nightly" -y
$UV_EXEC_PIP uninstall "skypilot-nightly"
rm -rf ~/.sky
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

eval "$(~/miniconda3/bin/conda shell.bash hook)"
conda activate base
pip install numpy
pip install pandas

export PATH=$PATH:$HOME/.local/bin
uv pip install numpy
uv pip install pandas

if [ "$AZURE_GRID_DRIVER" = 1 ]; then
# Need PyTorch X.X.X+cu121 version to be compatible with older NVIDIA driver (535.161.08 or lower)
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
uv pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
fi
4 changes: 2 additions & 2 deletions sky/skylet/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,15 @@
f'conda create -y -n {SKY_REMOTE_PYTHON_ENV_NAME} python=3.10 && '
f'conda activate {SKY_REMOTE_PYTHON_ENV_NAME};'
# Install uv for venv management and pip installation.
'which uv >/dev/null 2>&1 || '
f'{SKY_UV_INSTALL_DIR}/uv --version >/dev/null 2>&1 || '
'curl -LsSf https://astral.sh/uv/install.sh '
f'| UV_INSTALL_DIR={SKY_UV_INSTALL_DIR} sh;'
# Create a separate conda environment for SkyPilot dependencies.
f'[ -d {SKY_REMOTE_PYTHON_ENV} ] || '
# Do NOT use --system-site-packages here, because if users upgrade any
# packages in the base env, they interfere with skypilot dependencies.
# Reference: https://github.com/skypilot-org/skypilot/issues/4097
f'{SKY_UV_CMD} venv {SKY_REMOTE_PYTHON_ENV};'
f'{SKY_UV_CMD} venv --seed {SKY_REMOTE_PYTHON_ENV};'
f'echo "$(echo {SKY_REMOTE_PYTHON_ENV})/bin/python" > {SKY_PYTHON_PATH_FILE};'
)

Expand Down

0 comments on commit 4b85424

Please sign in to comment.