How to use the hokusai.lib.config.config 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_config.py View on Github external
def test_config_from_file(self):
    self.assertEqual(config.config.project_name, 'hello')
    self.assertEqual(config.config.pre_deploy, 'migrate.sh')
    self.assertEqual(config.config.post_deploy, 'sh -c report.sh')
    self.assertEqual(config.config.git_remote, 'git@github.com:artsy/hokusai.git')
    self.assertEqual(config.config.template_config_file, './test/fixtures/template_config.yml')
github artsy / hokusai / test / unit / test_config.py View on Github external
def test_config_from_file(self):
    self.assertEqual(config.config.project_name, 'hello')
    self.assertEqual(config.config.pre_deploy, 'migrate.sh')
    self.assertEqual(config.config.post_deploy, 'sh -c report.sh')
    self.assertEqual(config.config.git_remote, 'git@github.com:artsy/hokusai.git')
    self.assertEqual(config.config.template_config_file, './test/fixtures/template_config.yml')
github artsy / hokusai / test / unit / test_config.py View on Github external
def test_config_from_file(self):
    self.assertEqual(config.config.project_name, 'hello')
    self.assertEqual(config.config.pre_deploy, 'migrate.sh')
    self.assertEqual(config.config.post_deploy, 'sh -c report.sh')
    self.assertEqual(config.config.git_remote, 'git@github.com:artsy/hokusai.git')
    self.assertEqual(config.config.template_config_file, './test/fixtures/template_config.yml')
github artsy / hokusai / hokusai / commands / setup.py View on Github external
env = Environment(loader=FileSystemLoader(os.path.join(base_path, 'hokusai', 'templates')))
    except:
      env = Environment(loader=PackageLoader('hokusai', 'templates'))

  required_templates = [
    'Dockerfile.j2',
    '.dockerignore.j2',
    'hokusai/build.yml.j2',
    'hokusai/development.yml.j2',
    'hokusai/test.yml.j2',
    'hokusai/staging.yml.j2',
    'hokusai/production.yml.j2'
  ]

  template_context = {
    "project_name": config.project_name,
    "project_repo": ecr.project_repo
  }

  for s in template_vars:
    if '=' not in s:
      raise HokusaiError("Error: template variables must be of the form 'key=value'")
    split = s.split('=', 1)
    template_context[split[0]] = split[1]

  try:
    for template in required_templates:
      if custom_template_dir and not os.path.isfile(os.path.join(custom_template_dir, template)):
        raise HokusaiError("Could not find required template file %s" % template)
      with open(os.path.join(CWD, template.rstrip('.j2')), 'w') as f:
        f.write(env.get_template(template).render(**template_context))
      print_green("Created %s" % template.rstrip('.j2'))
github artsy / hokusai / hokusai / services / command_runner.py View on Github external
if os.environ.get('USER') is not None:
      uuid = "%s-%s" % (os.environ.get('USER'), k8s_uuid())
    else:
      uuid = k8s_uuid()

    name = "%s-hokusai-run-%s" % (config.project_name, uuid)
    image_name = "%s:%s" % (self.ecr.project_repo, image_tag)
    container = {
      "args": cmd.split(' '),
      "name": name,
      "image": image_name,
      "imagePullPolicy": "Always",
      'envFrom': [{'configMapRef': {'name': "%s-environment" % config.project_name}}]
    }

    run_tty = tty or config.run_tty
    if run_tty:
      container.update({
        "stdin": True,
        "stdinOnce": True,
        "tty": True
      })

    if env:
      container['env'] = []
      for s in env:
        if '=' not in s:
          raise HokusaiError("Error: environment variables must be of the form 'KEY=VALUE'")
        split = s.split('=', 1)
        container['env'].append({'name': split[0], 'value': split[1]})

    spec = { "containers": [container] }
github artsy / hokusai / hokusai / commands / gitcompare.py View on Github external
def gitcompare(org_name, git_compare_link):
  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(git_compare_link % (org_name, config.project_name, production_tag, staging_tag))
github artsy / hokusai / hokusai / commands / logs.py View on Github external
def logs(context, timestamps, follow, tail, namespace=None):
  kctl = Kubectl(context, namespace=namespace)

  opts = ''
  if timestamps:
    opts += ' --timestamps'
  if follow:
    opts += ' --follow'
  if tail:
    opts += " --tail=%s" % tail

  pods = kctl.get_objects('pod', selector="app=%s,layer=application" % config.project_name)
  pods = filter(lambda pod: pod['status']['phase'] == 'Running', pods)
  containers = []

  for pod in pods:
    for container in pod['spec']['containers']:
      containers.append({'pod': pod['metadata']['name'], 'name': container['name']})

  commands = [kctl.command("logs %s %s%s" % (container['pod'], container['name'], opts)) for container in containers]
  shout_concurrent(commands, print_output=True)
github artsy / hokusai / hokusai / commands / push.py View on Github external
ecr = ECR()
  if not ecr.project_repo_exists():
    raise HokusaiError("ECR repo %s does not exist... did you run `hokusai setup` for this project?" % config.project_name)

  shout(ecr.get_login(), mask=(r'^(docker login -u) .+ (-p) .+ (.+)$', r'\1 ****** \2 ***** \3'))
  if tag is None:
    tag = shout('git rev-parse HEAD').strip()

  if overwrite is None and ecr.tag_exists(tag):
    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)