Skip to content

Commit

Permalink
Improve micromamba setup
Browse files Browse the repository at this point in the history
  • Loading branch information
robballantyne committed Apr 11, 2024
1 parent e11ccb2 commit 02ce487
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 20 deletions.
4 changes: 2 additions & 2 deletions build/COPY_ROOT/opt/ai-dock/bin/build/layer0/amd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ if [[ -z $ROCM_VERSION ]]; then
exit 1
fi

export ROCM_VERSION="$ROCM_VERSION"
export ROCM_VERSION="${ROCM_VERSION}"
env-store ROCM_VERSION
export ROCM_LEVEL="$ROCM_LEVEL"
export ROCM_LEVEL="${ROCM_LEVEL}"
env-store ROCM_LEVEL
export PATH=/opt/rocm/bin:$PATH
env-store PATH
Expand Down
8 changes: 2 additions & 6 deletions build/COPY_ROOT/opt/ai-dock/bin/build/layer0/common.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
#!/bin/false

export MAMBA_CREATE="micromamba create --always-softlink -y -c conda-forge"
env-store MAMBA_CREATE
export MAMBA_INSTALL="micromamba install --always-softlink -y -c conda-forge"
env-store MAMBA_INSTALL

groupadd -g 1111 ai-dock
chown root.ai-dock /opt
chmod g+w /opt
Expand Down Expand Up @@ -42,6 +37,7 @@ $APT_INSTALL \
libcap2-bin \
libelf1 \
libglib2.0-0 \
libgoogle-perftools4 \
locales \
lsb-release \
lsof \
Expand Down Expand Up @@ -102,6 +98,7 @@ rm -f /etc/update-motd.d/10-help-text

# Install micromamba (conda replacement)
mkdir -p /opt/micromamba
printf "channels: [%sconda-forge]\nalways_softlink: true\n" "${CUDA_VERSION:+nvdia,}"> /opt/micromamba/.mambarc
cd /opt/micromamba
curl -Ls https://micro.mamba.pm/api/micromamba/linux-64/latest | tar -xvj bin/micromamba
micromamba shell init --shell bash --root-prefix=/opt/micromamba
Expand All @@ -112,7 +109,6 @@ mkdir -p --mode=0755 /run/sshd
chown -R root.ai-dock /var/log
chmod -R g+w /var/log
chmod -R g+s /var/log
mkdir -p /opt/ai-dock/lib/micromamba
mkdir -p /var/log/supervisor
mkdir -p /var/empty
mkdir -p /etc/rclone
Expand Down
14 changes: 5 additions & 9 deletions build/COPY_ROOT/opt/ai-dock/bin/build/layer0/nvidia.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
#!/bin/false

export CUDA_VERSION=${CUDA_VERSION}
export CUDA_VERSION="${CUDA_VERSION}"
env-store CUDA_VERSION
export CUDNN_VERSION=${CUDNN_VERSION}
export CUDNN_VERSION="${CUDNN_VERSION}"
env-store CUDNN_VERSION
export CUDA_LEVEL=${CUDA_LEVEL}
export CUDA_LEVEL="${CUDA_LEVEL}"
env-store CUDA_LEVEL
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
env-store LD_LIBRARY_PATH
export MAMBA_CREATE="micromamba create --always-softlink -y -c nvidia -c conda-forge"
env-store MAMBA_CREATE
export MAMBA_INSTALL="micromamba install --always-softlink -y -c nvidia -c conda-forge"
env-store MAMBA_INSTALL
export CUDA_STRING="$(cut -d '.' -f 1,2 <<< "${CUDA_VERSION}")"
env-store CUDA_STRING
1 change: 1 addition & 0 deletions build/COPY_ROOT/opt/ai-dock/bin/mamba-skel
32 changes: 32 additions & 0 deletions build/COPY_ROOT/opt/ai-dock/bin/mamba-skel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

env_location=$(micromamba info | grep "env location" | awk '{print $4}')

if [[ -z $env_location || $env_location == "-" ]]; then
printf "This command must be run in a micromamba environment\n"
exit 1
fi

activate_dir="${env_location}/etc/conda/activate.d"
deactivate_dir="${env_location}/etc/conda/deactivate.d"

mkdir -p "${activate_dir}"
mkdir -p "${deactivate_dir}"

# Default activation script

cat <<EOF > "${activate_dir}/10_ld.sh"
#!/bin/bash
export SYS_LD_LIBRARY_PATH="\${LD_LIBRARY_PATH}"
export LD_LIBRARY_PATH="${env_location}/lib\${SYS_LD_LIBRARY_PATH:+:\${SYS_LD_LIBRARY_PATH}}"
EOF

# Default deactivation script
cat <<EOF > "${deactivate_dir}/90_ld.sh"
#!/bin/bash
export LD_LIBRARY_PATH="\${SYS_LD_LIBRARY_PATH}"
EOF
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ function start() {
--arg listen_port "${LISTEN_PORT}" \
--arg metrics_port "${METRICS_PORT}" \
--arg proxy_port "${PROXY_PORT}" \
--arg proxy_secure "${PROXY_SECURE,,}" \
--arg service_name "${SERVICE_NAME}" \
--arg service_url "${SERVICE_URL}" \
'$ARGS.named'
Expand Down
1 change: 0 additions & 1 deletion build/COPY_ROOT/opt/ai-dock/bin/supervisor-syncthing.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ function start() {
--arg listen_port "${LISTEN_PORT}" \
--arg metrics_port "${METRICS_PORT}" \
--arg proxy_port "${PROXY_PORT}" \
--arg proxy_secure "${PROXY_SECURE,,}" \
--arg service_name "${SERVICE_NAME}" \
--arg service_url "${SERVICE_URL}" \
'$ARGS.named'
Expand Down
5 changes: 4 additions & 1 deletion build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ RUN apt-get update && \

FROM ${IMAGE_BASE}

# System libs are handled in /etc/ld.so.conf.d
# Mamba environments only to use this variable
ENV LD_LIBRARY_PATH=

COPY --from=caddybuilder /opt/caddy/ /opt/caddy/

# Determines which scripts at /opt/ai-dock/bin/build/layerX will be run by init.sh
Expand All @@ -45,7 +49,6 @@ ENV USER_PASSWORD=password
ENV USER_GROUPS=users,ai-dock,adm,sudo,audio,video,tty,cdrom,dialout,dip,fax,floppy,lp,plugdev,ssl-cert,sudo,tape,voice
ENV DEBIAN_FRONTEND=noninteractive
ENV PATH=/opt/ai-dock/bin:/opt/micromamba/bin:/opt/caddy/bin:$PATH
ENV LD_LIBRARY_PATH=/opt/ai-dock/lib/micromamba${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
ENV OPT_SYNC=
ENV PYTHONUNBUFFERED=true
ENV APT_INSTALL="apt-get install -y --no-install-recommends"
Expand Down

0 comments on commit 02ce487

Please sign in to comment.