-
Notifications
You must be signed in to change notification settings - Fork 27
/
generator
52 lines (44 loc) · 1.55 KB
/
generator
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
#!/bin/bash
set -x
for IMAGE in $LIST_IMAGES
do
OS_NAME=$(echo $IMAGE | cut -d";" -f1)
OS_VERSION=$(echo $IMAGE | cut -d";" -f2)
IMAGE_URL=$(echo $IMAGE | cut -d";" -f3)
URL_LIST=($(echo "$IMAGE_URL" | tr "/" " "))
FILE_NAME="${URL_LIST[${#URL_LIST[@]}-1]}"
NAME_IMAGE="$OS_NAME-container-disk"
FILE_LIST=($(echo "$FILE_NAME" | tr "." " "))
IMAGE_NAME=$(echo $FILE_NAME | cut -d"." -f1)
IMAGE_EXTENSION="${FILE_LIST[${#FILE_LIST[@]}-1]}"
echo "OS:$OS_NAME VERSION:$OS_VERSION IMAGE:$IMAGE_URL"
#if [ ! -f custom/$FILE_NAME ]; then
# curl -g -L $IMAGE_URL > custom/$FILE_NAME
#fi
echo "Build $OS_NAME:$OS_VERSION"
docker build -f base/Dockerfile -t $NAME_REGISTRY/$NAME_IMAGE:$OS_VERSION \
--build-arg OS_NAME="$OS_NAME" \
--build-arg OS_VERSION="$OS_VERSION" \
--build-arg IMAGE_URL="$IMAGE_URL" \
--build-arg FILE_NAME="$FILE_NAME" \
--build-arg IMAGE_NAME="$IMAGE_NAME" \
--build-arg IMAGE_EXTENSION="$IMAGE_EXTENSION" .
if [ $? != 0 ]; then exit 1; fi
echo "Push $OS_NAME:$OS_VERSION"
SUCCESS=1
CONT_TIMEOUT=0
# Hack Docker-Hub slow image push
while [[ $CONT_TIMEOUT < 5 ]] && [[ $SUCCESS != 0 ]]; do
timeout 300 docker push $NAME_REGISTRY/$NAME_IMAGE:$OS_VERSION
SUCCESS=$?
CONT_TIMEOUT=$((CONT_TIMEOUT + 1))
sleep 3
done
#rm -f custom/$FILE_NAME
docker rmi $NAME_REGISTRY/$NAME_IMAGE:$OS_VERSION
done
echo "Clean..."
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
docker rmi $(docker images | grep "^<none>" | awk '{ print $3 }')
docker rmi $(docker images | grep "<none>" | grep "$NAME_IMAGE" | awk '{ print $3 }')