Piotr Perzanowski | 046196f | 2018-12-18 16:33:00 +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 | CLEAN=false |
| 27 | if [ -z "$NEXUS_HOST" ]; then |
| 28 | echo "Independent run for inserting of additional docker images" |
| 29 | CLEAN=true |
| 30 | mv ~/.docker/config.json ~/.docker/config.json_backup 2>/dev/null |
| 31 | source "$LOCAL_PATH/docker-login.sh" |
| 32 | fi |
| 33 | IMG_DIR="$1" |
| 34 | if [[ -z "$IMG_DIR" ]]; then |
| 35 | IMG_DIR="$(pwd)/images" |
| 36 | fi |
| 37 | if [[ ! -d "${IMG_DIR}" ]]; then |
| 38 | echo "No ${IMG_DIR} to load images" |
| 39 | exit 0 |
| 40 | fi |
| 41 | load_image() { |
| 42 | local image="$1" |
| 43 | echo "[DEBUG] load ${image}" |
| 44 | result=$(docker load -i "${image}") |
| 45 | echo $result |
| 46 | name=$(echo $result | awk '{print $3}') |
| 47 | echo "[DEBUG] pushing $name" |
| 48 | retry docker push "$name" |
| 49 | # delete pushed image from docker |
| 50 | retry docker rmi "$name" |
| 51 | } |
| 52 | IMAGES=$(find ${IMG_DIR} -name "*.tar" -type f) |
| 53 | lines=$(echo ${IMAGES} | wc -l) |
| 54 | line=1 |
| 55 | for image in ${IMAGES}; do |
| 56 | echo "== pkg #$line of $lines ==" |
| 57 | load_image "$image" |
| 58 | line=$((line+1)) |
| 59 | done |
| 60 | if [ "$CLEAN" = true ]; then |
| 61 | # onap is using different credentials for docker login which can be conflicted |
| 62 | # with ours so better to clean this-up |
| 63 | rm ~/.docker/config.json |
| 64 | fi |