| 4417 |
dpurdie |
1 |
########################################################################
|
|
|
2 |
# Copyright (c) VIX TECHNOLOGY (AUST) LTD
|
|
|
3 |
#
|
|
|
4 |
# Module name : jats_deploy_builder.pl
|
|
|
5 |
# Module type : Makefile system
|
|
|
6 |
# Compiler(s) : Perl
|
|
|
7 |
# Environment(s): jats
|
|
|
8 |
#
|
|
|
9 |
# Description : Extract Data from RM in order to generate a deployment
|
|
|
10 |
# structure
|
|
|
11 |
#
|
|
|
12 |
# Creates a directory structure and maintain symlinks
|
|
|
13 |
#
|
|
|
14 |
# Usage: See POD
|
|
|
15 |
#
|
|
|
16 |
#......................................................................#
|
|
|
17 |
|
|
|
18 |
require 5.008_002;
|
|
|
19 |
use strict;
|
|
|
20 |
use warnings;
|
|
|
21 |
|
|
|
22 |
use Pod::Usage;
|
|
|
23 |
use Getopt::Long;
|
|
|
24 |
use POSIX qw(strftime);
|
|
|
25 |
use File::Path;
|
|
|
26 |
use File::Basename;
|
|
|
27 |
|
|
|
28 |
use JatsError;
|
|
|
29 |
use JatsSystem;
|
|
|
30 |
use Getopt::Long;
|
|
|
31 |
use Pod::Usage;
|
|
|
32 |
use JatsRmApi;
|
|
|
33 |
use ArrayHashUtils;
|
|
|
34 |
use DBI;
|
|
|
35 |
use JatsEnv;
|
|
|
36 |
use FileUtils;
|
|
|
37 |
|
|
|
38 |
my $VERSION = "1.0.0";
|
|
|
39 |
our $GBE_DPKG;
|
|
|
40 |
our $GBE_UNIX;
|
|
|
41 |
|
|
|
42 |
my $RM_DB;
|
|
|
43 |
my $opt_verbose = 0;
|
|
|
44 |
my $opt_help = 0;
|
|
|
45 |
my $opt_manual;
|
|
|
46 |
my $opt_outdir = 'tmp';
|
|
|
47 |
my $opt_outdirFin;
|
|
|
48 |
my $opt_outdirTmp;
|
|
|
49 |
my $opt_flat = 0;
|
|
|
50 |
my $opt_quiet;
|
|
|
51 |
|
|
|
52 |
#
|
|
|
53 |
# Data Items
|
|
|
54 |
#
|
|
|
55 |
my $startTime = strftime("%F %T", localtime);
|
|
|
56 |
my $progName = basename($0);
|
|
|
57 |
my @DeployData;
|
|
|
58 |
my %data;
|
|
|
59 |
|
|
|
60 |
#-------------------------------------------------------------------------------
|
|
|
61 |
# Function : Main Entry
|
|
|
62 |
#
|
|
|
63 |
# Description :
|
|
|
64 |
#
|
|
|
65 |
# Inputs :
|
|
|
66 |
#
|
|
|
67 |
# Returns :
|
|
|
68 |
#
|
|
|
69 |
{
|
|
|
70 |
my $result = GetOptions (
|
|
|
71 |
"help+" => \$opt_help, # flag, multiple use allowed
|
|
|
72 |
"manual" => \$opt_manual, # flag
|
|
|
73 |
"verbose:+" => \$opt_verbose, # flag
|
|
|
74 |
"quiet:+" => \$opt_quiet, # flag
|
|
|
75 |
"outdir:s" => \$opt_outdir, # String
|
|
|
76 |
"flat!" => \$opt_flat, # flag
|
|
|
77 |
);
|
|
|
78 |
|
|
|
79 |
#
|
|
|
80 |
# Process help and manual options
|
|
|
81 |
#
|
|
|
82 |
pod2usage(-verbose => 0, -message => "Version: $VERSION") if ($opt_help == 1 || ! $result);
|
|
|
83 |
pod2usage(-verbose => 1) if ($opt_help == 2 );
|
|
|
84 |
pod2usage(-verbose => 2) if ($opt_manual || ($opt_help > 2));
|
|
|
85 |
|
|
|
86 |
ErrorConfig( 'name' =>'DplyBuild',
|
|
|
87 |
'verbose' => $opt_verbose,
|
|
|
88 |
'quiet' => $opt_quiet);
|
|
|
89 |
|
|
|
90 |
#
|
|
|
91 |
# Sanity Check
|
|
|
92 |
#
|
|
|
93 |
EnvImport('GBE_DPKG');
|
|
|
94 |
EnvImport('GBE_UNIX');
|
|
|
95 |
|
|
|
96 |
Error("This program does not run under Windows","Windows cannot create Symbolic Links")
|
|
|
97 |
unless ($GBE_UNIX);
|
|
|
98 |
|
|
|
99 |
#
|
|
|
100 |
# Check that the parent of the base directory exists
|
|
|
101 |
# Check that the CWD is not within the target directory
|
|
|
102 |
# If the output directory exists - check they we created it
|
|
|
103 |
# Try to prevent users from kill entire directory trees
|
|
|
104 |
#
|
|
|
105 |
InitFileUtils();
|
|
|
106 |
my $pdir = FullPath( catdir($opt_outdir, '..') );
|
|
|
107 |
Error ("Cannot create deployment sets in non existent directory","Parent directory must exist", $pdir)
|
|
|
108 |
unless(-d $pdir);
|
|
|
109 |
|
|
|
110 |
my $rdir = RelPath( FullPath($opt_outdir));
|
|
|
111 |
Error ("Cannot create deployment sets in a parent of the current directory")
|
|
|
112 |
if ($rdir eq '..' || $rdir eq '.' || $rdir =~ m~/\.\.$~);
|
|
|
113 |
|
|
|
114 |
if (-d $opt_outdir)
|
|
|
115 |
{
|
|
|
116 |
Error("Cannot create deployment sets into a directory not created by this utility", catdir($opt_outdir,'.deploy_builder'))
|
|
|
117 |
unless (-f catdir($opt_outdir,'.deploy_builder'));
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
#
|
|
|
121 |
# Set up paths for a build and swap
|
|
|
122 |
# $opt_outdirFin - The final output directory
|
|
|
123 |
# $opt_outdir - Working (tmp) output directory
|
|
|
124 |
# $opt_outdirTmp - Temp output. Used in renaming
|
|
|
125 |
#
|
|
|
126 |
$opt_outdirFin = $opt_outdir;
|
|
|
127 |
$opt_outdir = join('.', $opt_outdir, 'tmp' );
|
|
|
128 |
$opt_outdirTmp = join('.', $opt_outdir, 'tmp' );
|
|
|
129 |
|
|
|
130 |
if (-d $opt_outdir && ! -f catdir($opt_outdir, '.deploy_builder')) {
|
|
|
131 |
Error("Working directory not created by this utility", $opt_outdir)
|
|
|
132 |
}
|
|
|
133 |
|
|
|
134 |
if (-d $opt_outdirTmp && ! -f catdir($opt_outdirTmp, '.deploy_builder')) {
|
|
|
135 |
Error("Temp directory not created by this utility", $opt_outdirTmp)
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
# Cleanout working directories
|
|
|
139 |
# We have verified the we created them
|
|
|
140 |
#
|
|
|
141 |
RmDirTree($opt_outdirTmp);
|
|
|
142 |
RmDirTree($opt_outdir);
|
|
|
143 |
|
|
|
144 |
#
|
|
|
145 |
# Do the body of the work
|
|
|
146 |
#
|
|
|
147 |
GetPkgInfo();
|
|
|
148 |
createDirectories();
|
|
|
149 |
createReports();
|
|
|
150 |
#DebugDumpData("data", \%data);
|
|
|
151 |
|
|
|
152 |
#
|
|
|
153 |
# Swap in new directory structure
|
|
|
154 |
# Try to do it as fast as possible
|
|
|
155 |
# Rename the existing directory
|
|
|
156 |
# Rename the working directory
|
|
|
157 |
# Then delete what we need to delete
|
|
|
158 |
#
|
|
|
159 |
rename($opt_outdirFin,$opt_outdirTmp) if (-d $opt_outdirFin);
|
|
|
160 |
rename($opt_outdir, $opt_outdirFin);
|
|
|
161 |
RmDirTree($opt_outdir);
|
|
|
162 |
RmDirTree($opt_outdirTmp);
|
|
|
163 |
|
|
|
164 |
#
|
|
|
165 |
# All done
|
|
|
166 |
#
|
|
|
167 |
exit 0;
|
|
|
168 |
}
|
|
|
169 |
|
|
|
170 |
#-------------------------------------------------------------------------------
|
|
|
171 |
# Function : populateHash
|
|
|
172 |
#
|
|
|
173 |
# Description : Put an array of data items into a hash
|
|
|
174 |
# Clean white space from the data
|
|
|
175 |
#
|
|
|
176 |
# Inputs : pHash - ref to output hash
|
|
|
177 |
# pRow - Ref to the row data
|
|
|
178 |
# pItems - Ref to an hash array of entry names
|
|
|
179 |
|
|
|
180 |
# Returns : pHash
|
|
|
181 |
#
|
|
|
182 |
sub populateHash
|
|
|
183 |
{
|
|
|
184 |
my ($pHash, $pRow, $pItems) = @_;
|
|
|
185 |
|
|
|
186 |
foreach my $item ( @{$pItems} ) {
|
|
|
187 |
my $data = shift @{$pRow};
|
|
|
188 |
if (defined $data)
|
|
|
189 |
{
|
|
|
190 |
$data =~ s~^\s+~~;
|
|
|
191 |
$data =~ s~\s+$~~;
|
|
|
192 |
$pHash->{$item} = $data;
|
|
|
193 |
}
|
|
|
194 |
}
|
|
|
195 |
return $pHash;
|
|
|
196 |
}
|
|
|
197 |
|
|
|
198 |
#-------------------------------------------------------------------------------
|
|
|
199 |
# Function : performSqlQueryCallback
|
|
|
200 |
#
|
|
|
201 |
# Description : Perform a general Sql query and invoke a user function for
|
|
|
202 |
# each row of results
|
|
|
203 |
#
|
|
|
204 |
# Inputs : $fname - Name of query for error reporting
|
|
|
205 |
# $m_sqlstr - Query string
|
|
|
206 |
# $f_process - Function called for each row in the result
|
|
|
207 |
# Use closure to have callback modify other data
|
|
|
208 |
#
|
|
|
209 |
# Returns : Number of rows found
|
|
|
210 |
#
|
|
|
211 |
sub performSqlQueryCallback
|
|
|
212 |
{
|
|
|
213 |
my ($fname, $m_sqlstr, $f_process ) = @_;
|
|
|
214 |
my $found = 0;
|
|
|
215 |
|
|
|
216 |
connectRM(\$RM_DB) unless $RM_DB;
|
|
|
217 |
|
|
|
218 |
$m_sqlstr =~ s~\s+~ ~g;
|
|
|
219 |
Verbose3("SQL:", $m_sqlstr);
|
|
|
220 |
my $sth = $RM_DB->prepare($m_sqlstr);
|
|
|
221 |
if ( defined($sth) )
|
|
|
222 |
{
|
|
|
223 |
if ( $sth->execute( ) )
|
|
|
224 |
{
|
|
|
225 |
if ( $sth->rows )
|
|
|
226 |
{
|
|
|
227 |
while ( my @row = $sth->fetchrow_array )
|
|
|
228 |
{
|
|
|
229 |
$found++;
|
|
|
230 |
&$f_process(\@row);
|
|
|
231 |
}
|
|
|
232 |
}
|
|
|
233 |
$sth->finish();
|
|
|
234 |
}
|
|
|
235 |
else
|
|
|
236 |
{
|
|
|
237 |
Error("$fname:Execute failure: $m_sqlstr", $sth->errstr() );
|
|
|
238 |
}
|
|
|
239 |
}
|
|
|
240 |
else
|
|
|
241 |
{
|
|
|
242 |
Error("$fname:Prepare failure" );
|
|
|
243 |
}
|
|
|
244 |
|
|
|
245 |
unless ( $found )
|
|
|
246 |
{
|
|
|
247 |
Warning("$fname:No data found");
|
|
|
248 |
}
|
|
|
249 |
return $found;
|
|
|
250 |
}
|
|
|
251 |
|
|
|
252 |
#-------------------------------------------------------------------------------
|
|
|
253 |
# Function : populateArrayFromSql
|
|
|
254 |
#
|
|
|
255 |
# Description : Issue an SQL query and push the results into an array of hashes
|
|
|
256 |
# where each row from the query is a hash and the entire result is an
|
|
|
257 |
# array
|
|
|
258 |
#
|
|
|
259 |
# Inputs : name - For error reporting
|
|
|
260 |
# pArray - Ref to the output array
|
|
|
261 |
# sql - Sql to process
|
|
|
262 |
# pItems - Array of tems to extract
|
|
|
263 |
# Must match the SQL SELECT arguments
|
|
|
264 |
# Item names starting with '-' do not end up in the
|
|
|
265 |
# generated XML
|
|
|
266 |
# Returns :
|
|
|
267 |
#
|
|
|
268 |
sub populateArrayFromSql
|
|
|
269 |
{
|
|
|
270 |
my ($fname, $pArray, $m_sqlstr, $pItems) = @_;
|
|
|
271 |
|
|
|
272 |
performSqlQueryCallback($fname,
|
|
|
273 |
$m_sqlstr,
|
|
|
274 |
sub {
|
|
|
275 |
my ($pRow) = @_;
|
|
|
276 |
Verbose3("$fname:" . join(',',@$pRow));
|
|
|
277 |
my %entry;
|
|
|
278 |
push @{$pArray}, populateHash( \%entry, $pRow, $pItems);
|
|
|
279 |
}
|
|
|
280 |
);
|
|
|
281 |
#DebugDumpData("populateArrayFromSql", $pArray);
|
|
|
282 |
}
|
|
|
283 |
|
|
|
284 |
#-------------------------------------------------------------------------------
|
|
|
285 |
# Function : GetPkgInfo
|
|
|
286 |
#
|
|
|
287 |
# Description : Get Basic Package Information
|
|
|
288 |
#
|
|
|
289 |
# Inputs : pHash - Ref to Hash to populate
|
|
|
290 |
#
|
|
|
291 |
# Returns :
|
|
|
292 |
#
|
|
|
293 |
sub GetPkgInfo
|
|
|
294 |
{
|
|
|
295 |
my ($pHash) = @_;
|
|
|
296 |
my $fname = 'GetPkgInfo';
|
|
|
297 |
|
|
|
298 |
#
|
|
|
299 |
# Now extract the package infromation
|
|
|
300 |
#
|
|
|
301 |
my @items = qw(pkgName version pvid rtagid projName releaseName official );
|
|
|
302 |
my $m_sqlstr = "select pkg.pkg_name, pv.pkg_version, pv.pv_id, rt.rtag_id, prj.proj_name, rt.rtag_name, rt.official".
|
|
|
303 |
" from release_manager.package_versions pv,".
|
|
|
304 |
" release_manager.packages pkg,".
|
|
|
305 |
" release_manager.release_content rc,".
|
|
|
306 |
" release_manager.release_tags rt,".
|
|
|
307 |
" release_manager.projects prj".
|
|
|
308 |
" where pkg.pkg_id = pv.pkg_id".
|
|
|
309 |
" and prj.proj_id = rt.proj_id".
|
|
|
310 |
" and pv.is_deployable = 'Y' and pv.dlocked = 'Y'".
|
|
|
311 |
" and rc.pv_id = pv.pv_id".
|
|
|
312 |
" and rt.rtag_id = rc.rtag_id".
|
|
|
313 |
" and rt.official not in ( 'Y', 'A' )";
|
|
|
314 |
|
|
|
315 |
populateArrayFromSql( $fname, \@DeployData, $m_sqlstr, \@items );
|
|
|
316 |
|
|
|
317 |
# DebugDumpData("$fname", \@DeployData);
|
|
|
318 |
}
|
|
|
319 |
|
|
|
320 |
#-------------------------------------------------------------------------------
|
|
|
321 |
# Function : cleanName
|
|
|
322 |
#
|
|
|
323 |
# Description : Create a 'nice' file/directory name
|
|
|
324 |
# Remove / and \
|
|
|
325 |
# Remove known Swedish characeters
|
|
|
326 |
# Remove mumtiple _
|
|
|
327 |
#
|
|
|
328 |
# Inputs : $arg - Unclean element
|
|
|
329 |
#
|
|
|
330 |
# Returns : Clean Element
|
|
|
331 |
#
|
|
|
332 |
sub cleanName
|
|
|
333 |
{
|
|
|
334 |
my ($arg) = @_;
|
|
|
335 |
$arg =~ s~[/\\]~_~;
|
|
|
336 |
$arg =~ tr~åÅäÄöÖéÉ~aAaAoOeE~s;
|
|
|
337 |
$arg =~ tr~_~~s;
|
|
|
338 |
|
|
|
339 |
return $arg;
|
|
|
340 |
}
|
|
|
341 |
|
|
|
342 |
#-------------------------------------------------------------------------------
|
|
|
343 |
# Function : createDirectories
|
|
|
344 |
#
|
|
|
345 |
# Description : Given a (global) data structure - create the output
|
|
|
346 |
# directory structure
|
|
|
347 |
#
|
|
|
348 |
# Inputs :
|
|
|
349 |
#
|
|
|
350 |
# Returns :
|
|
|
351 |
#
|
|
|
352 |
my %seen;
|
|
|
353 |
sub createDirectories
|
|
|
354 |
{
|
|
|
355 |
#
|
|
|
356 |
# Delete the existing directory tree
|
|
|
357 |
#
|
|
|
358 |
mkpath($opt_outdir);
|
|
|
359 |
TouchFile(catdir($opt_outdir, '.deploy_builder'));
|
|
|
360 |
|
|
|
361 |
foreach my $entry ( @DeployData) {
|
|
|
362 |
# print("$entry->{pkgName} $entry->{version}\n");
|
|
|
363 |
|
|
|
364 |
# Clean up names
|
|
|
365 |
my $projName = cleanName($entry->{projName});
|
|
|
366 |
my $releaseName = cleanName($entry->{releaseName});
|
|
|
367 |
|
|
|
368 |
#
|
|
|
369 |
# Create a hash with ProjectName:ReleaseName:PackageName:PackageVersion
|
|
|
370 |
#
|
|
|
371 |
$data{$projName}{$releaseName}{$entry->{pkgName}}{$entry->{version}}{'noDpkg'} = 1;
|
|
|
372 |
|
|
|
373 |
#
|
|
|
374 |
# Determine source files
|
|
|
375 |
#
|
|
|
376 |
my $pkgDir = catdir($GBE_DPKG, $entry->{pkgName}, $entry->{version});
|
|
|
377 |
if ( -d $pkgDir)
|
|
|
378 |
{
|
|
|
379 |
delete $data{$projName}{$releaseName}{$entry->{pkgName}}{$entry->{version}}{'noDpkg'};
|
|
|
380 |
|
|
|
381 |
# print("$pkgDir\n");
|
|
|
382 |
#
|
|
|
383 |
# Most Deployable package export build artifacts in the root directory
|
|
|
384 |
# They are installers after all
|
|
|
385 |
# The exception are debian packages
|
|
|
386 |
# Assume that they will be in bin/XXXX/*.deb
|
|
|
387 |
#
|
|
|
388 |
opendir (my $dh, $pkgDir) || Error ("Cannot open $pkgDir: $!");
|
|
|
389 |
while ( $_ = readdir $dh)
|
|
|
390 |
{
|
|
|
391 |
next if(m~^\.~);
|
|
|
392 |
next if(m~^built.~);
|
|
|
393 |
next if(m~^descpkg~);
|
|
|
394 |
|
|
|
395 |
my $fname = catdir($pkgDir, $_);
|
|
|
396 |
scanDebian($fname,$projName,$releaseName,$entry->{pkgName},$entry->{version}) if (m~^bin$~);
|
|
|
397 |
|
|
|
398 |
next if( -d $fname );
|
|
|
399 |
|
|
|
400 |
#
|
|
|
401 |
# Scan for allowed file types
|
|
|
402 |
# Defined as regexps
|
|
|
403 |
#
|
|
|
404 |
my @allowedExtensions = qw( \.pkg.gz$ \.exe$ \.msi$ \.deb$ ^IzPack-.*\.jar$ );
|
|
|
405 |
my $allowed;
|
|
|
406 |
foreach my $ext ( @allowedExtensions) {
|
|
|
407 |
if ( m~$ext~)
|
|
|
408 |
{
|
|
|
409 |
$allowed = $ext;
|
|
|
410 |
last;
|
|
|
411 |
}
|
|
|
412 |
}
|
|
|
413 |
|
|
|
414 |
if ($allowed)
|
|
|
415 |
{
|
|
|
416 |
addDeployedFile($_, $fname,$projName,$releaseName,$entry->{pkgName},$entry->{version});
|
|
|
417 |
}
|
|
|
418 |
else
|
|
|
419 |
{
|
|
|
420 |
IgnoreFile($_, $fname,$projName,$releaseName,$entry->{pkgName},$entry->{version});
|
|
|
421 |
}
|
|
|
422 |
}
|
|
|
423 |
closedir $dh;
|
|
|
424 |
}
|
|
|
425 |
else
|
|
|
426 |
{
|
|
|
427 |
# Warn about missing packages once
|
|
|
428 |
unless (exists ($seen{$entry->{pkgName}}{$entry->{version}})) {
|
|
|
429 |
$seen{$entry->{pkgName}}{$entry->{version}}++;
|
|
|
430 |
Warning("Package Not found: $entry->{pkgName}, $entry->{version}");
|
|
|
431 |
}
|
|
|
432 |
}
|
|
|
433 |
}
|
|
|
434 |
}
|
|
|
435 |
|
|
|
436 |
#-------------------------------------------------------------------------------
|
|
|
437 |
# Function : addDeployedFile
|
|
|
438 |
#
|
|
|
439 |
# Description : Add the specified file to the deployed area
|
|
|
440 |
#
|
|
|
441 |
# Inputs : $name
|
|
|
442 |
# $target
|
|
|
443 |
# $projName
|
|
|
444 |
# $releaseName
|
|
|
445 |
# $pkgName
|
|
|
446 |
# $version
|
|
|
447 |
#
|
|
|
448 |
# Returns :
|
|
|
449 |
#
|
|
|
450 |
sub addDeployedFile
|
|
|
451 |
{
|
|
|
452 |
my ($name, $target, $projName, $releaseName, $pkgName, $version) = @_;
|
|
|
453 |
my $tdir;
|
|
|
454 |
|
|
|
455 |
push @{$data{$projName}{$releaseName}{$pkgName}{$version}{files}}, $target;
|
|
|
456 |
Verbose("deploy: $target");
|
|
|
457 |
|
|
|
458 |
#
|
|
|
459 |
# Create a flat directory structure
|
|
|
460 |
# Project/Release/Files ...
|
|
|
461 |
#
|
|
|
462 |
if ($opt_flat) {
|
|
|
463 |
$tdir = catdir($opt_outdir,$projName,$releaseName);
|
|
|
464 |
} else {
|
|
|
465 |
$tdir = catdir($opt_outdir,$projName,$releaseName,$pkgName,$version );
|
|
|
466 |
}
|
|
|
467 |
mkpath($tdir);
|
|
|
468 |
my $linkDone = eval{ symlink( $target, catdir($tdir,$name)); 1};
|
|
|
469 |
Error ("Target file system does not appear to support symlinks")
|
|
|
470 |
unless $linkDone;
|
|
|
471 |
# print("$_\n");
|
|
|
472 |
}
|
|
|
473 |
|
|
|
474 |
sub IgnoreFile
|
|
|
475 |
{
|
|
|
476 |
my ($name, $target, $projName, $releaseName, $pkgName, $version) = @_;
|
|
|
477 |
Warning("Ignore: $target");
|
|
|
478 |
|
|
|
479 |
push @{$data{$projName}{$releaseName}{$pkgName}{$version}{ignored}}, $target;
|
|
|
480 |
}
|
|
|
481 |
|
|
|
482 |
|
|
|
483 |
#-------------------------------------------------------------------------------
|
|
|
484 |
# Function : scanDebian
|
|
|
485 |
#
|
|
|
486 |
# Description : Scan for debian packages
|
|
|
487 |
# Assumes that $target is the 'bin' directory
|
|
|
488 |
#
|
|
|
489 |
# Will only transfer files from one of 'P' or the 'D' directory
|
|
|
490 |
# cannot transfer from both as the generated debian packages will
|
|
|
491 |
# have the same name
|
|
|
492 |
#
|
|
|
493 |
# Inputs : $target
|
|
|
494 |
# $projName
|
|
|
495 |
# $releaseName
|
|
|
496 |
# $pkgName
|
|
|
497 |
# $version
|
|
|
498 |
#
|
|
|
499 |
# Returns :
|
|
|
500 |
#
|
|
|
501 |
sub scanDebian
|
|
|
502 |
{
|
|
|
503 |
my ($target, $projName, $releaseName, $pkgName, $version) = @_;
|
|
|
504 |
my %binTargetType;
|
|
|
505 |
my %binTargets;
|
|
|
506 |
|
|
|
507 |
#
|
|
|
508 |
# Locate directorues under bin
|
|
|
509 |
# Build up a hash splitting out the P and D
|
|
|
510 |
#
|
|
|
511 |
opendir (my $dh, $target) || Error ("Cannot open $target: $!");
|
|
|
512 |
while ($_ = readdir $dh)
|
|
|
513 |
{
|
|
|
514 |
next if(m~^\.~);
|
|
|
515 |
next unless (m~(.*)([PD])$~);
|
|
|
516 |
my $platform = $1;
|
|
|
517 |
my $type = $2;
|
|
|
518 |
|
|
|
519 |
my $binDir = catdir($target, $_);
|
|
|
520 |
if (-d $binDir)
|
|
|
521 |
{
|
|
|
522 |
unless(exists $binTargetType{$platform}{P})
|
|
|
523 |
{
|
|
|
524 |
$binTargets{$platform} = $binDir;
|
|
|
525 |
$binTargetType{$platform}{$type} = 1;
|
|
|
526 |
}
|
|
|
527 |
}
|
|
|
528 |
}
|
|
|
529 |
closedir $dh;
|
|
|
530 |
|
|
|
531 |
foreach my $binDir (values(%binTargets))
|
|
|
532 |
{
|
|
|
533 |
opendir (my $dh, $binDir) || Error ("Cannot open $binDir: $!");
|
|
|
534 |
while ($_ = readdir $dh)
|
|
|
535 |
{
|
|
|
536 |
next if(m~^\.~);
|
|
|
537 |
next unless (m~\.deb$~);
|
|
|
538 |
my $debFile = catdir($binDir, $_);
|
|
|
539 |
addDeployedFile($_,$debFile,$projName, $releaseName, $pkgName, $version);
|
|
|
540 |
}
|
|
|
541 |
closedir $dh;
|
|
|
542 |
}
|
|
|
543 |
}
|
|
|
544 |
|
|
|
545 |
#-------------------------------------------------------------------------------
|
|
|
546 |
# Function : createReports
|
|
|
547 |
#
|
|
|
548 |
# Description : Add a report into each Release directory to describe the
|
|
|
549 |
# success and failure of the deployment
|
|
|
550 |
#
|
|
|
551 |
# Inputs :
|
|
|
552 |
#
|
|
|
553 |
# Returns :
|
|
|
554 |
#
|
|
|
555 |
sub createReports
|
|
|
556 |
{
|
|
|
557 |
my $printHdr;
|
|
|
558 |
my $ofile;
|
|
|
559 |
foreach my $projName ( sort keys %data) {
|
|
|
560 |
foreach my $releaseName ( sort keys %{$data{$projName}}) {
|
|
|
561 |
$printHdr = 0;
|
|
|
562 |
my $odir = catdir($opt_outdir,$projName,$releaseName);
|
|
|
563 |
if (-d $odir)
|
|
|
564 |
{
|
|
|
565 |
$ofile = catdir($odir, 'build_report.txt');
|
|
|
566 |
}
|
|
|
567 |
else
|
|
|
568 |
{
|
|
|
569 |
$ofile = catdir($opt_outdir, join('-',$projName,$releaseName,'build_report.txt'));
|
|
|
570 |
$printHdr = 1;
|
|
|
571 |
}
|
|
|
572 |
open (my $oh , '>', $ofile ) || Warning("Cannot open $ofile. $!");
|
|
|
573 |
print $oh ("Project: $projName\n");
|
|
|
574 |
print $oh ("Release: $releaseName\n");
|
|
|
575 |
print $oh ("Created: $startTime\n");
|
|
|
576 |
print $oh ("Created by: $progName\n");
|
|
|
577 |
print $oh ("This project has not deployed any files\n") if $printHdr;
|
|
|
578 |
|
|
|
579 |
$printHdr = 0;
|
|
|
580 |
foreach my $pkgName (sort keys %{$data{$projName}{$releaseName}}) {
|
|
|
581 |
foreach my $version (sort keys %{$data{$projName}{$releaseName}{$pkgName}}) {
|
|
|
582 |
next unless $data{$projName}{$releaseName}{$pkgName}{$version}{noDpkg};
|
|
|
583 |
print $oh ("\nThe following packages do not exist in dpkg_archive\n") unless $printHdr;
|
|
|
584 |
$printHdr = 1;
|
|
|
585 |
print $oh (" $pkgName, $version\n");
|
|
|
586 |
}
|
|
|
587 |
}
|
|
|
588 |
|
|
|
589 |
$printHdr = 0;
|
|
|
590 |
foreach my $pkgName (sort keys %{$data{$projName}{$releaseName}}) {
|
|
|
591 |
foreach my $version (sort keys %{$data{$projName}{$releaseName}{$pkgName}}) {
|
|
|
592 |
next if $data{$projName}{$releaseName}{$pkgName}{$version}{noDpkg};
|
|
|
593 |
next if $data{$projName}{$releaseName}{$pkgName}{$version}{files};
|
|
|
594 |
print $oh ("\nThe following packages do contribute any files\n") unless $printHdr;
|
|
|
595 |
$printHdr = 1;
|
|
|
596 |
print $oh (" $pkgName, $version\n");
|
|
|
597 |
}
|
|
|
598 |
}
|
|
|
599 |
|
|
|
600 |
foreach my $pkgName (sort keys %{$data{$projName}{$releaseName}}) {
|
|
|
601 |
foreach my $version (sort keys %{$data{$projName}{$releaseName}{$pkgName}}) {
|
|
|
602 |
next unless $data{$projName}{$releaseName}{$pkgName}{$version}{ignored};
|
|
|
603 |
print $oh ("\nIgnored Files from Package: $pkgName, $version\n");
|
|
|
604 |
foreach my $ifile (@{$data{$projName}{$releaseName}{$pkgName}{$version}{ignored}}) {
|
|
|
605 |
print $oh (" $ifile\n");
|
|
|
606 |
}
|
|
|
607 |
}
|
|
|
608 |
}
|
|
|
609 |
close $oh;
|
|
|
610 |
}
|
|
|
611 |
}
|
|
|
612 |
}
|
|
|
613 |
|
|
|
614 |
#-------------------------------------------------------------------------------
|
|
|
615 |
# Documentation
|
|
|
616 |
#
|
|
|
617 |
|
|
|
618 |
=pod
|
|
|
619 |
|
|
|
620 |
=for htmltoc SYSUTIL::
|
|
|
621 |
|
|
|
622 |
=head1 NAME
|
|
|
623 |
|
|
|
624 |
jats_deploy_builder - Build Deployment package sets
|
|
|
625 |
|
|
|
626 |
=head1 SYNOPSIS
|
|
|
627 |
|
|
|
628 |
jats jats_deploy_builder [options]
|
|
|
629 |
|
|
|
630 |
Options:
|
|
|
631 |
-help - Brief help message
|
|
|
632 |
-help -help - Detailed help message
|
|
|
633 |
-man - Full documentation
|
|
|
634 |
-verbose[=n] - Display additional progress messages
|
|
|
635 |
-quiet[=n] - Supress output
|
|
|
636 |
-[no]flat - Control output structure. Default noflat
|
|
|
637 |
-outdir=name - [Optional] Root of the output directory
|
|
|
638 |
|
|
|
639 |
|
|
|
640 |
=head1 OPTIONS
|
|
|
641 |
|
|
|
642 |
=over 8
|
|
|
643 |
|
|
|
644 |
=item B<-help>
|
|
|
645 |
|
|
|
646 |
Print a brief help message and exits.
|
|
|
647 |
|
|
|
648 |
=item B<-help -help>
|
|
|
649 |
|
|
|
650 |
Print a detailed help message with an explanation for each option.
|
|
|
651 |
|
|
|
652 |
=item B<-man>
|
|
|
653 |
|
|
|
654 |
Prints the manual page and exits.
|
|
|
655 |
|
|
|
656 |
=item B<-quiet[=n]>
|
|
|
657 |
|
|
|
658 |
This option suppresses normal output. It is intended to allow the program to be run
|
|
|
659 |
within a 'cron' job. Only errors will generate output to be mailed to some user.
|
|
|
660 |
|
|
|
661 |
Use a value of 3 to supress warnings.
|
|
|
662 |
|
|
|
663 |
=item B<-[no]flat>
|
|
|
664 |
|
|
|
665 |
Control the output directory format. The default is noflat.
|
|
|
666 |
|
|
|
667 |
The flat structure places all the files in one directory under the 'release' directory.
|
|
|
668 |
|
|
|
669 |
The noflat structure creates package-name/package-version subdirectories
|
|
|
670 |
under the 'release' directory.
|
|
|
671 |
|
|
|
672 |
=item B<-outdir=name>
|
|
|
673 |
|
|
|
674 |
This option specifies the root of the output directory tree created by this tool.
|
|
|
675 |
|
|
|
676 |
If the directory exists it may be deleted. The entire directory subtree is in the
|
|
|
677 |
domain of this application.
|
|
|
678 |
|
|
|
679 |
If not provided then the program will use a directory of 'tmp' within the users current
|
|
|
680 |
woking directory.
|
|
|
681 |
|
|
|
682 |
=back
|
|
|
683 |
|
|
|
684 |
=head1 DESCRIPTION
|
|
|
685 |
|
|
|
686 |
This utility program is create and maintain a set of deployed packages for all active releases
|
|
|
687 |
defined within the Release Manager Database.
|
|
|
688 |
|
|
|
689 |
The tool is intended to facilitate the continuous deployment process by maintaining
|
|
|
690 |
a collection or depeloyed packages. See 'update_release' utility for other operations.
|
|
|
691 |
|
|
|
692 |
The utility will:
|
|
|
693 |
|
|
|
694 |
=over 4
|
|
|
695 |
|
|
|
696 |
=item *
|
|
|
697 |
|
|
|
698 |
Locate all active releases in the Release Manager database
|
|
|
699 |
|
|
|
700 |
It will ignore closed and archived releases.
|
|
|
701 |
|
|
|
702 |
=item *
|
|
|
703 |
|
|
|
704 |
Locate all released packages that are marked as 'deployable'
|
|
|
705 |
|
|
|
706 |
=item *
|
|
|
707 |
|
|
|
708 |
Create a directory structure
|
|
|
709 |
|
|
|
710 |
The directory structure is of the form: 'Project Name/Release Name'.
|
|
|
711 |
|
|
|
712 |
If the 'noflat' mode has been selected, then the structure under the 'release'
|
|
|
713 |
directory will also contain the package-name/package-version.
|
|
|
714 |
|
|
|
715 |
=item *
|
|
|
716 |
|
|
|
717 |
Transfer deployable artifacts (see below) from each package into the release subdirectory.
|
|
|
718 |
|
|
|
719 |
The utilty will create symbolic links to the actual packages within dpkg_archive.
|
|
|
720 |
|
|
|
721 |
=item *
|
|
|
722 |
|
|
|
723 |
Create a 'build_report.txt' file for each release processed.
|
|
|
724 |
|
|
|
725 |
If processing actually created and populated a 'release' directory, then the report will
|
|
|
726 |
be in the 'release' directory, otherwise it will be created in the base of the target
|
|
|
727 |
directory and will be prefixed with the Project and Release name.
|
|
|
728 |
|
|
|
729 |
The report details:
|
|
|
730 |
|
|
|
731 |
=over 4
|
|
|
732 |
|
|
|
733 |
=item *
|
|
|
734 |
|
|
|
735 |
Date Time that the package set was created
|
|
|
736 |
|
|
|
737 |
=item *
|
|
|
738 |
|
|
|
739 |
Packages that did not contribute any files to the output
|
|
|
740 |
|
|
|
741 |
=item *
|
|
|
742 |
|
|
|
743 |
Packages that do not exist in dpkg_archive
|
|
|
744 |
|
|
|
745 |
=item *
|
|
|
746 |
|
|
|
747 |
Ignored files
|
|
|
748 |
|
|
|
749 |
=back
|
|
|
750 |
|
|
|
751 |
=back
|
|
|
752 |
|
|
|
753 |
=head2 Deployable Artifacts
|
|
|
754 |
|
|
|
755 |
The utilty will only process files that it considers to be depoyable. These are:
|
|
|
756 |
|
|
|
757 |
=over 4
|
|
|
758 |
|
|
|
759 |
=item *
|
|
|
760 |
|
|
|
761 |
Suitable files in the root of the package
|
|
|
762 |
|
|
|
763 |
These are:
|
|
|
764 |
|
|
|
765 |
=over 4
|
|
|
766 |
|
|
|
767 |
=item *
|
|
|
768 |
|
|
|
769 |
Solaris Packages: *.pkg.gz
|
|
|
770 |
|
|
|
771 |
=item *
|
|
|
772 |
|
|
|
773 |
Windows executable installers: *.exe
|
|
|
774 |
|
|
|
775 |
=item *
|
|
|
776 |
|
|
|
777 |
Windows installers: *.msi
|
|
|
778 |
|
|
|
779 |
=item *
|
|
|
780 |
|
|
|
781 |
Debian Packages: *.deb
|
|
|
782 |
|
|
|
783 |
=item *
|
|
|
784 |
|
|
|
785 |
IzPack Pqackages: IzPack-*.jar
|
|
|
786 |
|
|
|
787 |
=back
|
|
|
788 |
|
|
|
789 |
The concept is that only these files are deployable.
|
|
|
790 |
|
|
|
791 |
=item *
|
|
|
792 |
|
|
|
793 |
Debian packages found within subdirectores of the 'bin' directory.
|
|
|
794 |
|
|
|
795 |
Debian packages that are to be deployed should be built to follow the deployable
|
|
|
796 |
convention. Unfortunately many have not been. This tool attampts to cater for this bad
|
|
|
797 |
practice. It will examine all directories with the 'bin' subdirectory and locate one
|
|
|
798 |
of the production or debug builds. It will then transfer debians packages from the
|
|
|
799 |
found directory. Preference is given to production versions.
|
|
|
800 |
|
|
|
801 |
This process is required as the debug and production versions have the same name.
|
|
|
802 |
|
|
|
803 |
=back
|
|
|
804 |
|
|
|
805 |
=head1 EXAMPLE
|
|
|
806 |
|
|
|
807 |
=head2 jats deploy_builder -outfile=/export/devl/releases/current
|
|
|
808 |
|
|
|
809 |
This will mainatin the package sets in the '/export/devl/releases/current' directory.
|
|
|
810 |
|
|
|
811 |
=cut
|