Skip to content

Commit

Permalink
#7944: add convenience script that installs docker deps and compose (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ttmchiou authored May 16, 2024
1 parent 925a14e commit 0f2a9f8
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 0 deletions.
9 changes: 9 additions & 0 deletions scripts/docker/build_docker_image.sh
Original file line number Diff line number Diff line change
@@ -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} .
)
25 changes: 25 additions & 0 deletions scripts/docker/run_docker_cmd.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"
61 changes: 61 additions & 0 deletions scripts/docker/run_docker_func.sh
Original file line number Diff line number Diff line change
@@ -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[@]}"
}

0 comments on commit 0f2a9f8

Please sign in to comment.