@@ -92,21 +92,21 @@ def match_outputs(outputs, keys_and_substrings):
92
92
yield key , body
93
93
94
94
95
- def detect_package_manager (cblog_data ):
95
+ # Map supported base images to the native package manager.
96
+ PACKAGE_MANAGERS = {
97
+ 'amazonlinux' : 'rpm' ,
98
+ 'debian' : 'dpkg' ,
99
+ 'ubuntu' : 'dpkg' ,
100
+ 'redhat/ubi8' : 'rpm' ,
101
+ 'registry.access.redhat.com/ubi7/ubi' : 'rpm' ,
102
+ }
103
+
104
+
105
+ def detect_package_manager (image ):
96
106
"""
97
- Determines which package manager is in use, based on scaped the cblog_data.
98
- Expects: cblog_data contains keys 'dpkg', 'rpm' with the relevant output
99
- (error or package info).
107
+ Determines which package manager is in use, based on the base image.
100
108
"""
101
- options = set (('dpkg' , 'rpm' ))
102
- not_found = set ()
103
- for o in options :
104
- if any (('command not found' in line for line in cblog_data [o ])):
105
- not_found .add (o )
106
-
107
- available = list (options .difference (not_found ))
108
- assert len (available ) == 1 , 'Expected exactly one package manager output'
109
- return available [0 ]
109
+ return PACKAGE_MANAGERS [image ]
110
110
111
111
112
112
def select_docker_image (os_info ):
@@ -302,12 +302,16 @@ def main(logfile):
302
302
303
303
# Extract Couchbase Server version and build
304
304
manifest = '' .join (cblog_data ['manifest' ])
305
- cb_version = re .findall (
306
- r'<annotation name="VERSION" value="([\d\.]+)" />' , manifest )[0 ]
307
- cb_build_number = re .findall (
308
- r'<annotation name="BLD_NUM" value="(\d+)" />' , manifest )[0 ]
309
- cb_release = re .findall (
310
- r'<annotation name="RELEASE" value="([^"]+)" />' , manifest )[0 ]
305
+ try :
306
+ cb_version = re .findall (
307
+ r'<annotation name="VERSION" value="([\d\.]+)"\s?/>' , manifest )[0 ]
308
+ cb_build_number = re .findall (
309
+ r'<annotation name="BLD_NUM" value="(\d+)"\s?/>' , manifest )[0 ]
310
+ cb_release = re .findall (
311
+ r'<annotation name="RELEASE" value="([^"]+)"\s?/>' , manifest )[0 ]
312
+ except IndexError :
313
+ dbg (f'Error processing manifest:\n { manifest } \n ' )
314
+ raise
311
315
312
316
dbg (f'Detected Couchbase Server: { cb_version } -{ cb_build_number } ' )
313
317
@@ -324,7 +328,7 @@ def main(logfile):
324
328
dbg (f'Detected platform: { platform } ' )
325
329
326
330
# Parse the list of installed packages
327
- pkg_manager = detect_package_manager (cblog_data )
331
+ pkg_manager = detect_package_manager (image )
328
332
dbg (f'Detected package manager: { pkg_manager } ' )
329
333
330
334
candidate_versions = [
@@ -404,12 +408,14 @@ def main(logfile):
404
408
important_packages = [
405
409
'libc6' ,
406
410
'libgcc1' ,
411
+ 'shadow-utils' ,
407
412
]
408
413
additional_packages = [
409
414
('binutils' , None ),
410
415
('gdb' , None ),
411
416
('wget' , None ),
412
- ('ca-certificates' , None )]
417
+ ('ca-certificates' , None ),
418
+ ]
413
419
# Docker image will have matching important_packages as well as the
414
420
# additional_packages we want
415
421
packages_to_install = list (preserve_packages (
@@ -455,23 +461,27 @@ def main(logfile):
455
461
end = '' )
456
462
print ('true' )
457
463
458
- # Fetch and install Couchbase Server
464
+ # Use a cache for the CB Server package downloads.
465
+ run_package_cache_command = ' ' .join ((
466
+ 'RUN --mount=type=cache,target=/root/Downloads,sharing=locked cd /root/Downloads' ,
467
+ command_separator ))
468
+ # Fetch packages (in parallel)
469
+ print (run_package_cache_command ,
470
+ f'(wget -c -nc \' { server_pkg } \' & wget -c -nc \' { symbols_pkg } \' )' ,
471
+ command_separator , 'wait' )
472
+
459
473
if pkg_manager == 'dpkg' :
460
- # Fetch packages (in parallel), install and cleanup
461
- print (
462
- f'RUN wget \' { server_pkg } \' & wget \' { symbols_pkg } \' && wait ' ,
463
- command_separator , f'dpkg -i \' { server_pkg_name } \' ' ,
464
- command_separator , f'dpkg -i \' { symbols_pkg_name } \' ' ,
465
- command_separator ,
466
- f'rm \' { server_pkg_name } \' \' { symbols_pkg_name } \' ' )
474
+ # Install packages and cleanup
475
+ print (run_package_cache_command ,
476
+ f'dpkg -i \' { server_pkg_name } \' ' )
477
+ print (run_package_cache_command ,
478
+ f'dpkg -i \' { symbols_pkg_name } \' ' )
467
479
elif pkg_manager == 'rpm' :
468
480
# Fetch packages (in parallel), install and cleanup
469
- print (
470
- f'RUN wget \' { server_pkg } \' & wget \' { symbols_pkg } \' && wait ' ,
471
- command_separator , f'rpm -i --nodeps \' { server_pkg_name } \' ' ,
472
- command_separator , f'rpm -i --nodeps \' { symbols_pkg_name } \' ' ,
473
- command_separator ,
474
- f'rm \' { server_pkg_name } \' \' { symbols_pkg_name } \' ' )
481
+ print (run_package_cache_command ,
482
+ f'rpm -i --nodeps \' { server_pkg_name } \' ' )
483
+ print (run_package_cache_command ,
484
+ f'rpm -i --nodeps \' { symbols_pkg_name } \' ' )
475
485
476
486
dbg ('\n Done! Run:\n docker build -t docker_repro_env - < Dockerfile && docker run --rm -it -v $PWD:/media docker_repro_env' )
477
487
dbg ('If the image architecture does not match your host, you may need to install '
0 commit comments