52459d5d5fd431e0d3cb987c1831a688ad4e5ef3
[policy/parent.git] / integration / src / release_scripts / 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 declare -a pf_repos=(
30         "policy/parent"
31         "policy/docker"
32         "policy/common"
33         "policy/models"
34         "policy/api"
35         "policy/pap"
36         "policy/drools-pdp"
37         "policy/apex-pdp"
38         "policy/xacml-pdp"
39         "policy/distribution"
40         "policy/gui"
41         "policy/clamp"
42         "policy/drools-applications"
43 )
44
45 usage()
46 {
47     echo ""
48     echo "$SCRIPT_NAME - generate an OOM commit to update the versions of Policy Framework images in values.yaml files"
49     echo ""
50     echo "       usage:  $SCRIPT_NAME [-options]"
51     echo ""
52     echo "       options"
53     echo "         -h           - this help message"
54     echo "         -d data_file - the policy release data file to use, defaults to '$release_data_file'"
55     echo "         -l location  - the location of the OOM repo on the file system,"
56     echo "                        defaults to '$repo_location'"
57     echo "         -i issue-id  - issue ID in the format POLICY-nnnn"
58     echo ""
59     echo " examples:"
60     echo "  $SCRIPT_NAME -l /home/user/onap -d /home/user/data/pf_release_data.csv -i POLICY-1234"
61     echo "    update the version of policy framework images at location '/home/user/onap/oom' using the release data"
62     echo "    in the file '/home/user/data/pf_release_data.csv'"
63     exit 255;
64 }
65
66 while getopts "hd:l:i:" opt
67 do
68     case $opt in
69     h)
70         usage
71         ;;
72     d)
73         release_data_file=$OPTARG
74         ;;
75     l)
76         repo_location=$OPTARG
77         ;;
78     i)
79         issue_id=$OPTARG
80         ;;
81     \?)
82         usage
83         exit 1
84         ;;
85     esac
86 done
87
88 if [ $OPTIND -eq 1 ]
89 then
90     echo "no arguments were specified"
91     usage
92 fi
93
94 if [[ -z "$repo_location" ]]
95 then
96     echo "OOM repo location not specified on -l flag"
97     exit 1
98 fi
99
100 if ! [ -d "$repo_location" ]
101 then
102     echo "OOM repo location '$repo_location' not found"
103     exit 1
104 fi
105
106 if [[ -z "$release_data_file" ]]
107 then
108     echo "policy release data file not specified on -d flag"
109     exit 1
110 fi
111
112 if ! [ -f "$release_data_file" ]
113 then
114     echo "policy release data file '$release_data_file' not found"
115     exit 1
116 fi
117
118 if [ -z "$issue_id" ]
119 then
120     echo "issue_id not specified on -i flag"
121     exit 1
122 fi
123
124 if ! echo "$issue_id" | grep -Eq '^POLICY-[0-9]*$'
125 then
126   echo "issue ID is invalid, it should be of form 'POLICY-nnnn'"
127   exit 1
128 fi
129
130 for specified_repo in "${pf_repos[@]}"
131 do
132     read    repo \
133             latest_released_tag \
134             latest_snapshot_tag \
135             changed_files docker_images \
136         <<< $( grep $specified_repo $release_data_file | tr ',' ' ' )
137
138     if [ ! "$repo" = "$specified_repo" ]
139     then
140         echo "repo '$specified_repo' not found in file 'pf_release_data.csv'"
141         continue
142     fi
143
144     if [ "$docker_images" = "" ]
145     then
146         continue
147     fi
148
149     for docker_image in `echo $docker_images | tr ':' ' '`
150     do
151         new_image="$docker_image:$latest_released_tag"
152
153         echo "updating OOM image $new_image . . ."
154         find $repo_location/oom/kubernetes/policy/components \
155             -name values.yaml \
156             -exec \
157                 sed -i \
158                 "s/^image:[ |\t]*onap\/$docker_image:[0-9]*\.[0-9]*\.[0-9]*$/image: onap\/$new_image/" {} \;
159         echo "OOM image $docker_image:$latest_released_tag updated"
160     done
161 done
162
163
164 echo "generating OOM commit to update policy framework docker image versions . . ."
165
166 generateCommit.sh \
167     -l $repo_location \
168     -r oom \
169     -i $issue_id \
170     -e "[POLICY] Update docker images to latest versions" \
171     -m "The image versions in policy values.yaml files have been updated"
172
173 echo "OOM commit to update policy framework docker image versions generated"
174