def execute(args): """Run the bot.""" if not args.skip_install_deps: common.install_dependencies() appengine_path = appengine.find_sdk_path() _setup_bot_directory(args) _setup_environment_and_configs(args, appengine_path) try: original_root_dir = os.path.abspath('.') os.chdir(os.path.join(args.directory, 'clusterfuzz')) if os.getenv('USE_GO_WORKER'): proc = common.execute_async( 'bazel run //go/untrusted_runner:worker', cwd=os.path.join(original_root_dir, 'src')) else: proc = common.execute_async('python src/python/bot/startup/run_bot.py') def _stop_handler(*_): print 'Bot has been stopped. Exit.' proc.kill() signal.signal(signal.SIGTERM, _stop_handler) common.process_proc_output(proc) proc.wait() except KeyboardInterrupt: _stop_handler()
def execute(args): """Install all required dependencies for running tests, the appengine, and the bot.""" is_reproduce_tool_setup = args.only_reproduce common.install_dependencies(is_reproduce_tool_setup=is_reproduce_tool_setup) # App engine setup is not needed for the reproduce tool. if not is_reproduce_tool_setup: appengine.symlink_dirs() print('Bootstrap successfully finished.')
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()
def package(revision, target_zip_dir=constants.PACKAGE_TARGET_ZIP_DIRECTORY, target_manifest_path=constants.PACKAGE_TARGET_MANIFEST_PATH, platform_name=None): """Prepare clusterfuzz-source.zip.""" is_ci = os.getenv('TEST_BOT_ENVIRONMENT') if not is_ci and common.is_git_dirty(): print('Your branch is dirty. Please fix before packaging.') sys.exit(1) if not _is_nodejs_up_to_date(): print( 'You do not have nodejs, or your nodejs is not at least version 4.' ) sys.exit(1) common.install_dependencies(platform_name=platform_name) # This needs to be done before packaging step to let src/appengine/config be # archived for bot. appengine.symlink_dirs() _, ls_files_output = common.execute('git -C . ls-files', print_output=False) file_paths = ls_files_output.splitlines() if not os.path.exists(target_zip_dir): os.makedirs(target_zip_dir) target_zip_name = constants.LEGACY_ZIP_NAME if platform_name: target_zip_name = platform_name + '.zip' target_zip_path = os.path.join(target_zip_dir, target_zip_name) _clear_zip(target_zip_path) output_file = zipfile.ZipFile(target_zip_path, 'w', zipfile.ZIP_DEFLATED) # Add files from git. for file_path in file_paths: if (file_path.startswith('config') or file_path.startswith('local') or file_path.startswith(os.path.join('src', 'appengine')) or file_path.startswith(os.path.join('src', 'local')) or file_path.startswith(os.path.join('src', 'python', 'tests'))): continue _add_to_zip(output_file, file_path) # These are project configuration yamls. for path in _get_files(os.path.join('src', 'appengine', 'config')): _add_to_zip(output_file, path) # These are third party dependencies. for path in _get_files(os.path.join('src', 'third_party')): _add_to_zip(output_file, path) output_file.close() with open(target_manifest_path, 'w') as f: f.write('%s\n' % revision) with zipfile.ZipFile(target_zip_path, 'a', zipfile.ZIP_DEFLATED) as f: _add_to_zip(f, target_manifest_path, constants.PACKAGE_TARGET_MANIFEST_PATH) print('Revision: %s' % revision) print() print('%s is ready.' % target_zip_path) return target_zip_path
def execute(args): """Run the server.""" os.environ['LOCAL_DEVELOPMENT'] = 'True' common.kill_leftover_emulators() if not args.skip_install_deps: common.install_dependencies() # Do this everytime as a past deployment might have changed these. appengine.symlink_dirs() # Deploy all yaml files from test project for basic appengine deployment and # local testing to work. This needs to be called on every iteration as a past # deployment might have overwritten or deleted these config files. yaml_paths = local_config.GAEConfig().get_absolute_path('deployment.prod3') appengine.copy_yamls_and_preprocess(yaml_paths) # Build templates. appengine.build_templates() # Clean storage directory if needed. if args.bootstrap or args.clean: if os.path.exists(args.storage_path): print('Clearing local datastore by removing %s.' % args.storage_path) shutil.rmtree(args.storage_path) if not os.path.exists(args.storage_path): os.makedirs(args.storage_path) # Set up local GCS buckets and symlinks. bootstrap_gcs(args.storage_path) # Start pubsub emulator. pubsub_emulator = test_utils.start_cloud_emulator( 'pubsub', args=['--host-port=' + constants.PUBSUB_EMULATOR_HOST], data_dir=args.storage_path) test_utils.setup_pubsub(constants.TEST_APP_ID) # Start Datastore emulator datastore_emulator = test_utils.start_cloud_emulator( 'datastore', args=['--host-port=' + constants.DATASTORE_EMULATOR_HOST], data_dir=args.storage_path, store_on_disk=True) # Start our custom GCS emulator. local_gcs = common.execute_async('go run emulators/gcs.go -storage-path=' + args.storage_path, cwd='local') if args.bootstrap: bootstrap_db() start_cron_threads() os.environ['APPLICATION_ID'] = constants.TEST_APP_ID os.environ['LOCAL_DEVELOPMENT'] = 'True' os.environ['LOCAL_GCS_BUCKETS_PATH'] = 'local_gcs' os.environ['LOCAL_GCS_SERVER_HOST'] = constants.LOCAL_GCS_SERVER_HOST os.environ['DATASTORE_EMULATOR_HOST'] = constants.DATASTORE_EMULATOR_HOST os.environ['PUBSUB_EMULATOR_HOST'] = constants.PUBSUB_EMULATOR_HOST os.environ['GAE_ENV'] = 'dev' try: cron_server = common.execute_async( 'gunicorn -b :{port} main:app'.format( port=constants.CRON_SERVICE_PORT), cwd=os.path.join('src', 'appengine')) common.execute('gunicorn -b :{port} main:app'.format( port=constants.DEV_APPSERVER_PORT), cwd=os.path.join('src', 'appengine')) except KeyboardInterrupt: print('Server has been stopped. Exit.') cron_server.terminate() datastore_emulator.cleanup() pubsub_emulator.cleanup() local_gcs.terminate()
def execute(args): """Run the server.""" os.environ['LOCAL_DEVELOPMENT'] = 'True' common.kill_leftover_emulators() if not args.skip_install_deps: common.install_dependencies() # Do this everytime as a past deployment might have changed these. appengine.symlink_dirs() # Deploy all yaml files from test project for basic appengine deployment and # local testing to work. This needs to be called on every iteration as a past # deployment might have overwritten or deleted these config files. yaml_paths = local_config.GAEConfig().get_absolute_path('deployment.prod') appengine.copy_yamls_and_preprocess(yaml_paths) # Build templates. appengine.build_templates() # Clean storage directory if needed. if args.bootstrap or args.clean: if os.path.exists(args.storage_path): print 'Clearing local datastore by removing %s.' % args.storage_path shutil.rmtree(args.storage_path) if not os.path.exists(args.storage_path): os.makedirs(args.storage_path) # Set up local GCS buckets and symlinks. bootstrap_gcs(args.storage_path) # Start pubsub emulator. pubsub_emulator = test_utils.start_cloud_emulator( 'pubsub', args=['--host-port=' + constants.PUBSUB_EMULATOR_HOST], data_dir=args.storage_path) test_utils.setup_pubsub(constants.TEST_APP_ID) # Start our custom GCS emulator. local_gcs = common.execute_async( 'bazel run //go/testing/gcs ' '--sandbox_writable_path=$(pwd)/../local/storage/local_gcs ' '-- -storage-path=$(pwd)/../local/storage/local_gcs', cwd='src') if args.bootstrap: bootstrap_db() start_cron_threads() try: common.execute( '{dev_appserver_path} -A {project} --skip_sdk_update_check=1 ' '--storage_path={storage_path} --port={appserver_port} ' '--admin_port={admin_port} ' '--datastore_emulator_port={datastore_emulator_port} ' '--require_indexes=true --log_level={log_level} ' '--dev_appserver_log_level={log_level} ' '--support_datastore_emulator=true ' '--env_var LOCAL_DEVELOPMENT=True ' '--env_var PUBSUB_EMULATOR_HOST={pubsub_emulator_host} ' '--env_var LOCAL_GCS_BUCKETS_PATH=local_gcs ' '--env_var LOCAL_GCS_SERVER_HOST={local_gcs_server_host} ' 'src/appengine src/appengine/cron-service.yaml'.format( dev_appserver_path=_dev_appserver_path(), project=constants.TEST_APP_ID, storage_path=args.storage_path, appserver_port=constants.DEV_APPSERVER_PORT, admin_port=constants.DEV_APPSERVER_ADMIN_PORT, datastore_emulator_port=constants.DATASTORE_EMULATOR_PORT, log_level=args.log_level, pubsub_emulator_host=constants.PUBSUB_EMULATOR_HOST, local_gcs_server_host=constants.LOCAL_GCS_SERVER_HOST)) except KeyboardInterrupt: print 'Server has been stopped. Exit.' pubsub_emulator.cleanup() local_gcs.terminate()
def execute(_): """Install all required dependencies for running tests, the appengine, and the bot.""" common.install_dependencies() appengine.symlink_dirs() print('Bootstrap successfully finished.')
def execute(_): """Install all required dependencies for running tests, the appengine, and the bot.""" common.install_dependencies() appengine.symlink_dirs()
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()