-
Notifications
You must be signed in to change notification settings - Fork 17
/
save.sh
executable file
·55 lines (44 loc) · 1.68 KB
/
save.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
#!/bin/bash -x
MY_DIR=$(dirname "$(readlink -f "$0")")
if [ $# -lt 1 ]; then
echo "Usage: "
echo " ${0} "
echo "e.g.: "
echo " ${0} "
fi
###################################################
#### ---- Change this only to use your own ----
###################################################
ORGANIZATION=openkbs
###################################################
#### **** Container package information ****
###################################################
DOCKER_IMAGE_REPO=`echo $(basename $PWD)|tr '[:upper:]' '[:lower:]'|tr "/: " "_" `
imageTag="${ORGANIZATION}/${DOCKER_IMAGE_REPO}"
imageTag=${1:-$imageTag}
IMAGE_NAME=${imageTag%:*}
IMAGE_VERSION=${imageTag#*:}
if [ "$IMAGE_VERSION" = "" ]; then
# -- patch in the image version
imageTag="${IMAGE_NAME}:latest"
fi
###################################################
#### ---- Mostly, you don't need change below ----
###################################################
## -- transform '-' and space to '_'
#instanceName=`echo $(basename ${imageTag})|tr '[:upper:]' '[:lower:]'|tr "/\-: " "_"`
instanceName=`echo $(basename ${imageTag})|tr '[:upper:]' '[:lower:]'|tr "/: " "_"`
TGZ_DOCKER_IMAGE=${instanceName}.tgz
function save() {
lookupImage=`sudo docker images ${imageTag} | grep ${imageTag} | awk '{print $1}'`
if [ "$lookupImage" = "" ]; then
echo "*** ERROR ***: Can't find Docker image (${imageTag}): Can't continue! Abort!"
exit 1
fi
sudo docker save ${imageTag} | gzip > ${TGZ_DOCKER_IMAGE}
ls -al ${TGZ_DOCKER_IMAGE}
}
echo "---------------------------------------------"
echo "---- SAVE a Container for ${imageTag}"
echo "---------------------------------------------"
save