How to use the hokusai.lib.config.HOKUSAI_CONFIG_DIR 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 / hokusai / commands / namespace.py View on Github external
for c in yaml_content: update_namespace(c, clean_string(app_name))

  new_namespace = OrderedDict([
      ('apiVersion', 'v1'),
      ('kind', 'Namespace'),
      ('metadata', {
        'name': clean_string(app_name)
      })
    ])
  yaml_content = [new_namespace] + yaml_content

  with open(os.path.join(CWD, HOKUSAI_CONFIG_DIR, "%s.yml" % app_name), 'w') as output:
    output.write(YAML_HEADER)
    yaml.safe_dump_all(yaml_content, output, default_flow_style=False)

  print_green("Created %s/%s.yml" % (HOKUSAI_CONFIG_DIR, app_name))
github artsy / hokusai / hokusai / commands / namespace.py View on Github external
yaml_content = list(yaml.load_all(stream))
    except yaml.YAMLError as exc:
      raise HokusaiError("Cannot read source yaml file %s." % source_file)

  for c in yaml_content: update_namespace(c, clean_string(app_name))

  new_namespace = OrderedDict([
      ('apiVersion', 'v1'),
      ('kind', 'Namespace'),
      ('metadata', {
        'name': clean_string(app_name)
      })
    ])
  yaml_content = [new_namespace] + yaml_content

  with open(os.path.join(CWD, HOKUSAI_CONFIG_DIR, "%s.yml" % app_name), 'w') as output:
    output.write(YAML_HEADER)
    yaml.safe_dump_all(yaml_content, output, default_flow_style=False)

  print_green("Created %s/%s.yml" % (HOKUSAI_CONFIG_DIR, app_name))
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 / cli / review_app.py View on Github external
def create(app_name, verbose):
  """Creates the Kubernetes based resources defined in ./hokusai/{APP_NAME}.yml"""
  hokusai.k8s_create(KUBE_CONTEXT, tag=app_name, namespace=clean_string(app_name), filename=os.path.join(CWD, HOKUSAI_CONFIG_DIR, "%s.yml" % app_name))
github artsy / hokusai / hokusai / services / deployment.py View on Github external
deployment cache using k8s field selectors and get deployments to watch the rollout from
    the yml file spec
    """

    # 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)
github artsy / hokusai / hokusai / services / docker.py View on Github external
def build(self, filename):
    if filename is None:
      docker_compose_yml = os.path.join(CWD, HOKUSAI_CONFIG_DIR, BUILD_YAML_FILE)
      legacy_docker_compose_yml = os.path.join(CWD, HOKUSAI_CONFIG_DIR, LEGACY_BUILD_YAML_FILE)

      if not os.path.isfile(docker_compose_yml) and not os.path.isfile(legacy_docker_compose_yml):
        raise HokusaiError("Yaml files %s / %s do not exist." % (docker_compose_yml, legacy_docker_compose_yml))

      if os.path.isfile(docker_compose_yml):
        build_command = "docker-compose -f %s -p hokusai build" % docker_compose_yml
      if os.path.isfile(legacy_docker_compose_yml):
        build_command = "docker-compose -f %s -p hokusai build" % legacy_docker_compose_yml
    else:
      build_command = "docker-compose -f %s -p hokusai build" % filename

    if config.pre_build:
      build_command = "%s && %s" % (config.pre_build, build_command)

    if config.post_build:
github artsy / hokusai / hokusai / commands / kubernetes.py View on Github external
def k8s_delete(context, namespace=None, filename=None):
  if filename is None:
    kubernetes_yml = os.path.join(CWD, HOKUSAI_CONFIG_DIR, "%s.yml" % context)
  else:
    kubernetes_yml = filename

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

  if filename is None:
    configmap = ConfigMap(context, namespace=namespace)
    configmap.destroy()
    print_green("Deleted configmap %s-environment" % config.project_name)

  kctl = Kubectl(context, namespace=namespace)
  kubernetes_spec = KubernetesSpec(kubernetes_yml).to_file()
  try:
    shout(kctl.command("delete -f %s" % kubernetes_spec), print_output=True)
    print_green("Deleted Kubernetes environment %s" % kubernetes_yml)
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'
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 / 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