Zhe Huang | 44fcaf0 | 2019-08-27 12:55:57 -0400 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | ############################################################################## |
| 3 | # |
| 4 | # Copyright (c) 2019 AT&T Intellectual Property. |
| 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 | ############################################################################## |
| 19 | |
| 20 | # Installs well-known RIC charts then verifies specified helm chart |
| 21 | # Requires chart tgz archives in /tmp |
| 22 | |
| 23 | |
| 24 | while [ -n "$1" ]; do # while loop starts |
| 25 | |
| 26 | case "$1" in |
| 27 | |
| 28 | -d) DOCKER_REGISTRY=$2 |
| 29 | shift |
| 30 | ;; |
| 31 | |
| 32 | -p) IMAGE_DIRECTORY_PATH=$2 |
| 33 | shift |
| 34 | ;; |
| 35 | |
| 36 | *) 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." |
| 37 | ;; # In case you typed a different option other than -d or -p |
| 38 | |
| 39 | esac |
| 40 | |
| 41 | shift |
| 42 | |
| 43 | done |
| 44 | |
| 45 | if [ -z $DOCKER_REGISTRY ]; then |
| 46 | echo "Please specify the docker registry path with the -d option." |
| 47 | exit 1 |
| 48 | fi |
| 49 | |
| 50 | if [ -z $IMAGE_DIRECTORY_PATH ]; then |
| 51 | echo "Please specify the directory path of the images with the -p option." |
| 52 | exit 1 |
| 53 | fi |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | for image in $IMAGE_DIRECTORY_PATH/*; do |
| 59 | OUTPUT=$(docker load -i $image) |
| 60 | IMAGE_PATH_ORIGINAL=$(echo $OUTPUT | grep image: | awk '{print $3}' ) |
| 61 | IMAGENAME=$(echo $IMAGE_PATH_ORIGINAL | awk '{ n=split($0, a, "/"); print a[n] }') |
| 62 | echo "************************************************************" |
| 63 | echo "Loading image $IMAGENAME" |
| 64 | docker tag $IMAGE_PATH_ORIGINAL $DOCKER_REGISTRY/$IMAGENAME |
| 65 | RESULT=$(docker push $DOCKER_REGISTRY/$IMAGENAME 2>&1) |
| 66 | LOGIN_ERROR=$(echo $RESULT |& grep "no basic auth credentials" ) |
| 67 | if [ ! -z "$LOGIN_ERROR" ]; then |
| 68 | echo "You are not logined to $DOCKER_REGISTRY. Please login by running \"docker login $DOCKER_REGISTRY\"" |
| 69 | exit 1 |
| 70 | fi |
| 71 | ACCESS_ERROR=$(echo $RESULT |& grep "denied: requested access to the resource is denied" ) |
| 72 | if [ ! -z "$ACCESS_ERROR" ]; then |
| 73 | echo "Failed to push image to docker registry: <$DOCKER_REGISTRY>. Please check if it is a typo." |
| 74 | exit 1 |
| 75 | fi |
| 76 | done |