Ejemplo n.º 1
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."
        )
Ejemplo n.º 2
0
def dev_status(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)

    shout("docker-compose -f %s -p hokusai ps" % docker_compose_yml,
          print_output=True)
Ejemplo n.º 3
0
    def test_follows_extends(self):
        httpretty.register_uri(
            httpretty.POST,
            "https://sts.amazonaws.com/",
            body=open(
                os.path.join(os.getcwd(), 'test', 'fixtures',
                             'sts-get-caller-identity-response.xml')).read(),
            content_type="application/xml")
        httpretty.register_uri(
            httpretty.POST,
            "https://api.ecr.us-east-1.amazonaws.com/",
            body=open(
                os.path.join(os.getcwd(), 'test', 'fixtures',
                             'ecr-repositories-response.json')).read(),
            content_type="application/x-amz-json-1.1")
        docker_compose_yml = os.path.join(
            CWD, 'test/fixtures/project/hokusai/docker-compose-extends.yml.j2')
        rendered_templates = docker_compose_helpers.follow_extends(
            docker_compose_yml)
        self.assertEqual(len(rendered_templates), 1)

        with open(rendered_templates[0], 'r') as f:
            struct = yaml.safe_load(f.read())
            self.assertEqual(struct['services']['nancy']['build']['context'],
                             '../')
Ejemplo n.º 4
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
Ejemplo n.º 5
0
def dev_logs(follow, tail, 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)

    opts = ''
    if follow:
        opts += ' --follow'
    if tail:
        opts += " --tail=%i" % tail

    shout("docker-compose -f %s -p hokusai logs%s" %
          (docker_compose_yml, opts),
          print_output=True)
Ejemplo n.º 6
0
def dev_run(command, service_name, stop, 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)

    if service_name is None:
        service_name = config.project_name

    shout("docker-compose -f %s -p hokusai run %s %s" %
          (docker_compose_yml, service_name, command),
          print_output=True)

    if stop:
        shout("docker-compose -f %s -p hokusai stop" % docker_compose_yml,
              print_output=True)