-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.bash
executable file
·61 lines (54 loc) · 1.52 KB
/
build.bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
OWNER=miyamonz
REPOROOT="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
require() {
local NAME=$1
if [ -z ${!NAME} ] ; then
echo specify $NAME
exit 1
fi
}
require CUDA_TAG
require SUFFIX
ROOT_CONTAINER=nvidia/cuda:${CUDA_TAG}
get_base_container() {
if [[ $1 = "" ]]; then
exit 1
fi
if [[ $1 = "base-notebook" ]]; then
exit 1
fi
cat $REPOROOT/docker-stacks/${1}/Dockerfile | grep 'ARG BASE_CONTAINER' | cut -d '=' -f 2 | cut -d / -f 2
}
to_image_name() {
echo ${OWNER}/${1}-${SUFFIX}
}
to_build_arg() {
# split space and append --build-arg
echo "$@" | tr ' ' "\n" | awk '{print "--build-arg " $0}' | tr "\n" ' '
}
build() {
local NB_NAME=$1
if [[ $NB_NAME = "" ]]; then
echo notebook name required
exit 1
fi
local IMAGE_NAME=$(to_image_name $NB_NAME)
local BUILD_ARG=""
if [[ $NB_NAME = "base-notebook" ]]; then
BUILD_ARG+=" ROOT_CONTAINER=${ROOT_CONTAINER}"
BUILD_ARG+=" PYTHON_VERSION=${PYTHON_VERSION:-default}"
else
local BASE_CONTAINER=$(get_base_container $NB_NAME)
build $BASE_CONTAINER
BUILD_ARG+=" BASE_CONTAINER=$(to_image_name $BASE_CONTAINER)"
fi
BUILD_ARGS=$(to_build_arg $BUILD_ARG)
echo building $IMAGE_NAME ....
local BUILD_COMMAND="docker build ${DARGS} ${BUILD_ARGS} --rm --force-rm -t ${IMAGE_NAME}:latest $REPOROOT/docker-stacks/${NB_NAME}"
echo $BUILD_COMMAND
eval $BUILD_COMMAND
echo built $IMAGE_NAME
echo
}
build $1