-
Notifications
You must be signed in to change notification settings - Fork 0
/
image_build.sh
72 lines (60 loc) · 3.14 KB
/
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
BUILD_DIR=/srv/build/images
# REGISTRY
MY_REGISTRY=image-registry.vo.elte.hu
IMAGE_DIR=`basename $2`
. ${IMAGE_DIR}/envs
NS=$3
POD_NAME=$4" -c hub"
API_CALL="python3 /kooplexhub/kooplexhub/manage.py manage_images"
IMAGE_NAME="${IMAGE_DIR}"
DESCRIPTION=${IMAGE_DIR}/Dockerfile
IMAGE_TYPE=`cat ${IMAGE_DIR}/imagetype`
RIMAGE_NAME="${MY_REGISTRY}/${IMAGE_NAME}"
BUILDMOD_DIR=${BUILD_DIR}/${IMAGE_DIR}
DESCRIPTION=`cat ${IMAGE_DIR}/DESCRIPTION`
DOCKERFILE=`cat ${IMAGE_DIR}/Dockerfile`
echo $IMAGE_NAME, $RIMAGE_NAME, $BUILDMOD_DIR
mkdir -p $BUILDMOD_DIR
case $1 in
"build")
echo "Building image ${IMAGE_NAME}" >&2
cp -r $IMAGE_DIR/* ${BUILDMOD_DIR}/
cd ${BUILDMOD_DIR}; . execute; cd $OLDPWD
docker $DOCKERARGS build -t ${IMAGE_NAME} -f $BUILDMOD_DIR/Dockerfile $BUILDMOD_DIR
docker $DOCKERARGS tag ${IMAGE_NAME} ${RIMAGE_NAME}
docker $DOCKERARGS push ${RIMAGE_NAME}
;;
"install")
echo "Register in hub ${RIMAGE_NAME}" >&2
echo "Install image"
echo kubectl exec -it -n ${NS} ${POD_NAME} -- ${API_CALL} --add_image ${RIMAGE_NAME} "${IMAGE_TYPE}"
kubectl exec -it -n ${NS} ${POD_NAME} -- ${API_CALL} --add_image ${RIMAGE_NAME} "${IMAGE_TYPE}"
echo "Install image w descr and dockfile"
kubectl exec -it -n ${NS} ${POD_NAME} -- ${API_CALL} --add_imagedescription ${RIMAGE_NAME} "${DESCRIPTION}" "${DOCKERFILE}"
for items in `cat ${BUILDMOD_DIR}/ENVVAR`
do
arr=(`echo $items| awk -F'=' '{print $1,$2}'`)
kubectl exec -it -n ${NS} ${POD_NAME} -- ${API_CALL} --add_envvar ${RIMAGE_NAME} ${arr[@]}
done
for items in `cat ${BUILDMOD_DIR}/PROXY`
do
arr=(`echo $items| awk -v IMN=${RIMAGE_NAME} -F',' '{print $1,IMN,$2,$3,$4,$5,$6}'`)
echo ${arr[@]}
kubectl exec -it -n ${NS} ${POD_NAME} -- ${API_CALL} --add_proxy ${arr[@]}
done
# kubectl exec -it -n ${NS} ${POD_NAME} -- python3 /kooplexhub/kooplexhub/manage.py manage_images --add_envvar ${RIMAGE_NAME} NB_USER {container.user.username}
# kubectl exec -it -n ${NS} ${POD_NAME} -- python3 /kooplexhub/kooplexhub/manage.py manage_images --add_envvar ${RIMAGE_NAME} NB_TOKEN {container.user.profile.token}
# kubectl exec -it -n ${NS} ${POD_NAME} -- python3 /kooplexhub/kooplexhub/manage.py manage_images --add_envvar ${RIMAGE_NAME} NB_PORT 8000
# kubectl exec -it -n ${NS} ${POD_NAME} -- python3 /kooplexhub/kooplexhub/manage.py manage_images --add_envvar ${RIMAGE_NAME} NB_URL {container.proxy_route}
# kubectl exec -it -n ${NS} ${POD_NAME} -- python3 /kooplexhub/kooplexhub/manage.py manage_images --add_envvar ${RIMAGE_NAME} NB_TESTURL notebook/test/{container.label}
# kubectl exec -it -n ${NS} ${POD_NAME} -- python3 /kooplexhub/kooplexhub/manage.py manage_images --add_proxy jupyter-notebook-basic ${RIMAGE_NAME} True True notebook/{container.label} notebook/{container.label}/ 8000
;;
"uninstall")
kubectl exec -it ${PREFIX}-hub -- python3 /kooplexhub/kooplexhub/manage.py manage_images --remove ${RIMAGE_NAME}
;;
"remove")
echo "Removing $BUILDMOD_DIR" >&2
rm -R -f $BUILDMOD_DIR
;;
esac