How to use the hokusai.lib.template_selector.TemplateSelector function in hokusai

To help you get started, we’ve selected a few hokusai examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github artsy / hokusai / test / unit / test_template_selector.py View on Github external
def test_finds_yml_file(self):
    test_file = os.path.join(self.template_path, 'test.yml')
    open(test_file, 'a').close()
    self.assertEqual(TemplateSelector().get(os.path.join(self.template_path, 'test')), test_file)
    os.remove(test_file)
github artsy / hokusai / test / unit / test_template_selector.py View on Github external
def test_finds_yaml_file(self):
    test_file = os.path.join(self.template_path, 'test.yaml')
    open(test_file, 'a').close()
    self.assertEqual(TemplateSelector().get(os.path.join(self.template_path, 'test')), test_file)
    os.remove(test_file)
github artsy / hokusai / test / unit / test_template_selector.py View on Github external
def test_finds_explicit_file_or_errors(self):
    with self.assertRaises(HokusaiError):
      TemplateSelector().get(os.path.join(self.template_path, 'test.yml'))
    test_file = os.path.join(self.template_path, 'test.yml')
    open(test_file, 'a').close()
    self.assertEqual(TemplateSelector().get(os.path.join(self.template_path, 'test.yml')), test_file)
    os.remove(test_file)
github artsy / hokusai / test / unit / test_template_selector.py View on Github external
def test_errors_with_no_template_found(self):
    with self.assertRaises(HokusaiError):
      TemplateSelector().get(os.path.join(self.template_path, 'test'))
github artsy / hokusai / hokusai / commands / development.py View on Github external
def dev_clean(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 stop" % docker_compose_yml, print_output=True)
  shout("docker-compose -f %s -p hokusai rm --force" % docker_compose_yml, print_output=True)
github artsy / hokusai / hokusai / lib / docker_compose_helpers.py View on Github external
def follow_extends(docker_compose_yml):
  with open(docker_compose_yml, 'r') as f:
    rendered_templates = []
    struct = yaml.safe_load(f.read())
    for service_name, service_spec in struct['services'].iteritems():
      if 'extends' not in service_spec or 'file' not in service_spec['extends']:
        continue
      extended_filename = service_spec['extends']['file']
      extended_template_path = os.path.join(CWD, HOKUSAI_CONFIG_DIR, extended_filename)
      if not os.path.isfile(extended_template_path):
        extended_template_path = os.path.join(CWD, HOKUSAI_CONFIG_DIR, extended_filename + '.j2')
      extended_template = TemplateSelector().get(extended_template_path)
      rendered_templates.append(YamlSpec(extended_template).to_file())
    return rendered_templates
github artsy / hokusai / hokusai / commands / development.py View on Github external
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)
github artsy / hokusai / hokusai / commands / development.py View on Github external
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()
  if detach:
    opts += ' -d'

  if not detach:
github artsy / hokusai / hokusai / services / deployment.py View on Github external
"""

    # Run the pre-deploy hook for the canonical app or a review app
    if config.pre_deploy and (filename is None or (filename and self.namespace)):
      print_green("Running pre-deploy hook '%s'..." % config.pre_deploy, newline_after=True)
      return_code = CommandRunner(self.context, namespace=self.namespace).run(tag, config.pre_deploy, constraint=constraint, tty=False)
      if return_code:
        raise HokusaiError("Pre-deploy hook failed with return code %s" % return_code, return_code=return_code)

    # Patch the deployments
    deployment_timestamp = datetime.datetime.utcnow().strftime("%s%f")

    if filename is None:
      yaml_template = TemplateSelector().get(os.path.join(CWD, HOKUSAI_CONFIG_DIR, self.context))
    else:
      yaml_template = TemplateSelector().get(filename)

    yaml_spec = YamlSpec(yaml_template).to_list()

    # If a review app, a canary app or the canonical app while updating config,
    # bust the deployment cache and populate deployments from the yaml file
    if filename or update_config:
      self.cache = []
      for item in yaml_spec:
        if item['kind'] == 'Deployment':
          self.cache.append(item)

    # If updating config, patch the spec and apply
    if update_config:
      print_green("Patching Deployments in spec %s with image digest %s" % (yaml_template, digest), newline_after=True)
      payload = []
      for item in yaml_spec:
github artsy / hokusai / hokusai / commands / development.py View on Github external
def dev_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)

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