blob: 685bed4239be0f03fe53cead11b9c4e134186b64 [file] [log] [blame]
Piotr Perzanowski046196f2018-12-18 16:33:00 +01001#! /usr/bin/env bash
Petr Ospalý03e61242019-01-03 16:54:50 +01002
Piotr Perzanowski046196f2018-12-18 16:33:00 +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 Perzanowski046196f2018-12-18 16:33:00 +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 Perzanowski046196f2018-12-18 16:33:00 +010030CLEAN=false
Petr Ospalý03e61242019-01-03 16:54:50 +010031
Piotr Perzanowski046196f2018-12-18 16:33:00 +010032if [ -z "$NEXUS_HOST" ]; then
33 echo "Independent run for inserting of additional docker images"
34 CLEAN=true
35 mv ~/.docker/config.json ~/.docker/config.json_backup 2>/dev/null
36 source "$LOCAL_PATH/docker-login.sh"
37fi
Petr Ospalý03e61242019-01-03 16:54:50 +010038
Piotr Perzanowski046196f2018-12-18 16:33:00 +010039IMG_DIR="$1"
40if [[ -z "$IMG_DIR" ]]; then
41 IMG_DIR="$(pwd)/images"
42fi
Petr Ospalý03e61242019-01-03 16:54:50 +010043
Piotr Perzanowski046196f2018-12-18 16:33:00 +010044if [[ ! -d "${IMG_DIR}" ]]; then
45 echo "No ${IMG_DIR} to load images"
46 exit 0
47fi
Petr Ospalý03e61242019-01-03 16:54:50 +010048
Piotr Perzanowski046196f2018-12-18 16:33:00 +010049load_image() {
50 local image="$1"
51 echo "[DEBUG] load ${image}"
52 result=$(docker load -i "${image}")
53 echo $result
54 name=$(echo $result | awk '{print $3}')
55 echo "[DEBUG] pushing $name"
56 retry docker push "$name"
57 # delete pushed image from docker
58 retry docker rmi "$name"
59}
Petr Ospalý03e61242019-01-03 16:54:50 +010060
Piotr Perzanowski046196f2018-12-18 16:33:00 +010061IMAGES=$(find ${IMG_DIR} -name "*.tar" -type f)
62lines=$(echo ${IMAGES} | wc -l)
63line=1
64for image in ${IMAGES}; do
65 echo "== pkg #$line of $lines =="
66 load_image "$image"
Petr Ospalý03e61242019-01-03 16:54:50 +010067
Piotr Perzanowski046196f2018-12-18 16:33:00 +010068 line=$((line+1))
69done
Petr Ospalý03e61242019-01-03 16:54:50 +010070
Piotr Perzanowski046196f2018-12-18 16:33:00 +010071if [ "$CLEAN" = true ]; then
72 # onap is using different credentials for docker login which can be conflicted
73 # with ours so better to clean this-up
74 rm ~/.docker/config.json
75fi