Beispiel #1
0
def dev_start(build, detach, filename):
    if filename is None:
        docker_compose_yml = os.path.join(CWD, HOKUSAI_CONFIG_DIR,
                                          DEVELOPMENT_YML_FILE)
    else:
        docker_compose_yml = filename

    if not os.path.isfile(docker_compose_yml):
        raise HokusaiError("Yaml file %s does not exist." % docker_compose_yml)

    def cleanup(*args):
        shout("docker-compose -f %s -p hokusai stop" % docker_compose_yml,
              print_output=True)

    for sig in EXIT_SIGNALS:
        signal.signal(sig, cleanup)

    opts = ''
    if build:
        Docker().build(filename)
    if detach:
        opts += ' -d'

    if not detach:
        print_green(
            "Starting development environment... Press Ctrl+C to stop.")

    shout("docker-compose -f %s -p hokusai up%s" % (docker_compose_yml, opts),
          print_output=True)

    if detach:
        print_green(
            "Run `hokousai dev stop` to shut down, or `hokusai dev logs --follow` to tail output."
        )
Beispiel #2
0
def test(build, cleanup):
  docker_compose_yml = os.path.join(CWD, HOKUSAI_CONFIG_DIR, TEST_YML_FILE)
  if not os.path.isfile(docker_compose_yml):
    raise HokusaiError("Yaml file %s does not exist." % docker_compose_yml)

  def on_cleanup(*args):
    shout("docker-compose -f %s -p hokusai stop" % docker_compose_yml)
    shout("docker-compose -f %s -p hokusai rm --force" % docker_compose_yml)

  if cleanup:
    for sig in EXIT_SIGNALS:
      signal.signal(sig, on_cleanup)

  opts = ' --abort-on-container-exit'
  if build:
    Docker().build()

  print_green("Starting test environment... Press Ctrl+C to stop.", newline_after=True)
  try:
    shout("docker-compose -f %s -p hokusai up%s" % (docker_compose_yml, opts), print_output=True)
    return_code = int(shout("docker wait hokusai_%s_1" % config.project_name))
  except CalledProcessError:
    if cleanup: on_cleanup()
    raise HokusaiError('Tests Failed')

  if return_code:
    raise HokusaiError('Tests Failed - Exit Code: %s\n' % return_code, return_code=return_code)
  else:
    print_green("Tests Passed")

  if cleanup: on_cleanup()

  return return_code
Beispiel #3
0
def dev_start(build, detach, filename):
    if filename is None:
        yaml_template = TemplateSelector().get(
            os.path.join(CWD, HOKUSAI_CONFIG_DIR, DEVELOPMENT_YML_FILE))
    else:
        yaml_template = TemplateSelector().get(filename)

    docker_compose_yml = YamlSpec(yaml_template).to_file()
    follow_extends(docker_compose_yml)

    def cleanup(*args):
        shout("docker-compose -f %s -p hokusai stop" % docker_compose_yml,
              print_output=True)

    for sig in EXIT_SIGNALS:
        signal.signal(sig, cleanup)

    opts = ''
    if build:
        Docker().build(filename=yaml_template)
    if detach:
        opts += ' -d'

    if not detach:
        print_green(
            "Starting development environment... Press Ctrl+C to stop.")

    shout("docker-compose -f %s -p hokusai up%s" % (docker_compose_yml, opts),
          print_output=True)

    if detach:
        print_green(
            "Run `hokousai dev stop` to shut down, or `hokusai dev logs --follow` to tail output."
        )
Beispiel #4
0
def push(tag, build, force, overwrite, skip_latest=False):
  if force is None and shout('git status --porcelain'):
    raise HokusaiError("Working directory is not clean.  Aborting.")

  if force is None and shout('git status --porcelain --ignored'):
    raise HokusaiError("Working directory contains ignored files and/or directories.  Aborting.")

  ecr = ECR()
  if not ecr.project_repo_exists():
    raise HokusaiError("ECR repo %s does not exist... did you run `hokusai setup` for this project?" % config.project_name)

  shout(ecr.get_login())
  if tag is None:
    tag = shout('git rev-parse HEAD').strip()

  if overwrite is None and ecr.tag_exists(tag):
    raise HokusaiError("Tag %s already exists in registry.  Aborting." % tag)

  if build:
    Docker().build()

  build_tag = "hokusai_%s:latest" % config.project_name

  shout("docker tag %s %s:%s" % (build_tag, ecr.project_repo, tag))
  shout("docker push %s:%s" % (ecr.project_repo, tag), print_output=True)
  print_green("Pushed %s to %s:%s" % (build_tag, ecr.project_repo, tag), newline_after=True)

  if skip_latest: return

  shout("docker tag %s %s:%s" % (build_tag, ecr.project_repo, 'latest'))
  shout("docker push %s:%s" % (ecr.project_repo, 'latest'), print_output=True)
  print_green("Pushed %s to %s:%s" % (build_tag, ecr.project_repo, 'latest'), newline_after=True)
Beispiel #5
0
def test(build, cleanup, filename, service_name):
    if filename is None:
        yaml_template = TemplateSelector().get(
            os.path.join(CWD, HOKUSAI_CONFIG_DIR, TEST_YML_FILE))
    else:
        yaml_template = TemplateSelector().get(filename)

    docker_compose_yml = YamlSpec(yaml_template).to_file()
    follow_extends(docker_compose_yml)

    def on_cleanup(*args):
        shout("docker-compose -f %s -p hokusai stop" % docker_compose_yml)
        shout("docker-compose -f %s -p hokusai rm --force" %
              docker_compose_yml)

    if cleanup:
        for sig in EXIT_SIGNALS:
            signal.signal(sig, on_cleanup)

    opts = ' --abort-on-container-exit'
    if build:
        Docker().build()

    if service_name is None:
        service_name = config.project_name

    print_green("Starting test environment... Press Ctrl+C to stop.",
                newline_after=True)
    try:
        shout("docker-compose -f %s -p hokusai up%s" %
              (docker_compose_yml, opts),
              print_output=True)
        return_code = int(shout("docker wait hokusai_%s_1" % service_name))
    except CalledProcessError:
        if cleanup: on_cleanup()
        raise HokusaiError('Tests Failed')

    if return_code:
        raise HokusaiError('Tests Failed - Exit Code: %s\n' % return_code,
                           return_code=return_code)
    else:
        print_green("Tests Passed")

    if cleanup: on_cleanup()

    return return_code
Beispiel #6
0
def build(filename):
  Docker().build(filename)
Beispiel #7
0
def build():
    Docker().build()