blob: e97fc6b9ee925a935724b6db5ed7f057b9e12713 [file] [log] [blame]
Piotr Perzanowski046196f2018-12-18 16:33:00 +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
26CLEAN=false
27if [ -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"
32fi
33IMG_DIR="$1"
34if [[ -z "$IMG_DIR" ]]; then
35 IMG_DIR="$(pwd)/images"
36fi
37if [[ ! -d "${IMG_DIR}" ]]; then
38 echo "No ${IMG_DIR} to load images"
39 exit 0
40fi
41load_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}
52IMAGES=$(find ${IMG_DIR} -name "*.tar" -type f)
53lines=$(echo ${IMAGES} | wc -l)
54line=1
55for image in ${IMAGES}; do
56 echo "== pkg #$line of $lines =="
57 load_image "$image"
58 line=$((line+1))
59done
60if [ "$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
64fi