Revert "Remove Grafana charm"
[osm/devops.git] / tools / promote-charms-and-snaps.sh
1 #!/bin/bash
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 #
15
16 CHANNEL=${1:-latest}
17 SOURCE=${2:-beta}
18 TARGET=${3:-candidate}
19 echo "==========================================================="
20 echo Promoting charms and snaps from $SOURCE to $TARGET
21 echo ""
22
23 for snap in osmclient ; do
24
25 echo "==========================================================="
26 echo "${snap}"
27
28 track="${CHANNEL}/${SOURCE}\\*"
29 SOURCE_REV=$(snapcraft revisions $snap | grep $track | tail -1 | awk '{print $1}')
30 track="${CHANNEL}/${TARGET}\\*"
31 TARGET_REV=$(snapcraft revisions $snap | grep $track | tail -1 | awk '{print $1}')
32
33 echo "$SOURCE: $SOURCE_REV, $TARGET: $TARGET_REV"
34
35 if [ -z $TARGET_REV ] || [ $SOURCE_REV -ne $TARGET_REV ]; then
36 echo "Promoting $SOURCE_REV to beta in place of $TARGET_REV"
37 track="${CHANNEL}/${TARGET}"
38 snapcraft release $snap $SOURCE_REV $track
39 fi
40
41 done
42
43 for charm in \
44 'osm' \
45 'osm-ha' \
46 'osm-grafana' \
47 'mongodb-exporter-k8s' \
48 'mysqld-exporter-k8s' \
49 'osm-lcm' \
50 'osm-mon' \
51 'osm-nbi' \
52 'osm-ng-ui' \
53 'osm-pol' \
54 'osm-ro' \
55 'osm-prometheus' \
56 'osm-vca-integrator' ; do
57
58 echo "==========================================================="
59 echo "${charm}"
60
61 charmcraft status $charm --format json > ${charm}.json
62 isCharm=$(grep architecture ${charm}.json | wc -l 2>/dev/null)
63 resourceArgument=""
64
65 if [ $isCharm -gt 0 ]; then
66 base=20.04
67 is2204=$(cat ${charm}.json | jq -r ".[] | select(.track==\"$CHANNEL\") | .mappings[] | select(.base.architecture==\"amd64\" and .base.channel==\"22.04\")"|wc -l)
68 if [ $is2204 -gt 0 ]; then
69 base=22.04
70 fi
71
72
73 SOURCE_REV=$(cat ${charm}.json | jq -r ".[] | select(.track==\"$CHANNEL\") | .mappings[] | select(.base.architecture==\"amd64\" and .base.channel==\"$base\") | .releases[] | select(.channel==\"$CHANNEL/$SOURCE\")| .version"|head -1)
74 TARGET_REV=$(cat ${charm}.json | jq -r ".[] | select(.track==\"$CHANNEL\") | .mappings[] | select(.base.architecture==\"amd64\" and .base.channel==\"$base\") | .releases[] | select(.channel==\"$CHANNEL/$TARGET\")| .version"|head -1)
75
76
77 index=0
78 while [ $index -lt 5 ]; do
79 resourceName=$(cat ${charm}.json | jq -r ".[] | select(.track==\"$CHANNEL\") | .mappings[] | select(.base.architecture==\"amd64\" and .base.channel==\"$base\") | .releases[] | select(.channel==\"$CHANNEL/$SOURCE\")| .resources[$index].name"|head -1)
80 resourceRevs=$(cat ${charm}.json | jq -r ".[] | select(.track==\"$CHANNEL\") | .mappings[] | select(.base.architecture==\"amd64\" and .base.channel==\"$base\") | .releases[] | select(.channel==\"$CHANNEL/$SOURCE\")| .resources[$index].revision"|head -1)
81 if [ "$resourceName" != "null" ] ; then
82 resourceArgument=" $resourceArgument --resource ${resourceName}:${resourceRevs}"
83 else
84 break
85 fi
86 ((index=index+1))
87 done
88 else
89 SOURCE_REV=$(cat ${charm}.json | jq -r ".[] | select(.track==\"$CHANNEL\") | .mappings[].releases[] | select(.channel==\"$CHANNEL/$SOURCE\")| .version"|head -1)
90 TARGET_REV=$(cat ${charm}.json | jq -r ".[] | select(.track==\"$CHANNEL\") | .mappings[].releases[] | select(.channel==\"$CHANNEL/$TARGET\")| .version"|head -1)
91 fi
92
93 rm ${charm}.json
94 echo "$SOURCE: $SOURCE_REV, $TARGET: $TARGET_REV $resourceArgument"
95
96 if [ $TARGET_REV == "null" ] || [ $SOURCE_REV -gt $TARGET_REV ] ; then
97 echo Promoting ${charm} revision ${SOURCE_REV} to ${TARGET} ${resourceArgument}
98 charmcraft release ${charm} --revision=${SOURCE_REV} ${resourceArgument} --channel=${CHANNEL}/$TARGET
99 fi
100
101 done