How to use the hokusai.lib.command.command 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 / env.py View on Github external
@command()
def set_env(context, environment, namespace=None):
  configmap = ConfigMap(context, namespace=namespace)
  configmap.load()
  for s in environment:
    if '=' not in s:
      raise HokusaiError("Error: environment variables must be of the form 'KEY=VALUE'")
    split = s.split('=', 1)
    configmap.update(split[0], split[1])
  configmap.save()
github artsy / hokusai / hokusai / commands / development.py View on Github external
@command()
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)
github artsy / hokusai / hokusai / commands / images.py View on Github external
@command()
def images(reverse_sort, limit, filter_tags, digests):
  images = ECR().images
  sorted_images = sorted(images, key=itemgetter('imagePushedAt'), reverse=not reverse_sort)
  filtered_images = filter(lambda image: 'imageTags' in image.keys(), sorted_images)
  if filter_tags:
    filtered_images = filter(lambda image: filter_tags in ', '.join(image['imageTags']), filtered_images)

  if digests:
    print_green('Image Pushed At           | Image Digest                                                            | Image Tags', newline_before=True)
    print_green('--------------------------------------------------------------------------------------------------------------------------------------')
  else:
    print_green('Image Pushed At           | Image Tags', newline_before=True)
    print_green('----------------------------------------------------------')

  for image in filtered_images[:limit]:
    image_tags = ', '.join(image['imageTags'])
github artsy / hokusai / hokusai / commands / env.py View on Github external
@command()
def unset_env(context, environment, namespace=None):
  configmap = ConfigMap(context, namespace=namespace)
  configmap.load()
  for s in environment:
    configmap.delete(s)
  configmap.save()
github artsy / hokusai / hokusai / commands / development.py View on Github external
@command()
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 / commands / kubernetes.py View on Github external
@command()
def k8s_status(context, resources, pods, describe, top, 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)

  kctl = Kubectl(context, namespace=namespace)
  kubernetes_spec = KubernetesSpec(kubernetes_yml).to_file()
  try:
    if describe:
      kctl_cmd = "describe"
      output = ""
    else:
github artsy / hokusai / hokusai / commands / run.py View on Github external
@command()
def run(context, cmd, tty, tag, env, constraint, namespace=None):
  if tag is None:
    tag = context

  return CommandRunner(context, namespace=namespace).run(tag, cmd, tty=tty, env=env, constraint=constraint)
github artsy / hokusai / hokusai / commands / namespace.py View on Github external
@command()
def create_new_app_yaml(source_file, app_name):
  with open(source_file, 'r') as stream:
    try:
      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)
      })
    ])
github artsy / hokusai / hokusai / commands / configure.py View on Github external
@command()
def configure(kubectl_version, bucket_name, key_name, config_file, install_to, install_config_to):
  if global_config.is_present() and global_config.kubectl_version is not None:
    kubectl_version = global_config.kubectl_version

  if not kubectl_version:
    raise HokusaiError("You must supply a kubectl_version")

  if global_config.is_present() and global_config.kubectl_config_file is not None:
    uri = urlparse(global_config.kubectl_config_file)
    if uri.scheme == 's3':
      bucket_name = uri.netloc
      key_name = uri.path
    if uri.scheme == 'file':
      key_name = uri.path

  if not ((bucket_name and key_name) or config_file):
github artsy / hokusai / hokusai / commands / check.py View on Github external
@command
def check():
  return_code = 0

  def check_ok(check_item):
    print_green(u'\u2714 ' + check_item + ' found')

  def check_err(check_item):
    print_red(u'\u2718 ' + check_item + ' not found')

  config.check()

  try:
    config.project_name
    check_ok('Config project-name')
  except HokusaiError:
    check_err('Config project-name')