예제 #1
0
파일: command.py 프로젝트: artsy/hokusai
 def wrapper(*args, **kwargs):
   try:
     if config_check:
       config.check()
     result = func(*args, **kwargs)
     if result is None:
       sys.exit(0)
     else:
       sys.exit(result)
   except SystemExit:
     raise
   except KeyboardInterrupt:
     raise
   except HokusaiError as e:
     print_red("ERROR: %s" % e.message)
     sys.exit(e.return_code)
   except CalledProcessError as e:
     if get_verbosity() or os.environ.get('DEBUG'):
       print_red(traceback.format_exc())
     else:
       print_red("ERROR: %s" % str(e))
     if hasattr(e, 'output') and e.output is not None:
       if type(e.output) == bytes:
         print_red("ERROR: %s" % e.output.decode('utf-8'))
       else:
         print_red("ERROR: %s" % e.output)
     sys.exit(e.returncode)
   except Exception as e:
     if get_verbosity() or os.environ.get('DEBUG'):
       print_red(traceback.format_exc())
     else:
       print_red("ERROR: %s" % str(e))
     sys.exit(1)
예제 #2
0
파일: command.py 프로젝트: rm3l/hokusai
 def wrapper(*args, **kwargs):
     try:
         if config_check:
             config.check()
         result = func(*args, **kwargs)
         if result is None:
             sys.exit(0)
         else:
             sys.exit(result)
     except HokusaiError as e:
         print_red(e.message)
         sys.exit(e.return_code)
     except SystemExit:
         raise
     except KeyboardInterrupt:
         raise
     except (CalledProcessError, Exception) as e:
         if get_verbosity() or os.environ.get('DEBUG') is '1':
             print_red(traceback.format_exc(e))
         else:
             print_red("ERROR: %s" % str(e))
         sys.exit(1)
예제 #3
0
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')

  try:
    shout('docker --version')
    check_ok('docker')
  except CalledProcessError:
    check_err('docker')
    return_code += 1

  try:
    shout('docker-compose --version')
    check_ok('docker-compose')
  except CalledProcessError:
    check_err('docker-compose')
    return_code += 1

  try:
    shout('kubectl version')
    check_ok('kubectl')
  except CalledProcessError:
    check_err('kubectl')
    return_code += 1

  try:
    shout('git version')
    check_ok('git')
  except CalledProcessError:
    check_err('git')
    return_code += 1

  if os.environ.get('AWS_ACCESS_KEY_ID') is not None:
    check_ok('$AWS_ACCESS_KEY_ID')
  else:
    check_err('$AWS_ACCESS_KEY_ID')
    return_code += 1

  if os.environ.get('AWS_SECRET_ACCESS_KEY') is not None:
    check_ok('$AWS_SECRET_ACCESS_KEY')
  else:
    check_err('$AWS_SECRET_ACCESS_KEY')
    return_code += 1

  ecr = ECR()
  if ecr.project_repo_exists():
    check_ok("ECR repository '%s'" % config.project_name)
  else:
    check_err("ECR repository '%s'" % config.project_name)
    return_code += 1

  if not os.path.isfile(os.path.join(os.getcwd(), 'hokusai/build.yml')):
    if os.path.isfile(os.path.join(os.getcwd(), 'hokusai/common.yml')):
      check_ok('./hokusai/common.yml')
    else:
      check_err('./hokusai/build.yml')
  else:
    check_ok('./hokusai/build.yml')
    return_code += 1

  if os.path.isfile(os.path.join(os.getcwd(), 'hokusai/development.yml')):
    check_ok('./hokusai/development.yml')
  else:
    check_err('./hokusai/development.yml')
    return_code += 1

  if os.path.isfile(os.path.join(os.getcwd(), 'hokusai/test.yml')):
    check_ok('./hokusai/test.yml')
  else:
    check_err('./hokusai/test.yml')
    return_code += 1

  for context in ['staging', 'production']:
    if context in Kubectl('staging').contexts():
      check_ok("kubectl context '%s'" % context)
    else:
      check_err("kubectl context '%s'" % context)
      return_code += 1

    if os.path.isfile(os.path.join(os.getcwd(), "hokusai/%s.yml" % context)):
      check_ok("./hokusai/%s.yml" % context)
    else:
      check_err("./hokusai/%s.yml" % context)
      return_code += 1

  return return_code