forked from b-it-bots/docker
-
Notifications
You must be signed in to change notification settings - Fork 2
/
build_and_publish.sh
156 lines (139 loc) · 3.49 KB
/
build_and_publish.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# Build and publish images
# Copyright a2s-institute, Hochschule Bonn-Rhein-Sieg
CONTAINER_REGISTRY=""
PUBLISH="all"
IMAGE="base-gpu-notebook"
TAG="cuda11.8.0-ubuntu20.04"
show_help() {
echo "Usage: bash build-and-deploy.sh"
echo " "
echo "options:"
echo "-h, --help show brief help"
echo "-r, --registry container registry e.g. ghcr.io for GitHub container registry, default: docker hub"
echo "-p, --publish option whether to publish <all> or <latest> (default: all), all means publish all tags"
echo "-i, --image image to build or publish"
echo "-c, --tag cuda version to build cuda11.3.1-ubuntu20.04|cuda11.8.0-ubuntu20.04|all (default: all)"
}
parse_args() {
while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help)
show_help
exit 0
;;
-r|--registry)
CONTAINER_REGISTRY="$2"
shift 2
;;
-p|--publish)
PUBLISH="$2"
shift 2
;;
-i|--image)
IMAGE="$2"
shift 2
;;
-c|--tag)
TAG="$2"
TAG_PROVIDED=true
shift 2
;;
*)
echo "Invalid argument: $1"
show_help
exit 1
;;
esac
done
}
if [ -z "$CONTAINER_REGISTRY" ]
then
echo "Container registry is not set!. Using docker hub registry"
CONTAINER_REG_OWNER=quay.io/a2s-institute
else
echo "Using $CONTAINER_REGISTRY registry"
CONTAINER_REG_OWNER=$CONTAINER_REGISTRY/a2s-institute
fi
echo "Container registry/owner = $CONTAINER_REG_OWNER"
function build_and_publish_single_image {
IMAGE_DIR=$1
IMAGE_TAG=$2
PORT=$3
echo "Building docker build -t $IMAGE_TAG $IMAGE_DIR"
if ! docker build --rm --force-rm --tag $IMAGE_TAG $IMAGE_DIR; then
echo "Docker build failed $IMAGE_TAG"
exit 1
fi
if docker run -it --rm -d -p $PORT:8888 $IMAGE_TAG;
then
echo "$IMAGE_TAG is running";
else
echo "Failed to run $IMAGE_TAG" && exit 1;
fi
if [ "$PUBLISH" = "all" ]
then
echo "Pushing $IMAGE_TAG"
docker push $IMAGE_TAG
else
echo "None is published"
fi
}
function build_base_image {
# Generate base dockerfile and images
cd $IMAGE
bash generate_dockerfile.sh
BASE_PORT=7070
TAG_DIR=$1
IMAGE_DIR=.build/$TAG_DIR
IMAGE_TAG=$CONTAINER_REG_OWNER/$IMAGE:$TAG_DIR
echo "Building base image $IMAGE_TAG"
build_and_publish_single_image $IMAGE_DIR $IMAGE_TAG $BASE_PORT
cd ..
}
function build_image {
cd $IMAGE
NB_PORT=8080
TAG_DIR=$1
IMAGE_DIR=$TAG_DIR
IMAGE_TAG=$CONTAINER_REG_OWNER/$IMAGE:$IMAGE_DIR
echo "Building image $IMAGE_TAG"
build_and_publish_single_image $IMAGE_DIR $IMAGE_TAG $NB_PORT
cd ..
}
function main {
if [ "$IMAGE" = "base-gpu-notebook" ]
then
echo "Building $IMAGE $TAG"
build_base_image $TAG
elif [ "$IMAGE" = "gpu-notebook" ]
then
echo "Building $IMAGE $TAG"
build_image $TAG
elif [ "$IMAGE" = "pytorch-notebook" ]
then
echo "Building $IMAGE $TAG"
build_image $TAG
elif [ "$IMAGE" = "ml-notebook" ]
then
echo "Building $IMAGE $TAG"
build_image $TAG
elif [ "$IMAGE" = "nlp-notebook" ]
then
echo "Building $IMAGE $TAG"
build_image $TAG
elif [ "$IMAGE" = "geo-notebook" ]
then
echo "Building $IMAGE $TAG"
build_image $TAG
elif [ "$IMAGE" = "ros" ]
then
echo "Building $IMAGE $TAG"
build_image $TAG
else
echo "Unrecognized $IMAGE and $TAG"
fi
}
# build and push docker image
parse_args "$@"
echo "Building and publishing images"
main