def setup_cli(ask_repository=True, ask_revision=True): """ Setup CLI options parser and taskcluster bootstrap """ parser = argparse.ArgumentParser(description="Mozilla Code Coverage Bot") if ask_repository: parser.add_argument("--repository", default=os.environ.get("REPOSITORY")) if ask_revision: parser.add_argument("--revision", default=os.environ.get("REVISION")) parser.add_argument("--cache-root", required=True, help="Cache root, used to pull changesets") parser.add_argument( "--working-dir", required=True, help="Working dir to download artifacts and build reports", ) parser.add_argument( "--task-name-filter", default="*", help="Filter Taskcluster tasks using a glob expression", ) parser.add_argument( "--taskcluster-secret", help="Taskcluster Secret path", default=os.environ.get("TASKCLUSTER_SECRET"), ) parser.add_argument("--taskcluster-client-id", help="Taskcluster Client ID") parser.add_argument("--taskcluster-access-token", help="Taskcluster Access token") args = parser.parse_args() # Auth on Taskcluster taskcluster_config.auth(args.taskcluster_client_id, args.taskcluster_access_token) # Then load secrets secrets.load(args.taskcluster_secret) init_logger( "bot", channel=secrets.get("APP_CHANNEL", "dev"), PAPERTRAIL_HOST=secrets.get("PAPERTRAIL_HOST"), PAPERTRAIL_PORT=secrets.get("PAPERTRAIL_PORT"), sentry_dsn=secrets.get("SENTRY_DSN"), ) return args
def create_app(): # Load secrets from Taskcluster local_secrets_path = os.environ.get("LOCAL_CONFIGURATION") if local_secrets_path is not None: assert os.path.exists( local_secrets_path ), f"Invalid local secrets path {local_secrets_path}" taskcluster.auth() taskcluster.load_secrets( os.environ.get("TASKCLUSTER_SECRET"), prefixes=["common", "backend", "code-coverage-backend"], required=["GOOGLE_CLOUD_STORAGE", "APP_CHANNEL"], existing={ "REDIS_URL": os.environ.get("REDIS_URL", "redis://localhost:6379") }, local_secrets=yaml.safe_load(open(local_secrets_path)) if local_secrets_path else None, ) # Configure logger init_logger( "backend", channel=taskcluster.secrets.get("APP_CHANNEL", "dev"), PAPERTRAIL_HOST=taskcluster.secrets.get("PAPERTRAIL_HOST"), PAPERTRAIL_PORT=taskcluster.secrets.get("PAPERTRAIL_PORT"), sentry_dsn=taskcluster.secrets.get("SENTRY_DSN"), ) logger = structlog.get_logger(__name__) app = build_flask_app( project_name=code_coverage_backend.config.PROJECT_NAME, app_name=code_coverage_backend.config.APP_NAME, openapi=os.path.join(os.path.dirname(__file__), "../api.yml"), ) # Setup datadog stats code_coverage_backend.datadog.get_stats() # Warm up GCP cache try: code_coverage_backend.gcp.load_cache() except Exception as e: logger.warn("GCP cache warmup failed: {}".format(e)) return app
def main(): args = parse_cli() # Auth on Taskcluster taskcluster_config.auth(args.taskcluster_client_id, args.taskcluster_access_token) # Then load secrets secrets.load(args.taskcluster_secret) init_logger( config.PROJECT_NAME, channel=secrets.get("APP_CHANNEL", "dev"), PAPERTRAIL_HOST=secrets.get("PAPERTRAIL_HOST"), PAPERTRAIL_PORT=secrets.get("PAPERTRAIL_PORT"), sentry_dsn=secrets.get("SENTRY_DSN"), ) c = CodeCov(args.repository, args.revision, args.task_name_filter, args.cache_root) c.go()
def main(): args = parse_cli() taskcluster_config.auth(args.taskcluster_client_id, args.taskcluster_access_token) taskcluster_config.load_secrets( args.taskcluster_secret, "events", required=("pulse_user", "pulse_password", "hook_id", "hook_group_id"), existing=dict( admins=["*****@*****.**", "*****@*****.**"]), ) init_logger( "events", channel=taskcluster_config.secrets.get("APP_CHANNEL", "dev"), PAPERTRAIL_HOST=taskcluster_config.secrets.get("PAPERTRAIL_HOST"), PAPERTRAIL_PORT=taskcluster_config.secrets.get("PAPERTRAIL_PORT"), sentry_dsn=taskcluster_config.secrets.get("SENTRY_DSN"), ) events = Events() events.run()
def create_app(): # Load secrets from Taskcluster taskcluster.auth() taskcluster.load_secrets( os.environ.get("TASKCLUSTER_SECRET"), code_coverage_backend.config.PROJECT_NAME, required=["GOOGLE_CLOUD_STORAGE", "APP_CHANNEL"], existing={ "REDIS_URL": os.environ.get("REDIS_URL", "redis://localhost:6379") }, ) # Configure logger init_logger( "backend", channel=taskcluster.secrets.get("APP_CHANNEL", "dev"), PAPERTRAIL_HOST=taskcluster.secrets.get("PAPERTRAIL_HOST"), PAPERTRAIL_PORT=taskcluster.secrets.get("PAPERTRAIL_PORT"), sentry_dsn=taskcluster.secrets.get("SENTRY_DSN"), ) logger = structlog.get_logger(__name__) app = build_flask_app( project_name=code_coverage_backend.config.PROJECT_NAME, app_name=code_coverage_backend.config.APP_NAME, openapi=os.path.join(os.path.dirname(__file__), "../api.yml"), ) # Setup datadog stats code_coverage_backend.datadog.get_stats() # Warm up GCP cache try: code_coverage_backend.gcp.load_cache() except Exception as e: logger.warn("GCP cache warmup failed: {}".format(e)) return app