def test_dirty_tags_various(func, tmpdir): tmp = tmpdir.join('shipwright-sample') path = str(tmp) source = pkg_resources.resource_filename( __name__, 'examples/shipwright-sample', ) repo = create_repo(path, source) scm = source_control.GitSourceControl( path=path, namespace='shipwright', name_map={}, ) assert not scm.is_dirty() old_refs = _refs(scm.targets()) old_ref_str = scm.this_ref_str() tag = repo.head.ref.commit.hexsha[:12] expected_tag_suffix = func(tmp, repo) or '-dirty-0d6d6d2f8739' assert scm.is_dirty() new_refs = _refs(scm.targets()) new_ref_str = scm.this_ref_str() assert new_refs['shipwright/base'] != old_refs['shipwright/base'] dirty_tag = tag + expected_tag_suffix assert new_refs == { 'shipwright/base': dirty_tag, 'shipwright/service1': dirty_tag, 'shipwright/shared': dirty_tag, } assert old_ref_str == tag assert new_ref_str == dirty_tag
def test_dirty_tags_new_dir(tmpdir): tmp = tmpdir.join('shipwright-sample') path = str(tmp) source = pkg_resources.resource_filename( __name__, 'examples/shipwright-sample', ) repo = create_repo(path, source) scm = source_control.GitSourceControl( path=path, namespace='shipwright', name_map={}, ) assert not scm.is_dirty() old_ref_str = scm.this_ref_str() tag = repo.head.ref.commit.hexsha[:12] tmp.join('service2').mkdir() tmp.join('service2/Dockerfile').write('FROM busybox\n') assert scm.is_dirty() new_refs = _refs(scm.targets()) new_ref_str = scm.this_ref_str() dirty_suffix = '-dirty-f2f0df80ff0f' service2_tag = 'g' * 12 + dirty_suffix assert new_refs['shipwright/base'] == tag assert new_refs['shipwright/shared'] == tag assert new_refs['shipwright/service1'] == tag assert new_refs['shipwright/service2'] == service2_tag assert new_refs == { 'shipwright/base': tag, 'shipwright/service1': tag, 'shipwright/shared': tag, 'shipwright/service2': service2_tag, } assert old_ref_str == tag assert new_ref_str == tag + dirty_suffix
def test_default_tags_works_with_detached_head(tmpdir): tmp = tmpdir.join('shipwright-sample') path = str(tmp) source = pkg_resources.resource_filename( __name__, 'examples/shipwright-sample', ) repo = create_repo(path, source) old_commit = repo.head.ref.commit tmp.join('service1/base.txt').write('Hi mum') commit_untracked(repo) repo.head.reference = old_commit scm = source_control.GitSourceControl( path=path, namespace=None, name_map=None, ) assert scm.default_tags() == []
def run(path, arguments, client_cfg, environ): args = process_arguments( path, arguments, client_cfg, environ, ) build_targets, no_build, command_name, dump_file, config, client = args namespace = config['namespace'] name_map = config.get('names', {}) scm = source_control.GitSourceControl(path, namespace, name_map) sw = Shipwright(scm, client, arguments['tags']) command = getattr(sw, command_name) show_progress = sys.stdout.isatty() errors = [] if no_build: events = command(build_targets, no_build) else: events = command(build_targets) for event in events: if dump_file: dump_file.write(json.dumps(event)) dump_file.write('\n') if 'error' in event: errors.append(event) msg = pretty_event(event, show_progress) if msg is not None: print(msg) if errors: print('The following errors occurred:', file=sys.stdout) messages = [pretty_event(error, True) for error in errors] for msg in sorted(m for m in messages if m is not None): print(msg, file=sys.stdout) sys.exit(1)
def test_dirty_tags_tracked(tmpdir): tmp = tmpdir.join('shipwright-sample') path = str(tmp) source = pkg_resources.resource_filename( __name__, 'examples/shipwright-sample', ) repo = create_repo(path, source) scm = source_control.GitSourceControl( path=path, namespace='shipwright', name_map={}, ) assert not scm.is_dirty() old_refs = _refs(scm.targets()) old_ref_str = scm.this_ref_str() tag = repo.head.ref.commit.hexsha[:12] tmp.join('shared/base.txt').write('Hi mum') # Untracked repo.index.add(['shared/base.txt']) assert scm.is_dirty() new_refs = _refs(scm.targets()) new_ref_str = scm.this_ref_str() assert new_refs['shipwright/base'] == old_refs['shipwright/base'] assert new_refs['shipwright/shared'] != old_refs['shipwright/shared'] assert new_refs['shipwright/service1'] != old_refs['shipwright/service1'] dirty_tag = tag + '-dirty-adc37b7d003f' assert new_refs == { 'shipwright/base': tag, 'shipwright/service1': dirty_tag, 'shipwright/shared': dirty_tag, } assert old_ref_str == tag assert new_ref_str == dirty_tag
def run(path, arguments, client_cfg, environ, new_style_args=None): args = process_arguments( path, arguments, client_cfg, environ, ) build_targets, no_build, command_name, dump_file, config, client = args if new_style_args is None: dirty = False pull_cache = False registry_logins = [] else: dirty = new_style_args.dirty pull_cache = new_style_args.pull_cache registry_logins = _flatten(new_style_args.registry_login) namespace = config['namespace'] name_map = config.get('names', {}) scm = source_control.GitSourceControl(path, namespace, name_map) if not dirty and scm.is_dirty(): return ( 'Aborting build, due to uncommitted changes. If you are not ready ' 'to commit these changes, re-run with the --dirty flag.') if registry_logins: if isinstance(drc, Exception): raise drc registry_config = parse_registry_logins(registry_logins) registries = {} for server, config in registry_config.items(): registries[server] = drc.BaseClient( config['server'], username=config['username'], password=config['password'], api_version=2, ) the_cache = cache.DirectRegistry(client, registry.Registry(registries)) elif pull_cache: the_cache = cache.Cache(client) else: the_cache = cache.NoCache(client) sw = Shipwright(scm, client, arguments['tags'], the_cache) command = getattr(sw, command_name) show_progress = sys.stdout.isatty() errors = [] if no_build: events = command(build_targets, no_build) else: events = command(build_targets) for event in events: if dump_file: dump_file.write(json.dumps(event)) dump_file.write('\n') if 'error' in event: errors.append(event) msg = pretty_event(event, show_progress) if msg is not None: print(msg) if errors: print('The following errors occurred:', file=sys.stdout) messages = [pretty_event(error, True) for error in errors] for msg in sorted(m for m in messages if m is not None): print(msg, file=sys.stdout) sys.exit(1)