Esempio n. 1
0
def execute(args):
  """Deploy Clusterfuzz to Appengine."""
  os.environ['ROOT_DIR'] = '.'

  if not os.path.exists(args.config_dir):
    print('Please provide a valid configuration directory.')
    sys.exit(1)

  os.environ['CONFIG_DIR_OVERRIDE'] = args.config_dir

  if not common.has_file_in_path('gcloud'):
    print('Please install gcloud.')
    sys.exit(1)

  is_ci = os.getenv('TEST_BOT_ENVIRONMENT')
  if not is_ci and common.is_git_dirty():
    print('Your branch is dirty. Please fix before deploying.')
    sys.exit(1)

  if not common.has_file_in_path('gsutil'):
    print('gsutil not found in PATH.')
    sys.exit(1)

  # Build templates before deployment.
  appengine.build_templates()

  if not is_ci and not args.staging:
    if is_diff_origin_master():
      if args.force:
        print('You are not on origin/master. --force is used. Continue.')
        for _ in range(3):
          print('.')
          time.sleep(1)
        print()
      else:
        print('You are not on origin/master. Please fix or use --force.')
        sys.exit(1)

  if args.staging:
    revision = common.compute_staging_revision()
    platforms = ['linux']  # No other platforms required.
  elif args.prod:
    revision = common.compute_prod_revision()
    platforms = list(constants.PLATFORMS.keys())
  else:
    print('Please specify either --prod or --staging. For production '
          'deployments, you probably want to use deploy.sh from your '
          'configs directory instead.')
    sys.exit(1)

  deploy_zips = 'zips' in args.targets
  deploy_appengine = 'appengine' in args.targets

  package_zip_paths = []
  if deploy_zips:
    for platform_name in platforms:
      package_zip_paths.append(
          package.package(revision, platform_name=platform_name))
  else:
    # package.package calls these, so only set these up if we're not packaging,
    # since they can be fairly slow.
    appengine.symlink_dirs()
    common.install_dependencies('linux')
    with open(constants.PACKAGE_TARGET_MANIFEST_PATH, 'w') as f:
      f.write('%s\n' % revision)

  too_large_file_path = find_file_exceeding_limit('src/appengine',
                                                  APPENGINE_FILESIZE_LIMIT)
  if too_large_file_path:
    print(("%s is larger than %d bytes. It wouldn't be deployed to appengine."
           ' Please fix.') % (too_large_file_path, APPENGINE_FILESIZE_LIMIT))
    sys.exit(1)

  deploy_go = args.with_go
  if args.staging:
    _staging_deployment_helper(deploy_go)
  else:
    _prod_deployment_helper(args.config_dir, package_zip_paths, deploy_go,
                            deploy_appengine)

  with open(constants.PACKAGE_TARGET_MANIFEST_PATH) as f:
    print('Source updated to %s' % f.read())

  if platforms[-1] != common.get_platform():
    # Make sure the installed dependencies are for the current platform.
    common.install_dependencies()
Esempio n. 2
0
def execute(args):
    """Deploy Clusterfuzz to Appengine."""
    # TODO(ochang): Remove once python3 deployment is fixed.
    os.environ["CLOUDSDK_PYTHON"] = "python2"
    os.environ["ROOT_DIR"] = "."

    if not os.path.exists(args.config_dir):
        print("Please provide a valid configuration directory.")
        sys.exit(1)

    os.environ["CONFIG_DIR_OVERRIDE"] = args.config_dir

    if not common.has_file_in_path("gcloud"):
        print("Please install gcloud.")
        sys.exit(1)

    is_ci = os.getenv("TEST_BOT_ENVIRONMENT")
    if not is_ci and common.is_git_dirty():
        print("Your branch is dirty. Please fix before deploying.")
        sys.exit(1)

    if not common.has_file_in_path("gsutil"):
        print("gsutil not found in PATH.")
        sys.exit(1)

    # Build templates before deployment.
    appengine.build_templates()

    if not is_ci and not args.staging:
        if is_diff_origin_master():
            if args.force:
                print(
                    "You are not on origin/master. --force is used. Continue.")
                for _ in range(3):
                    print(".")
                    time.sleep(1)
                print()
            else:
                print(
                    "You are not on origin/master. Please fix or use --force.")
                sys.exit(1)

    if args.staging:
        revision = common.compute_staging_revision()
        platforms = ["linux"]  # No other platforms required.
    elif args.prod:
        revision = common.compute_prod_revision()
        platforms = list(constants.PLATFORMS.keys())
    else:
        print("Please specify either --prod or --staging. For production "
              "deployments, you probably want to use deploy.sh from your "
              "configs directory instead.")
        sys.exit(1)

    deploy_zips = "zips" in args.targets
    deploy_appengine = "appengine" in args.targets

    package_zip_paths = []
    if deploy_zips:
        for platform_name in platforms:
            package_zip_paths.append(
                package.package(revision, platform_name=platform_name))
    else:
        # package.package calls these, so only set these up if we're not packaging,
        # since they can be fairly slow.
        appengine.symlink_dirs()
        common.install_dependencies("linux")
        with open(constants.PACKAGE_TARGET_MANIFEST_PATH, "w") as f:
            f.write("%s\n" % revision)

    too_large_file_path = find_file_exceeding_limit("src/appengine",
                                                    APPENGINE_FILESIZE_LIMIT)
    if too_large_file_path:
        print((
            "%s is larger than %d bytes. It wouldn't be deployed to appengine."
            " Please fix.") % (too_large_file_path, APPENGINE_FILESIZE_LIMIT))
        sys.exit(1)

    deploy_go = args.with_go
    if args.staging:
        _staging_deployment_helper(deploy_go)
    else:
        _prod_deployment_helper(args.config_dir, package_zip_paths, deploy_go,
                                deploy_appengine)

    with open(constants.PACKAGE_TARGET_MANIFEST_PATH) as f:
        print("Source updated to %s" % f.read())

    if platforms[-1] != common.get_platform():
        # Make sure the installed dependencies are for the current platform.
        common.install_dependencies()