How to use the hokusai.lib.common.print_green 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_common.py View on Github external
def test_print_green(self):
    with captured_output() as (out, err):
      print_green(TEST_MESSAGE)
      self.assertEqual(out.getvalue().strip(), "\x1b[32m%s\x1b[0m" % TEST_MESSAGE)
github artsy / hokusai / hokusai / commands / deployment.py View on Github external
def update(context, tag, migration, constraint, git_remote, timeout,
            namespace=None, resolve_tag_sha1=True, update_config=False, filename=None):
  if migration is not None:
    print_green("Running migration '%s' on %s..." % (migration, context), newline_after=True)
    return_code = CommandRunner(context, namespace=namespace).run(tag, migration, constraint=constraint, tty=False)
    if return_code:
      raise HokusaiError("Migration failed with return code %s" % return_code, return_code=return_code)
  Deployment(context, namespace=namespace).update(tag, constraint, git_remote, timeout,
                                                  resolve_tag_sha1=resolve_tag_sha1, update_config=update_config, filename=filename)
  print_green("Deployment updated to %s" % tag)
github artsy / hokusai / hokusai / commands / gitdiff.py View on Github external
def gitdiff():
  ecr = ECR()

  staging_tag = ecr.find_git_sha1_image_tag('staging')
  if staging_tag is None:
    raise HokusaiError("Could not find a tag for staging.  Aborting.")

  production_tag = ecr.find_git_sha1_image_tag('production')
  if production_tag is None:
    raise HokusaiError("Could not find a git SHA1 tag for production.  Aborting.")

  print_green("Comparing %s to %s" % (production_tag, staging_tag))
  for remote in shout('git remote').splitlines():
    shout("git fetch %s" % remote)
  shout("git diff %s %s" % (production_tag, staging_tag), print_output=True)
github artsy / hokusai / hokusai / commands / deployment.py View on Github external
def update(context, tag, migration, constraint, git_remote, timeout,
            namespace=None, resolve_tag_sha1=True, update_config=False, filename=None):
  if migration is not None:
    print_green("Running migration '%s' on %s..." % (migration, context), newline_after=True)
    return_code = CommandRunner(context, namespace=namespace).run(tag, migration, constraint=constraint, tty=False)
    if return_code:
      raise HokusaiError("Migration failed with return code %s" % return_code, return_code=return_code)
  Deployment(context, namespace=namespace).update(tag, constraint, git_remote, timeout,
                                                  resolve_tag_sha1=resolve_tag_sha1, update_config=update_config, filename=filename)
  print_green("Deployment updated to %s" % tag)
github artsy / hokusai / hokusai / commands / push.py View on Github external
raise HokusaiError("Tag %s already exists in registry.  Aborting." % tag)

  if build:
    Docker().build(filename)

  build_tag = "hokusai_%s:%s" % (config.project_name, local_tag)

  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)
github artsy / hokusai / hokusai / commands / deployment.py View on Github external
tag = deploy_from.current_tag
  if tag is None:
    raise HokusaiError("Could not find a tag for staging.  Aborting.")
  tag = ecr.find_git_sha1_image_tag(tag)
  if tag is None:
    print_red("Could not find a git SHA1 for tag %s.  Aborting." % tag)
    return 1

  if migration is not None:
    print_green("Running migration '%s' on production..." % migration, newline_after=True)
    return_code = CommandRunner('production').run(tag, migration, constraint=constraint, tty=False)
    if return_code:
      raise HokusaiError("Migration failed with return code %s" % return_code, return_code=return_code)

  deploy_to = Deployment('production').update(tag, constraint, git_remote, timeout)
  print_green("Promoted staging to production at %s" % tag)
github artsy / hokusai / hokusai / services / deployment.py View on Github external
def refresh(self):
    deployment_timestamp = datetime.datetime.utcnow().strftime("%s%f")
    for deployment in self.cache:
      patch = {
        "spec": {
          "template": {
            "metadata": {
              "labels": {"deploymentTimestamp": deployment_timestamp}
            }
          }
        }
      }
      print_green("Refreshing %s..." % deployment['metadata']['name'], newline_after=True)
      shout(self.kctl.command("patch deployment %s -p '%s'" % (deployment['metadata']['name'], json.dumps(patch))))

    print_green("Waiting for refresh to complete...")

    rollout_commands = [self.kctl.command("rollout status deployment/%s" % deployment['metadata']['name']) for deployment in self.cache]
    return_codes = shout_concurrent(rollout_commands, print_output=True)
    if any(return_codes):
      raise HokusaiError("Refresh failed!")
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)
  finally:
    os.unlink(kubernetes_spec)