Skip to content

Commit b6f340e

Browse files
committed
[docker_repro_env] Fixes for 7.6 and Amazon Linux 2
- Handle removed whitespace in 7.6 manifest before the />. - Install shadow-utils package, which is needed to install. - Hardcode package manager, do not try to be clever (fails). - Use a cache mount to download the packages - this allows Docker to cache them and avoid re-downloading when the installation fails, while simultaneously allows us to avoid storing the installation files in a layer. wget now uses -nc (no clobber), and -c to continue a partial download. Change-Id: If43c0000c6bc85537c50a037f58bdcdfb7f16f94 Reviewed-on: https://review.couchbase.org/c/kv_engine/+/223663 Reviewed-by: Faizan Alam <[email protected]> Tested-by: Vesko Karaganev <[email protected]>
1 parent 1a22089 commit b6f340e

File tree

1 file changed

+45
-35
lines changed

1 file changed

+45
-35
lines changed

scripts/docker_repro_env.py

+45-35
Original file line numberDiff line numberDiff line change
@@ -92,21 +92,21 @@ def match_outputs(outputs, keys_and_substrings):
9292
yield key, body
9393

9494

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):
96106
"""
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.
100108
"""
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]
110110

111111

112112
def select_docker_image(os_info):
@@ -302,12 +302,16 @@ def main(logfile):
302302

303303
# Extract Couchbase Server version and build
304304
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
311315

312316
dbg(f'Detected Couchbase Server: {cb_version}-{cb_build_number}')
313317

@@ -324,7 +328,7 @@ def main(logfile):
324328
dbg(f'Detected platform: {platform}')
325329

326330
# Parse the list of installed packages
327-
pkg_manager = detect_package_manager(cblog_data)
331+
pkg_manager = detect_package_manager(image)
328332
dbg(f'Detected package manager: {pkg_manager}')
329333

330334
candidate_versions = [
@@ -404,12 +408,14 @@ def main(logfile):
404408
important_packages = [
405409
'libc6',
406410
'libgcc1',
411+
'shadow-utils',
407412
]
408413
additional_packages = [
409414
('binutils', None),
410415
('gdb', None),
411416
('wget', None),
412-
('ca-certificates', None)]
417+
('ca-certificates', None),
418+
]
413419
# Docker image will have matching important_packages as well as the
414420
# additional_packages we want
415421
packages_to_install = list(preserve_packages(
@@ -455,23 +461,27 @@ def main(logfile):
455461
end='')
456462
print('true')
457463

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+
459473
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}\'')
467479
elif pkg_manager == 'rpm':
468480
# 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}\'')
475485

476486
dbg('\nDone! Run:\n docker build -t docker_repro_env - < Dockerfile && docker run --rm -it -v $PWD:/media docker_repro_env')
477487
dbg('If the image architecture does not match your host, you may need to install '

0 commit comments

Comments
 (0)