forked from argenos/b-it-bots-docker
-
Notifications
You must be signed in to change notification settings - Fork 6
/
build_and_publish.sh
216 lines (193 loc) · 5.82 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# Build and publish images
# Copyright b-it-bots, Hochschule Bonn-Rhein-Sieg
DEPLOYMENT=""
CONTAINER_REGISTRY=""
PUBLISH="all"
if [ $# -eq 0 ]
then
echo "Usage: bash build-and-deploy.sh"
echo " "
echo "options:"
echo "-h, --help show brief help"
echo "-bi, --base-image base image tag e.g. ghcr.io/a2s-institute/docker-stacks/gpu-notebook (default)"
echo "-bit, --base-image-tag base image tag e.g. 11.8.0-cudnn8-runtime-ubuntu22.04 (default)"
echo "-d, --deployment deployment (dev or prod), default: is empty or not published to registry"
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 base|domestic|gpu-notebook|all (default: all)"
exit 0
fi
while test $# -gt 0; do
case "$1" in
-h|--help)
echo "Usage: bash build-and-deploy.sh"
echo " "
echo "options:"
echo "-h, --help show brief help"
echo "-b, --base-image base image tag e.g. ghcr.io/a2s-institute/docker-stacks/gpu-notebook:11.8.0-cudnn8-runtime-ubuntu22.04 (default)"
echo "-d, --deployment deployment (dev or prod), default: is empty or not published to registry"
echo "-r, --registry container registry e.g. ghcr.io for GitHub container registry, default: docker hub"
echo "-p, --publish option whether to publish <all> tags or <latest> tags only (default: all)"
echo "-i, --image image to build domestic|gpu-notebook|all (default: all)"
exit 0
;;
-bi|--base-image)
BASE_IMAGE="$2"
shift
shift
;;
-bit|--base-image-tag)
BASE_IMAGE_TAG="$2"
shift
shift
;;
-d|--deployment)
DEPLOYMENT="$2"
shift
shift
;;
-r|--registry)
CONTAINER_REGISTRY="$2"
shift
shift
;;
-p|--publish)
PUBLISH="$2"
shift
shift
;;
-i|--image)
IMAGE="$2"
shift
shift
;;
*)
break
;;
esac
done
if [ -z "$BASE_IMAGE" ]
then
echo "Cuda version is not set, setting it to default ghcr.io/a2s-institute/docker-stacks/gpu-notebook"
BASE_IMAGE=ghcr.io/a2s-institute/docker-stacks/gpu-notebook
fi
echo "Base image: $BASE_IMAGE"
if [ -z "$BASE_IMAGE_TAG" ]
then
echo "Cuda version is not set, setting it to default 11.3.1-cudnn8-runtime-ubuntu20.04"
BASE_IMAGE_TAG=11.8.0-cudnn8-runtime-ubuntu22.04
fi
echo "Base image: $BASE_IMAGE_TAG"
BASE_NOTEBOOK_IMAGE=$BASE_IMAGE:$BASE_IMAGE_TAG
echo "Base notebook image: $BASE_NOTEBOOK_IMAGE"
if [ -z "$CONTAINER_REGISTRY" ]
then
echo "Container registry is not set!. Using docker hub registry"
CONTAINER_REG_OWNER=bitbots
else
echo "Using $CONTAINER_REGISTRY registry"
OWNER=b-it-bots/docker
CONTAINER_REG_OWNER=$CONTAINER_REGISTRY/$OWNER
fi
echo "Container registry/owner = $CONTAINER_REG_OWNER"
echo "Deployment: $DEPLOYMENT"
function build_and_publish_gpu_notebook {
GPU_NOTEBOOK_TAG=$CONTAINER_REG_OWNER/gpu-notebook:$BASE_IMAGE_TAG
docker build -t $GPU_NOTEBOOK_TAG --build-arg BASE_NOTEBOOK_IMAGE=$BASE_NOTEBOOK_IMAGE gpu-notebook/
if docker run -it --rm -d -p 8880:8888 $BASE_NOTEBOOK_IMAGE;
then
echo "$BASE_NOTEBOOK_IMAGE is running";
else
echo "Failed to run $BASE_NOTEBOOK_IMAGE" && exit 1;
fi
if docker run -it --rm -d -p 8881:8888 $GPU_NOTEBOOK_TAG;
then
echo "$GPU_NOTEBOOK_TAG is running";
else
echo "Failed to run $GPU_NOTEBOOK_TAG" && exit 1;
fi
if [ "$PUBLISH" = "all" ]
then
echo "Pushing $GPU_NOTEBOOK_TAG"
docker push $GPU_NOTEBOOK_TAG
else
echo "None is published"
fi
cd ..
}
function build_and_publish_base_image {
cd base
BASE_PORT=5000
for ROS_DIST in */;
do
ROS_DISTRO=${ROS_DIST%/}
BASE_IMAGE_TAG=$CONTAINER_REG_OWNER/bitbots-base:$ROS_DISTRO
echo "Building base image $BASE_IMAGE_TAG"
docker build -t $BASE_IMAGE_TAG $ROS_DISTRO
if docker run -it --rm -d -p $BASE_PORT:$BASE_PORT $BASE_IMAGE_TAG;
then
echo "$BASE_IMAGE_TAG is running";
else
echo "Failed to run $BASE_IMAGE_TAG" && exit 1;
fi
let "BASE_PORT+=1"
done
if [ "$PUBLISH" = "all" ]
then
for ROS_DIST in */;
do
ROS_DISTRO=${ROS_DIST%/}
BASE_IMAGE_TAG=$CONTAINER_REG_OWNER/bitbots-base:$ROS_DISTRO
echo "Publishing base image $BASE_IMAGE_TAG"
docker push $BASE_IMAGE_TAG
done
else
echo "No base image is published"
fi
cd ..
}
function build_and_publish_domestic_image {
cd domestic
BASE_PORT=6000
for ROS_DIST in */;
do
ROS_DISTRO=${ROS_DIST%/}
DOMESTIC_IMAGE_TAG=$CONTAINER_REG_OWNER/bitbots-domestic:$ROS_DISTRO-base
echo "Building image $DOMESTIC_IMAGE_TAG"
docker build -t $DOMESTIC_IMAGE_TAG $ROS_DISTRO
if docker run -it --rm -d -p $BASE_PORT:$BASE_PORT $DOMESTIC_IMAGE_TAG;
then
echo "$DOMESTIC_IMAGE_TAG is running";
else
echo "Failed to run $DOMESTIC_IMAGE_TAG" && exit 1;
fi
let "BASE_PORT+=1"
done
if [ "$PUBLISH" = "all" ]
then
for ROS_DIST in */;
do
ROS_DISTRO=${ROS_DIST%/}
DOMESTIC_IMAGE_TAG=$CONTAINER_REG_OWNER/bitbots-domestic:$ROS_DISTRO-base
echo "Publishing image $DOMESTIC_IMAGE_TAG"
docker push $DOMESTIC_IMAGE_TAG
done
else
echo "No domestic image is published"
fi
cd ..
}
# build and push docker image
echo "Building and publishing $IMAGE"
if [ "$IMAGE" = "gpu-notebook" ]
then
build_and_publish_gpu_notebook
elif [ "$IMAGE" = "domestic" ]
then
build_and_publish_base_image
build_and_publish_domestic_image
else
build_and_publish_gpu_notebook
build_and_publish_base_image
build_and_publish_domestic_image
fi