forked from Kaggle/docker-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build
executable file
·74 lines (63 loc) · 1.8 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
66
67
68
69
70
71
72
73
74
#!/bin/bash
set -e
usage() {
cat << EOF
Usage: $0 [OPTIONS]
Build a new Python Docker image.
Options:
-g, --gpu Build an image with GPU support.
-c, --use-cache Use layer cache when building a new image.
EOF
}
CACHE_FLAG='--no-cache'
DOCKERFILE='Dockerfile'
ACCELERATOR='none'
IMAGE_TAG='kaggle/python-build'
BUILD_ARGS=''
while :; do
case "$1" in
-h|--help)
usage
exit
;;
-g|--gpu)
IMAGE_TAG='kaggle/python-gpu-build'
DOCKERFILE='gpu.Dockerfile'
ACCELERATOR='gpu'
;;
-c|--use-cache)
CACHE_FLAG=''
;;
-?*)
usage
printf 'ERROR: Unknown option: %s\n' "$1" >&2
exit
;;
*)
break
esac
shift
done
BUILD_ARGS+=" --build-arg GIT_COMMIT=$(git rev-parse HEAD)"
BUILD_ARGS+=" --build-arg BUILD_DATE=$(date '+%Y%m%d-%H%M%S')"
# Read build args from config.txt file.
SRCDIR=$(dirname "${BASH_SOURCE[0]}")
for l in `cat ${SRCDIR}/config.txt`; do
BUILD_ARGS+=" --build-arg $l"
done
readonly CACHE_FLAG
readonly DOCKERFILE
readonly ACCELERATOR
readonly IMAGE_TAG
readonly BUILD_ARGS
DOCKERFILE_OUTDIR="${SRCDIR}/.generated"
mkdir -p $DOCKERFILE_OUTDIR
DOCKERFILE_PATH="$DOCKERFILE_OUTDIR/$DOCKERFILE"
# Generate Dockerfile from template.
echo "Generating Dockerfile from template..."
docker run --rm -v $PWD:/input:ro gcr.io/kaggle-images/go-renderizer:latest --ACCELERATOR=$ACCELERATOR /input/Dockerfile.tmpl > $DOCKERFILE_PATH
echo "==================== $DOCKERFILE START ===================="
cat $DOCKERFILE_PATH
echo "==================== $DOCKERFILE END ===================="
set -x
docker build --rm --pull $CACHE_FLAG -t "$IMAGE_TAG" -f "$DOCKERFILE_PATH" $BUILD_ARGS .