forked from Tedezed/kubevirt-images-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerator
44 lines (35 loc) · 1.42 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
#!/bin/bash
set -x
export LIST_IMAGES="coreos;2079.4.0;https://stable.release.core-os.net/amd64-usr/current/coreos_production_openstack_image.img.bz2"
export NAME_REGISTRY="1337andre"
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
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" .
docker push $NAME_REGISTRY/$NAME_IMAGE:$OS_VERSION
#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 }')