Skip to content

Instantly share code, notes, and snippets.

@ixobert
Created September 30, 2021 00:47
Show Gist options
  • Save ixobert/4448bb25e1fbdba66c8818979ce6ab62 to your computer and use it in GitHub Desktop.
Save ixobert/4448bb25e1fbdba66c8818979ce6ab62 to your computer and use it in GitHub Desktop.
determined-ai-toolchain
#!/bin/sh
uid="$(id -u)"
user="$(id -un)"
dockergid="$(getent group docker | cut -f3 -d:)"
if [ "$*" == "--image" ] ; then
# rebuild the docker container containing the toolchain
docker build -t determined-toolchain - << EOF
FROM ubuntu:20.04
RUN apt-get update -y \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y \
build-essential \
curl \
docker.io \
golang-1.16 \
golang-google-genproto-dev \
golang-goprotobuf-dev \
golang-grpc-gateway \
jq \
openjdk-11-jre-headless \
protobuf-compiler \
python3 \
python3-pip \
sudo \
vim \
wget \
&& ln -s /usr/bin/python3 /usr/local/bin/python
ENV PATH="\$PATH:/usr/lib/go-1.16/bin"
# # Alternative: install go via direct download
# RUN wget -q https://dl.google.com/go/go1.16.3.linux-amd64.tar.gz \
# && tar -C /usr/local/ -xzf go1.16.3.linux-amd64.tar.gz \
# && rm go1.16.3.linux-amd64.tar.gz
# ENV PATH="/usr/local/go/bin:\$PATH"
# # Alternative: install protoc from source
# RUN wget -q https://github.com/protocolbuffers/protobuf/releases/download/v3.12.3/protobuf-all-3.12.3.tar.gz \
# && tar -xzf protobuf-all-3.12.3.tar.gz \
# && cd protobuf-3.12.3 \
# && ./configure \
# && make PREFIX=/usr/local install \
# && cd .. \
# && rm -r protobuf-3.12.3 protobuf-all-3.12.3.tar.gz
# Install helm
RUN curl -fsSL https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
# Install node via nvm
ENV NVM_DIR="/usr/local/nvm"
ENV NODE_VERSION="14.18.0"
ENV PATH="\$PATH:\$NVM_DIR/versions/node/v\$NODE_VERSION/bin"
RUN mkdir -p "\$NVM_DIR" && curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
# Configure a form of non-root support for this container.
ARG UID
ARG USER
ARG DOCKERGID
RUN useradd -s /bin/bash --no-create-home -u $uid $user \
&& echo "$user ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers \
&& sed -i -e "s/docker:x:[0-9]*:/docker:x:$dockergid:$user/" /etc/group
ENV HOME="/home/$user"
ENV PATH="/home/$user/.local/bin:\$PATH"
ENV PATH="/home/$user/go/bin:\$PATH"
# Expect the Determined repo to be mounted into /mnt.
WORKDIR /mnt
EOF
# done
exit 0
fi
# normal behavior: use the toolchain to execute some command
cache="$HOME/.toolchain-cache"
mkdir -p "$cache"
# figure out where we are in a determined repo
repo="$(git rev-parse --show-toplevel)" || exit 1
repo_pwd="$(git rev-parse --show-prefix)" || exit 2
runtoolchain () {
docker run \
--rm --network host -it \
-v /var/run/docker.sock:/var/run/docker.sock \
-u "$uid:$dockergid" \
-v "$cache:/home/$user" \
-v "$repo":/mnt \
-w "/mnt/$repo_pwd" \
determined-toolchain "$@"
}
if [ "$#" -eq 1 ] ; then
# allow short shell snippets
runtoolchain bash -c "$1"
else
# allow normal commands
runtoolchain "$@"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment