Frankfurt Staging override
[integration.git] / deployment / heat / onap-rke / scripts / createStagingOverride.pl
1 #! /usr/bin/perl
2 # ============LICENSE_START====================================================
3 # =============================================================================
4 # Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
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 # ============LICENSE_END======================================================
18
19
20 use LWP::Simple;
21 use JSON;
22
23 my $browser = LWP::UserAgent->new;
24 if(defined $ENV{'HTTPS_PROXY'}) {
25    $browser->proxy('https', $ENV{'HTTPS_PROXY'});
26 }
27 elsif(defined $ENV{'http_proxy'}) {
28    $browser->proxy('https', $ENV{'https_proxy'});
29 }
30
31
32
33 #############################################################################################
34 #  Usage: createStagingOverride.yaml staging-image-override.yaml
35 #      generates staging-image-orveride.yaml.out which can be used as a -f override file
36 #
37 #      script queries nexus3 docker.snapshot repository for the image tags 
38 #             query is only for lines with "onap/"  in the override.yaml file
39 #             ignores 2019/2010, v* tagged images to try to find the latest version numbered SNAPSHOT/STAGING:latest
40 #
41 #############################################################################################
42 $infile=$ARGV[0];
43 $outfile=">" . $infile . ".out";
44
45 my %VERSIONS='' ;
46
47 open (INFILE, $infile) or die "couldnt open INFILE $infile\n";
48 open(OUTOVER,$outfile) or die "couldnt open OUTOVER $outfile\n";
49
50 while ($line=<INFILE>) {
51         #image: onap/portal-app:2.6.0-STAGING-latest
52         if ($line=~/: onap\//) {
53                 chomp($line);
54                 ($imageJunk,$imagePath,$imageVersion) = split(':', $line);
55                 $imagePath=~s/ //g;
56                 $imageVersion=~s/ //g;
57                 $stagingImageVersion=&getVersion($imagePath,$imageVersion);
58                 $stagingImageVersion=~s/ //g;
59                 print "$imagePath , $imageVersion, $stagingImageVersion\n";
60                 $VERSIONS{$imagePath}=$stagingImageVersion;
61                 $line=~s/$imageVersion/$VERSIONS{$imagePath}/;
62                 print OUTOVER $line . "\n";
63         }
64         else {
65                 print OUTOVER $line;
66         }
67 }       
68
69 exit ;
70
71
72 sub getVersion {
73         my   ($path, $version) = @_;
74         #print $path , $version , "\n";
75         my $url = "https://nexus3.onap.org:10001/v2/$path/tags/list"  ;
76         #print $url , "\n";
77         my $response = $browser->get( $url );
78         die "Can't get $url -- ", $response->status_line 
79                 unless $response->is_success;
80         #print $response->decoded_content;
81         # name , tag [ ]
82         $response_json=decode_json $response->decoded_content; 
83         #print $response_json->{'name'} , "\n"; 
84         $latest_tag=$response_json->{'tags'}->[0] ;     
85         $tags=$response_json->{'tags'};
86         foreach my $element (@$tags)  {
87                 if ($element=~/^v/) {
88                         next ;
89                 }
90                 if ($element=~/2019/) {
91                         next ;
92                 }
93                 if ($element=~/2020/) {
94                         next ;
95                 }
96                 if ($element=~/\d\./) {
97                         #print $element , "\n";
98                         if($element gt $latest_tag) {
99                                 $latest_tag=$element;
100                         }       
101                 }
102         }
103         return $latest_tag 
104 }
105
106