Piotr Perzanowski | 6d14adb | 2018-12-18 17:00:08 +0100 | [diff] [blame] | 1 | #! /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 |
| 20 | RELATIVE_PATH=../ # relative path from this script to 'common-functions.sh' |
| 21 | if [ "$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 |
| 25 | fi |
| 26 | IMG_DIR="$1" |
| 27 | if [[ -z "$IMG_DIR" ]]; then |
| 28 | IMG_DIR="./images" |
| 29 | fi |
| 30 | echo "Creating ${IMG_DIR}" |
| 31 | if [[ ! -d "${IMG_DIR}" ]]; then |
| 32 | mkdir -p "${IMG_DIR}" |
| 33 | fi |
| 34 | save_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 | } |
| 47 | echo "Save all images" |
| 48 | line=1 |
| 49 | lines=$(docker images|grep -v 'IMAGE ID'|wc -l) |
| 50 | while 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)) |
| 56 | done <<< "$(docker images|grep -v 'IMAGE ID'|awk '{printf("%s %s\n", $1, $2)}'|column -t)" |