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