-
Notifications
You must be signed in to change notification settings - Fork 1
/
docker_save.sh
executable file
·61 lines (53 loc) · 1.85 KB
/
docker_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
54
55
56
57
58
59
60
61
#!/bin/bash -x
STORAGE=/var/lib/portkey/docker
SENT_IMAGES=/var/lib/portkey/sent-images.txt
IMAGE_STORAGE=${STORAGE}/images
DESTINATION=/var/lib/portkey/to_send/
DOCKER_IMAGES=$(mktemp)
rh_repos=$(/var/lib/portkey/sat6-disconnected/docker_list_images.py | egrep '^rhel|^openshift3|^rhscl/|^jboss|^dotnet|^cloudforms|^redhat' | grep -v beta)
crunch_repos=$(curl https://access.crunchydata.com/containerinfo/containerversions.txt | grep -v ^# | cut -d: -f1)
# do a fresh pull of everything in our regex above
for r in $rh_repos;
do
SAVE_DIR=$(dirname ${IMAGE_STORAGE}/$r)
mkdir -p ${SAVE_DIR}
CLEANEXIT=1
TRIES=1
while [ ${CLEANEXIT} -ne 0 -a ${TRIES} -lt 4 ];
do
docker pull -a registry.access.redhat.com/$r
CLEANEXIT=$?
((TRIES++))
done
done
for r in $crunch_repos;
do
SAVE_DIR=$(dirname ${IMAGE_STORAGE}/$r)
mkdir -p ${SAVE_DIR}
CLEANEXIT=1
TRIES=1
while [ ${CLEANEXIT} -ne 0 -a ${TRIES} -lt 4 ];
do
docker pull -a registry.crunchydata.com/$r
CLEANEXIT=$?
((TRIES++))
done
done
# Gen up current list of images
docker images > $DOCKER_IMAGES
# Save only those image IDs that we haven't saved before
for image in $(cat $DOCKER_IMAGES | awk '{print $3}' | sort | uniq)
do
if [[ $( grep ${image} ${SENT_IMAGES} ) == '' ]]
then
VERSIONSTRING=$(cat $DOCKER_IMAGES | grep ${image} | awk '{print $1 ":" $2}'| sort | uniq)
echo docker save $VERSIONSTRING \| gzip \> ${IMAGE_STORAGE}/${image}.tar.gz
docker save $VERSIONSTRING | gzip > ${IMAGE_STORAGE}/${image}.tar.gz
mv -v ${IMAGE_STORAGE}/${image}.tar.gz ${DESTINATION}/${image}.tar.gz.docker
temp_sort=$(mktemp)
echo ${image} | sort ${SENT_IMAGES} - > ${temp_sort}
mv -f ${temp_sort} ${SENT_IMAGES}
fi
done
# toss the new mapping into to_send, to double-check versions on the other side
mv -v $DOCKER_IMAGES ${DESTINATION}/docker-image-mapping.txt