forked from Kaggle/kagglehub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker-hatch
executable file
·72 lines (62 loc) · 1.93 KB
/
docker-hatch
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
#!/bin/bash
set -e
PYTHON_VERSION='3.11.6' # Default Python version to use.
CACHE_FLAG=''
usage() {
cat << EOF
Usage: $0 [OPTIONS] HATCH-OPTIONS-COMMAND-ARGS
Run the given HATCH-OPTIONS-COMMAND-ARGS in a container.
Options:
-h, --help Show documentation on how to use $0
-v, --python-version PYTHON-VERSION Run in a container using this specfic Python version.
Valid versions are tags of the \`python\` Docker image: https://hub.docker.com/_/python
-f, --force-rebuild-docker-image Force re-build the Docker image.
EOF
}
while :; do
case "$1" in
-h|--help)
usage
exit
;;
-v|--python-version)
if [[ -z $2 ]]; then
usage
printf 'ERROR: No PYTHON-VERSION specified after the %s flag.\n' "$1" >&2
exit
fi
PYTHON_VERSION=$2
shift # skip the flag value
;;
-f|--force-rebuild-docker-image)
CACHE_FLAG='--no-cache'
;;
# Use this marker to indicate that the rest of the command is for hatch
--)
shift # skip this one to pass the rest to hatch
break
;;
-?*)
usage
printf 'ERROR: Unknown option: %s\n' "$1" >&2
exit
;;
*)
break
esac
shift
done
DOCKER_IMAGE="kagglehub-docker-hatch:${PYTHON_VERSION}"
readonly PYTHON_VERSION
readonly DOCKER_IMAGE
readonly CACHE_FLAG
echo "Running 'hatch $@' inside a Docker container using Python ${PYTHON_VERSION}"
docker build -f Dockerfile \
-t ${DOCKER_IMAGE} \
${CACHE_FLAG} \
--cache-from ${DOCKER_IMAGE} \
--build-arg PYTHON_VERSION=${PYTHON_VERSION} \
--quiet \
.
set -x
docker run --rm -v $PWD:/working -v ~/.kaggle:/root/.kaggle -w /working ${DOCKER_IMAGE} "$@"