Exemple #1
0
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))
Exemple #2
0
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))
Exemple #3
0
def tags_from_containers(client, containers):
  return map(
    compose(last_built_from_docker(client), fn.getattr('name')),
    containers
  )
Exemple #4
0
def last_built_from_docker(client, name):
  return compose(
    list,
    flatten,
    fn.fmap(key_from_image_info) # {.. 'RepoTags': [...]} -> [...]
  )(client.images(name))
Exemple #5
0
def tags_from_containers(client, containers):
    return map(compose(last_built_from_docker(client), fn.getattr('name')),
               containers)
Exemple #6
0
def last_built_from_docker(client, name):
    return compose(
        list,
        flatten,
        fn.fmap(key_from_image_info)  # {.. 'RepoTags': [...]} -> [...]
    )(client.images(name))