Fix bugs in AUX deployment
[it/dep.git] / bin / prepull-images
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     -f) IMAGELISTFILE=$2
29         shift
30         ;; 
31
32
33     -d) IMAGE_DIRECTORY_PATH=$2
34         shift
35         ;;
36
37
38     *) echo "Option $1 not recognized. Please use -f to specify the recipe path." ;; # In case you typed a different option other than a,b,c
39
40     esac
41
42     shift
43
44 done
45
46 if [ -z "$IMAGELISTFILE" ]; then
47    echo "Image list file is missing. Please use -f to specify the path."
48    exit 1
49 fi
50
51 if [ -z "$IMAGE_DIRECTORY_PATH" ]; then
52     IMAGE_DIRECTORY_PATH=/tmp/ric_image
53 fi
54
55
56 rm -rf $IMAGE_DIRECTORY_PATH
57 mkdir -p $IMAGE_DIRECTORY_PATH
58
59
60 while IFS= read -r image
61 do
62     if [[ $image == "#"* ]]; then
63         # supporting comment lines
64         continue
65     fi
66
67     IMAGENAME=$(echo $image | awk '{ n=split($0, a, "/"); print a[n] }')
68
69     echo "Pulling image $image"
70     RESULT=$(docker pull $image |& grep "no basic auth credentials" )
71     if [ ! -z "$RESULT" ]; then
72         echo "You are not logined to docker registry. Please login by running \"docker login DOCKER_REGISTRY\""
73         exit 1
74     fi
75
76     echo "Saving image $image"
77     docker save $image -o $IMAGE_DIRECTORY_PATH/$IMAGENAME
78
79     echo "************************************************************"
80
81
82 done < "$IMAGELISTFILE"
83
84
85 echo "RIC Images are downloaded to: $IMAGE_DIRECTORY_PATH"