-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathoci-image-build.sh
57 lines (52 loc) · 1.79 KB
/
oci-image-build.sh
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
# Parse script options
while [[ $# -gt 0 ]]; do
case $1 in
-r|--runtime)
RUNTIME="$2"
shift # past argument
shift # past value
;;
-*|--*)
echo "Unknown option $1"
exit 1
;;
esac
done
if [[ -z ${RUNTIME} ]]; then
echo "Error: --runtime option is required, please choose in {docker, podman}."
exit 2
elif [[ ${RUNTIME} = "podman" ]]; then
RUNTIME=$(which podman)
OPTIONS="--storage-opt overlay.mount_program=/usr/bin/fuse-overlayfs"
elif [[ ${RUNTIME} = "docker" ]]; then
RUNTIME=$(which docker)
else
echo "runtime \"${RUNTIME}\" not supported, please choose in {docker, podman}."
exit 3
fi
# Automatically retrieve the CUDA and torch version from env var, otherwise set them from reference file env.yaml
if [[ -z "${PY4CAST_CUDA_VERSION}" ]]; then
PY4CAST_CUDA_VERSION=$(cat env.yaml | grep pytorch-cuda= | sed 's/.*pytorch-cuda=\([0-9]*\.[0-9]\).*/\1/')
else
echo "PY4CAST_CUDA_VERSION version found in the environment: ${PY4CAST_CUDA_VERSION}"
fi
if [[ -z "${PY4CAST_TORCH_VERSION}" ]]; then
PY4CAST_TORCH_VERSION=$(cat env.yaml | grep torch== | sed 's/.*torch==\([0-9]\.[0-9]\.[0-9]\).*/\1/')
else
echo "PY4CAST_TORCH_VERSION version found in the environment: ${PY4CAST_TORCH_VERSION}"
fi
# Tag the docker image with the latest commit hash on the currrent branch
TAG=$(git rev-parse --short HEAD)
# Build the py4cast docker image
${RUNTIME} build \
${OPTIONS} \
--build-arg CUDA_VERS=${PY4CAST_CUDA_VERSION} \
--build-arg TORCH_VERS=${PY4CAST_TORCH_VERSION} \
--build-arg USERNAME=$(id -un) \
--build-arg GROUPNAME=$(id -gn) \
--build-arg USER_UID=$(id -u) \
--build-arg USER_GUID=$(id -g) \
--build-arg HOME_DIR=${HOME} \
--build-arg INJECT_MF_CERT=${INJECT_MF_CERT} \
--tag py4cast:${TAG} \
.