-
Notifications
You must be signed in to change notification settings - Fork 90
/
build
executable file
·65 lines (58 loc) · 1.51 KB
/
build
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
62
63
64
65
#!/bin/bash
set -e
usage() {
cat << EOF
Usage: $0 [OPTIONS]
Build a new Docker R image.
Options:
-c, --use-cache Use layer cache when building a new image.
-g, --gpu Build an image with GPU support.
-b, --base-image-tag TAG Base image tag. Defaults to value defined in DOCKERFILE.
EOF
}
CACHE_FLAG='--no-cache'
DOCKERFILE='Dockerfile'
IMAGE_TAG='kaggle/rstats-build'
NCPUS=$(nproc || echo 1)
BUILD_ARGS=''
while :; do
case "$1" in
-h|--help)
usage
exit
;;
-c|--use-cache)
CACHE_FLAG=''
;;
-g|--gpu)
IMAGE_TAG='kaggle/rstats-gpu-build'
DOCKERFILE='gpu.Dockerfile'
;;
-b|--base-image-tag)
if [[ -z $2 ]]; then
usage
printf 'ERROR: No TAG specified after the %s flag.\n' "$1" >&2
exit
fi
BUILD_ARGS="--build-arg BASE_TAG=$2"
shift # skip the flag value
;;
-?*)
usage
printf 'ERROR: Unknown option: %s\n' "$1" >&2
exit
;;
*)
break
esac
shift
done
BUILD_ARGS+=" --build-arg ncpus=$NCPUS"
BUILD_ARGS+=" --build-arg GIT_COMMIT=$(git rev-parse HEAD)"
BUILD_ARGS+=" --build-arg BUILD_DATE_RSTATS=$(date '+%Y%m%d-%H%M%S')"
readonly CACHE_FLAG
readonly DOCKERFILE
readonly IMAGE_TAG
readonly BUILD_ARGS
set -x
docker build --rm --pull $CACHE_FLAG -t "$IMAGE_TAG" -f "$DOCKERFILE" $BUILD_ARGS .