def run_test(stack_dir): IMAGES_BUILT = read_var('IMAGES_BUILT') test_params = _tests_collector(stack_dir, IMAGES_BUILT) IMAGES_TEST_PASSED = [] IMAGES_TEST_ERROR = [] for image_tag, test_dirs in test_params.items(): print(f'*** Testing {image_tag} ***') environ['TEST_IMAGE'] = image_tag exit_code = pytest.main([ '-x', # exit instantly on first error or failed test *test_dirs # test dirs ]) if exit_code is pytest.ExitCode.OK: IMAGES_TEST_PASSED.append(image_tag) else: IMAGES_TEST_ERROR.append(image_tag) store_var('IMAGES_TEST_PASSED', IMAGES_TEST_PASSED) store_var('IMAGES_TEST_ERROR', IMAGES_TEST_ERROR) assert len(IMAGES_TEST_ERROR ) == 0, f"Images did not pass tests: {IMAGES_TEST_ERROR}"
def save_changed_images(): """ side-effects: """ images = ['datahub-base-notebook'] # FIXME: get_changed_images() print('Images changed:', images) store_var('IMAGES_CHANGED', images)
def save_git_info(): for fp, func in { 'GIT_HASH': GitHelper.commit_hash_tag, 'GIT_HASH_SHORT': GitHelper.commit_hash_tag_shortened, 'GIT_MESSAGE': GitHelper.commit_message, 'GIT_CHANGED_FILES': GitHelper.commit_changed_files }.items(): store_var(fp, func())
def test_integration(self, doit_handler, root_dir, stack_dir, docker_client, imgs_changed, imgs_expected): store_var('IMAGES_CHANGED', imgs_changed) # single task execution used for not running dependent tasks assert doit_handler.run(['-s', 'build', '--stack_dir', stack_dir]) == 0 imgs_built = read_var('IMAGES_BUILT') assert imgs_built == imgs_expected # test each image exists for img in imgs_built: docker_client.images.get(img)
def test_integration(self, doit_handler, root_dir, stack_dir, prep_wiki, prep_img_dep, deps_table, imgs_built): store_var('IMAGES_BUILT', imgs_built) store_var('GIT_HASH_SHORT', '1a2b3c') assert doit_handler.run(['-s', 'manifest', '--stack_dir', stack_dir]) == 0 manifests_path = os.path.join(root_dir, 'manifests') assert len(os.listdir(manifests_path)) - 1 == len( imgs_built) # exclude ".empty"
def push_images( client: docker.DockerClient, pairs: List[ImageFulltagPair], ): """ Push a list of images with their full tag names """ images_pushed = [] for image, full_tag in pairs: if ':' not in full_tag: repository = full_tag tag = 'latest' else: repository, tag = full_tag.split(':') try: logger.info(f'Attempting to push {image} to {repository}:{tag}') r = client.images.push( repository, tag, stream=True, decode=True, ) for chunk in r: logger.info(chunk) if 'status' in chunk: # "The push refers to repository XXX_repo" if repository in chunk['status']: print(chunk['status']) # "XXX_tag: digest: sha256:XXX size: XXX" elif tag in chunk['status']: print('\n' + chunk['status']) # regular progress else: print('.', end='') # push success images_pushed.append(full_tag) store_var('IMAGES_PUSHED', images_pushed) except docker.errors.APIError as e: logger.error('Push error') raise e
def __enter__(self): logger.info( f"Building image stack from {self.path} using {self.specs_fp}") build_params = self.build_spec.gen_build_args(self.path, self.git_suffix, self.images_changed) for build_param in build_params: image_name, build_path, build_args, plan_name, image_tag = build_param if not self.dry_run: # Go to build print(f'\n*** Started building "{image_tag}" ***') meta = self.build_img(image_name, build_path, build_args, plan_name, image_tag) store_var('IMAGES_BUILT', self.images_built) self.process_meta(meta, image_name, build_args, image_tag)
def test_collection(self, root_dir, stack_dir, imgs_built, expected_items): store_var('IMAGES_BUILT', imgs_built) collected = _tests_collector(stack_dir, imgs_built) assert collected == expected_items