def main(): arguments = docopt( __doc__, options_first=False, version='Shipwright ' + version, ) repo = git.Repo(os.getcwd()) try: config = json.load( open(os.path.join(repo.working_dir, '.shipwright.json'))) except OSError: config = { 'namespace': (arguments['DOCKER_HUB_ACCOUNT'] or os.environ.get('SW_NAMESPACE')) } if config['namespace'] is None: exit("Please specify your docker hub account in\n" "the .shipwright.json config file,\n " "the command line or set SW_NAMESPACE.\n" "Run shipwright --help for more information.") assert_hostname = config.get('assert_hostname') if arguments['--x-assert-hostname']: assert_hostname = not arguments['--x-assert-hostname'] client_cfg = kwargs_from_env() fn.maybe(fn.setattr('assert_hostname', assert_hostname), client_cfg.get('tls')) client = docker.Client(version='1.18', **client_cfg) commands = ['build', 'push', 'purge'] # {'publish': false, 'purge': true, ...} = 'purge' command_name = _0([c for c in commands if arguments[c]]) or "build" command = getattr(Shipwright(config, repo, client), command_name) args = [ chain(map(exact, arguments.pop('--exact')), map(dependents, arguments.pop('--dependents')), map(exclude, arguments.pop('--exclude')), map(upto, arguments.pop('--upto')), map(upto, arguments.pop('TARGET'))) ] if command_name == 'push': args.append(not arguments.pop('--no-build')) if arguments['--dump-file']: dump_file = open(arguments['--dump-file'], 'w') writer = fn.compose(switch, fn.tap(streamout(dump_file))) else: writer = switch for event in command(*args): show_fn = mk_show(event) show_fn(writer(event))
def mk_show(evt): if evt['event'] in ('build_msg', 'push') or 'error' in evt: return memo( highlight, fn.maybe(fn.getattr('name'), evt.get('container')) or evt.get('image'), ) else: return print
def mk_show(evt): if evt['event'] in ('build_msg', 'push') or 'error' in evt: return memo( highlight, fn.maybe(fn.getattr('name'), evt.get('container')) or evt.get('image') ) else: return print
def main(): arguments = docopt(__doc__, options_first=False, version='Shipwright ' + version) repo = git.Repo(os.getcwd()) try: config = json.load(open( os.path.join(repo.working_dir, '.shipwright.json') )) except OSError: config = { 'namespace': arguments['DOCKER_HUB_ACCOUNT'] or os.environ.get('SW_NAMESPACE') } if config['namespace'] is None: exit( "Please specify your docker hub account in\n" "the .shipwright.json config file,\n " "the command line or set SW_NAMESPACE.\n" "Run shipwright --help for more information." ) assert_hostname = config.get('assert_hostname') if arguments['--x-assert-hostname']: assert_hostname = not arguments['--x-assert-hostname'] client_cfg = kwargs_from_env() fn.maybe( fn.setattr('assert_hostname', assert_hostname), client_cfg.get('tls') ) client = docker.Client(version='1.15', **client_cfg) commands = ['build','push', 'purge'] # {'publish': false, 'purge': true, ...} = 'purge' command_name = _0([ c for c in commands if arguments[c] ]) or "build" command = getattr(Shipwright(config,repo,client), command_name) args = [chain( map(exact, arguments.pop('--exact')), map(dependents, arguments.pop('--dependents')), map(exclude, arguments.pop('--exclude')), map(upto, arguments.pop('--upto')), map(upto, arguments.pop('TARGET')) )] if command_name == 'push': args.append(not arguments.pop('--no-build')) if arguments['--dump-file']: dump_file = open(arguments['--dump-file'], 'w') writer = fn.compose( switch, fn.tap(streamout(dump_file)) ) else: writer = switch for event in command(*args): show_fn = mk_show(event) show_fn(writer(event))