blob: 98facb0c4536c111de431dc491e0c7c213e27047 [file] [log] [blame]
Piotr Perzanowski6d14adb2018-12-18 17:00:08 +01001#! /usr/bin/env bash
2# COPYRIGHT NOTICE STARTS HERE
3#
4# Copyright 2018 © Samsung Electronics Co., Ltd.
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18# COPYRIGHT NOTICE ENDS HERE
19# boilerplate
20RELATIVE_PATH=../ # relative path from this script to 'common-functions.sh'
21if [ "$IS_COMMON_FUNCTIONS_SOURCED" != YES ] ; then
22 SCRIPT_DIR=$(dirname "${0}")
23 LOCAL_PATH=$(readlink -f "$SCRIPT_DIR")
24 . "${LOCAL_PATH}"/"${RELATIVE_PATH}"/common-functions.sh
25fi
26IMG_DIR="$1"
27if [[ -z "$IMG_DIR" ]]; then
28 IMG_DIR="./images"
29fi
30echo "Creating ${IMG_DIR}"
31if [[ ! -d "${IMG_DIR}" ]]; then
32 mkdir -p "${IMG_DIR}"
33fi
34save_image() {
35 local name_tag=$1
36 echo "$name_tag"
37 local img_name=$(echo "${name_tag}" | tr /: __)
38 local img_path="${IMG_DIR}/${img_name}.tar"
39 if [[ ! -f "${img_path}" ]] ; then
40 echo "[DEBUG] save ${name_tag} to ${img_path}"
41 echo "${name_tag}" >> $IMG_DIR/_image_list.txt
42 retry docker -l error save -o "${img_path}" ${name_tag}
43 else
44 echo "[DEBUG] ${name_tag} already saved"
45 fi
46}
47echo "Save all images"
48line=1
49lines=$(docker images|grep -v 'IMAGE ID'|wc -l)
50while read -r image; do
51 echo "== pkg #$line of $lines =="
52 name=$(echo $image|awk '{print $1}')
53 tag=$(echo $image|awk '{print $2}')
54 save_image "$name:$tag"
55 line=$((line+1))
56done <<< "$(docker images|grep -v 'IMAGE ID'|awk '{printf("%s %s\n", $1, $2)}'|column -t)"