Fixed db migrator image update
[policy/parent.git] / integration / src / main / scripts / release / updateOomImages.sh
1 #!/bin/bash
2
3 #
4 # ============LICENSE_START================================================
5 # ONAP
6 # =========================================================================
7 # Copyright (C) 2021-2022 Nordix Foundation.
8 # =========================================================================
9 # Licensed under the Apache License, Version 2.0 (the "License");
10 # you may not use this file except in compliance with the License.
11 # You may obtain a copy of the License at
12 #
13 #      http://www.apache.org/licenses/LICENSE-2.0
14 #
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS,
17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 # See the License for the specific language governing permissions and
19 # limitations under the License.
20 # ============LICENSE_END==================================================
21 #
22
23 set -e
24
25 SCRIPT_NAME=$(basename "$0")
26 repo_location="./"
27 release_data_file="./pf_release_data.csv"
28
29 # Use the bash internal OSTYPE variable to check for MacOS
30 if [[ "$OSTYPE" == "darwin"* ]]
31 then
32     SED="gsed"
33 else
34     SED="sed"
35 fi
36
37 declare -a pf_repos=(
38         "policy/parent"
39         "policy/docker"
40         "policy/common"
41         "policy/models"
42         "policy/api"
43         "policy/pap"
44         "policy/drools-pdp"
45         "policy/apex-pdp"
46         "policy/xacml-pdp"
47         "policy/distribution"
48         "policy/gui"
49         "policy/clamp"
50         "policy/drools-applications"
51 )
52
53 usage()
54 {
55     echo ""
56     echo "$SCRIPT_NAME - generate an OOM commit to update the versions of Policy Framework images in values.yaml files"
57     echo ""
58     echo "       usage:  $SCRIPT_NAME [-options]"
59     echo ""
60     echo "       options"
61     echo "         -h           - this help message"
62     echo "         -d data_file - the policy release data file to use, defaults to '$release_data_file'"
63     echo "         -l location  - the location of the OOM repo on the file system,"
64     echo "                        defaults to '$repo_location'"
65     echo "         -i issue-id  - issue ID in the format POLICY-nnnn"
66     echo ""
67     echo " examples:"
68     echo "  $SCRIPT_NAME -l /home/user/onap -d /home/user/data/pf_release_data.csv -i POLICY-1234"
69     echo "    update the version of policy framework images at location '/home/user/onap/oom' using the release data"
70     echo "    in the file '/home/user/data/pf_release_data.csv'"
71     exit 255;
72 }
73
74 while getopts "hd:l:i:" opt
75 do
76     case $opt in
77     h)
78         usage
79         ;;
80     d)
81         release_data_file=$OPTARG
82         ;;
83     l)
84         repo_location=$OPTARG
85         ;;
86     i)
87         issue_id=$OPTARG
88         ;;
89     \?)
90         usage
91         exit 1
92         ;;
93     esac
94 done
95
96 if [ $OPTIND -eq 1 ]
97 then
98     echo "no arguments were specified"
99     usage
100 fi
101
102 if [[ -z "$repo_location" ]]
103 then
104     echo "OOM repo location not specified on -l flag"
105     exit 1
106 fi
107
108 if ! [ -d "$repo_location" ]
109 then
110     echo "OOM repo location '$repo_location' not found"
111     exit 1
112 fi
113
114 if [[ -z "$release_data_file" ]]
115 then
116     echo "policy release data file not specified on -d flag"
117     exit 1
118 fi
119
120 if ! [ -f "$release_data_file" ]
121 then
122     echo "policy release data file '$release_data_file' not found"
123     exit 1
124 fi
125
126 if [ -z "$issue_id" ]
127 then
128     echo "issue_id not specified on -i flag"
129     exit 1
130 fi
131
132 if ! echo "$issue_id" | grep -Eq '^POLICY-[0-9]*$'
133 then
134   echo "issue ID is invalid, it should be of form 'POLICY-nnnn'"
135   exit 1
136 fi
137
138 for specified_repo in "${pf_repos[@]}"
139 do
140     # shellcheck disable=SC2034
141     # shellcheck disable=SC2046
142     read -r repo \
143             latest_released_tag \
144             latest_snapshot_tag \
145             changed_files docker_images \
146         <<< $(grep "$specified_repo" "$release_data_file" | tr ',' ' ' )
147
148     if [ ! "$repo" = "$specified_repo" ]
149     then
150         echo "repo '$specified_repo' not found in file 'pf_release_data.csv'"
151         continue
152     fi
153
154     if [ "$docker_images" = "" ]
155     then
156         continue
157     fi
158
159     for docker_image in $(echo "$docker_images" | sed -e "s/'//g" -e "s/:/ /g")
160     do
161         new_image="$docker_image:$latest_released_tag"
162
163         echo "updating OOM image $new_image . . ."
164         find "$repo_location/oom/kubernetes/policy" \
165             -name values.yaml \
166             -exec \
167                 $SED -i \
168                 "s/image:[ |\t]*onap\/$docker_image:[0-9]*\.[0-9]*\.[0-9]*$/image: onap\/$new_image/" {} \;
169         echo "OOM image $docker_image:$latest_released_tag updated"
170     done
171 done
172
173 echo "generating OOM commit to update policy framework docker image versions . . ."
174
175 generateCommit.sh \
176     -l "$repo_location" \
177     -r oom \
178     -i "$issue_id" \
179     -e "[POLICY] Update docker images to latest versions" \
180     -m "The image versions in policy values.yaml files have been updated"
181
182 echo "OOM commit to update policy framework docker image versions generated"
183