#!/bin/bash ############################################################################## # # Copyright (c) 2019 AT&T Intellectual Property. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ############################################################################## # Installs well-known RIC charts then verifies specified helm chart # Requires chart tgz archives in /tmp while [ -n "$1" ]; do # while loop starts case "$1" in -d) DOCKER_REGISTRY=$2 shift ;; -p) IMAGE_DIRECTORY_PATH=$2 shift ;; *) echo "Option $1 not recognized. Please specify the docker registry path with the -d option and specify the directory path of the images with the -p option." ;; # In case you typed a different option other than -d or -p esac shift done if [ -z $DOCKER_REGISTRY ]; then echo "Please specify the docker registry path with the -d option." exit 1 fi if [ -z $IMAGE_DIRECTORY_PATH ]; then echo "Please specify the directory path of the images with the -p option." exit 1 fi for image in $IMAGE_DIRECTORY_PATH/*; do OUTPUT=$(docker load -i $image) IMAGE_PATH_ORIGINAL=$(echo $OUTPUT | grep image: | awk '{print $3}' ) IMAGENAME=$(echo $IMAGE_PATH_ORIGINAL | awk '{ n=split($0, a, "/"); print a[n] }') echo "************************************************************" echo "Loading image $IMAGENAME" docker tag $IMAGE_PATH_ORIGINAL $DOCKER_REGISTRY/$IMAGENAME RESULT=$(docker push $DOCKER_REGISTRY/$IMAGENAME 2>&1) LOGIN_ERROR=$(echo $RESULT |& grep "no basic auth credentials" ) if [ ! -z "$LOGIN_ERROR" ]; then echo "You are not logined to $DOCKER_REGISTRY. Please login by running \"docker login $DOCKER_REGISTRY\"" exit 1 fi ACCESS_ERROR=$(echo $RESULT |& grep "denied: requested access to the resource is denied" ) if [ ! -z "$ACCESS_ERROR" ]; then echo "Failed to push image to docker registry: <$DOCKER_REGISTRY>. Please check if it is a typo." exit 1 fi done