From 0f2a9f8990d0eaf65997267bd38ff9d76b4c2f95 Mon Sep 17 00:00:00 2001 From: Michael Chiou <156848643+ttmchiou@users.noreply.github.com> Date: Thu, 16 May 2024 16:16:08 -0700 Subject: [PATCH] #7944: add convenience script that installs docker deps and compose (#8566) --- scripts/docker/build_docker_image.sh | 9 ++++ scripts/docker/run_docker_cmd.sh | 25 ++++++++++++ scripts/docker/run_docker_func.sh | 61 ++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100755 scripts/docker/build_docker_image.sh create mode 100755 scripts/docker/run_docker_cmd.sh create mode 100755 scripts/docker/run_docker_func.sh diff --git a/scripts/docker/build_docker_image.sh b/scripts/docker/build_docker_image.sh new file mode 100755 index 00000000000..82df50664e4 --- /dev/null +++ b/scripts/docker/build_docker_image.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +TT_METAL_DOCKER_IMAGE_TAG=${1:-ubuntu-20.04-amd64:latest} + +TT_METAL_HOME=$(git rev-parse --show-toplevel) +( + cd ${TT_METAL_HOME} || exit + docker build -f dockerfile/ubuntu-20.04-x86.Dockerfile -t ${TT_METAL_DOCKER_IMAGE_TAG} . +) \ No newline at end of file diff --git a/scripts/docker/run_docker_cmd.sh b/scripts/docker/run_docker_cmd.sh new file mode 100755 index 00000000000..e62ee429803 --- /dev/null +++ b/scripts/docker/run_docker_cmd.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +set -e + +if [[ -z "${TT_METAL_DOCKER_IMAGE_TAG}" ]]; then + echo "TT_METAL_DOCKER_IMAGE_TAG is not set or is empty, setting to ubuntu-20.04-amd64:latest" + TT_METAL_DOCKER_IMAGE_TAG="ubuntu-20.04-amd64:latest" +else + echo "TT_METAL_DOCKER_IMAGE_TAG is set to ${TT_METAL_DOCKER_IMAGE_TAG}" +fi + +if [[ -z "${ARCH_NAME}" ]]; then + echo "Must provide ARCH_NAME in environment" 1>&2 + exit 1 +fi + +if [[ $# -eq 0 ]] ; then + echo 'You must provide an argument to run in docker!' + exit 1 +fi +TT_METAL_HOME=$(git rev-parse --show-toplevel) +# Allows this script to be called anywhere in the tt-metal repo +source $TT_METAL_HOME/scripts/docker/run_docker_func.sh + +run_docker_common "$@" diff --git a/scripts/docker/run_docker_func.sh b/scripts/docker/run_docker_func.sh new file mode 100755 index 00000000000..5db7f6133e0 --- /dev/null +++ b/scripts/docker/run_docker_func.sh @@ -0,0 +1,61 @@ +#!/bin/bash + +set -e + +if [[ -z "${TT_METAL_DOCKER_IMAGE_TAG}" ]]; then + echo "TT_METAL_DOCKER_IMAGE_TAG is not set or is empty, setting to ubuntu-20.04-amd64:latest" + TT_METAL_DOCKER_IMAGE_TAG="ubuntu-20.04-amd64:latest" +else + echo "TT_METAL_DOCKER_IMAGE_TAG is set to ${TT_METAL_DOCKER_IMAGE_TAG}" +fi + +GID=$(id -g "${USER}") + +if [[ -z "${TT_METAL_HOME}" ]]; then + TT_METAL_HOME=$(git rev-parse --show-toplevel) +else + echo "TT_METAL_DOCKER_IMAGE_TAG is set to ${TT_METAL_DOCKER_IMAGE_TAG}" +fi + +[ -d ${TT_METAL_HOME}/.pipcache ] || mkdir ${TT_METAL_HOME}/.pipcache + +function run_docker_common { + # Split the arguments into docker options and command + local docker_opts=() + local cmd=() + local append_cmd=false + for arg in "$@"; do + if $append_cmd; then + cmd+=("$arg") + elif [[ $arg == "--" && $append_cmd == false ]]; then + append_cmd=true + else + docker_opts+=("$arg") + fi + done + + docker run \ + --rm \ + -v ${TT_METAL_HOME}:/${TT_METAL_HOME} \ + -v /home:/home \ + -v /dev/hugepages-1G:/dev/hugepages-1G \ + -v /etc/group:/etc/group:ro \ + -v /etc/passwd:/etc/passwd:ro \ + -v /etc/shadow:/etc/shadow:ro \ + -w ${TT_METAL_HOME} \ + -e TT_METAL_HOME=${TT_METAL_HOME} \ + -e TT_METAL_ENV=${TT_METAL_ENV} \ + -e LOGURU_LEVEL=${LOGURU_LEVEL} \ + -e LD_LIBRARY_PATH=${LD_LIBRARY_PATH} \ + -e CONFIG=${CONFIG} \ + -e ARCH_NAME=${ARCH_NAME} \ + -e PYTHONPATH=${TT_METAL_HOME} \ + -e XDG_CACHE_HOME=${TT_METAL_HOME}/.pipcache \ + -e SILENT=${SILENT} \ + -e VERBOSE=${VERBOSE} \ + -u ${UID}:${GID} \ + --net host \ + "${docker_opts[@]}" \ + ${TT_METAL_DOCKER_IMAGE_TAG} \ + "${cmd[@]}" +}