From 665070088b92dc2d3d45becc88739e203bd0077e Mon Sep 17 00:00:00 2001 From: Stanislaw Adaszewski Date: Tue, 26 May 2020 10:21:40 +0200 Subject: [PATCH] Improve test_build_image and add options to copy step as a by-product. --- focker/jail.py | 2 ++ focker/steps.py | 7 ++++++- tests/test_compose.py | 15 +++++++++++++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/focker/jail.py b/focker/jail.py index 1512891..486c01a 100644 --- a/focker/jail.py +++ b/focker/jail.py @@ -160,6 +160,8 @@ def jail_run(path, command, mounts=[]): print('Running:', ' '.join(command)) try: do_mounts(path, mounts) + os.makedirs(os.path.join(path, 'etc'), exist_ok=True) + os.makedirs(os.path.join(path, 'dev'), exist_ok=True) shutil.copyfile('/etc/resolv.conf', os.path.join(path, 'etc/resolv.conf')) res = subprocess.run(command) finally: diff --git a/focker/steps.py b/focker/steps.py index cf3f77f..e01c195 100644 --- a/focker/steps.py +++ b/focker/steps.py @@ -67,10 +67,15 @@ class CopyStep(object): lst = [ self.spec ] \ if not isinstance(self.spec[0], list) \ else self.spec - for (source, target) in lst: + for entry in lst: + (source, target) = entry[:2] + options = entry[2] if len(entry) > 2 else {} target = target.strip('/') + os.makedirs(os.path.split(os.path.join(path, target))[0], exist_ok=True) shutil.copyfile(os.path.join(kwargs['args'].focker_dir, source), os.path.join(path, target)) + if 'chmod' in options: + os.chmod(os.path.join(path, target), options['chmod']) def create_step(spec): diff --git a/tests/test_compose.py b/tests/test_compose.py index d91e9a9..242d7c5 100644 --- a/tests/test_compose.py +++ b/tests/test_compose.py @@ -134,13 +134,22 @@ def test_build_volumes(): def test_build_images(): - # focker_unlock() + subprocess.check_output(['focker', 'image', 'remove', '--force', 'test-focker-bootstrap']) + subprocess.check_output(['focker', 'bootstrap', '--dry-run', '--tags', 'test-focker-bootstrap']) subprocess.check_output(['focker', 'image', 'remove', '--force', 'test-build-images']) with TemporaryDirectory() as d: with open(os.path.join(d, 'Fockerfile'), 'w') as f: yaml.dump({ - 'base': 'freebsd-latest', + 'base': 'test-focker-bootstrap', 'steps': [ + { 'copy': [ + [ '/bin/sh', '/bin/sh', { 'chmod': 0o777 } ], + [ '/lib/libedit.so.7', '/lib/libedit.so.7' ], + [ '/lib/libncursesw.so.8', '/lib/libncursesw.so.8' ], + [ '/lib/libc.so.7', '/lib/libc.so.7' ], + [ '/usr/bin/touch', '/usr/bin/touch', { 'chmod': 0o777 } ], + [ '/libexec/ld-elf.so.1', '/libexec/ld-elf.so.1', { 'chmod': 0o555 } ] + ] }, { 'run': 'touch /test-build-images' } ] }, f) @@ -153,3 +162,5 @@ def test_build_images(): name, _ = zfs_find('test-build-images', focker_type='image') assert os.path.exists(os.path.join(zfs_mountpoint(name), 'test-build-images')) subprocess.check_output(['focker', 'image', 'remove', '--force', 'test-build-images']) + subprocess.check_output(['focker', 'image', 'prune']) + subprocess.check_output(['focker', 'image', 'remove', '--force', 'test-focker-bootstrap'])