Fixes #1385 ## Changes Supports multiple crawler 'channels' which can be configured to different browsertrix-crawler versions - Replaces `crawler_image` in helm chart with `crawler_channels` array similar to how storages are handled - The `default` crawler channel must always be provided and specifies the default crawler image - Adds backend `/orgs/{oid}/crawlconfigs/crawler-channels` API endpoint to fetch information about available crawler versions (name, image, and label) and test - Adds crawler channel select to workflow creation/edit screens and profile creation dialog, and updates related API endpoints and configmaps accordingly. The select dropdown is shown only if more than one channel is configured. - Adds `crawlerChannel` to workflow and crawl details. - Add `image` to crawler image, used to display actual image used as part of the crawl. - Modifies `crawler_crawl_id` backend test fixture to use `test` crawler version to ensure crawler versions other than latest work - Adds migration to add `crawlerChannel` set to `default` to existing workflow and profile objects and workflow configmaps --------- Co-authored-by: Ilya Kreymer <ikreymer@gmail.com> Co-authored-by: Henry Wilkinson <henry@wilkinson.graphics>
72 lines
2.5 KiB
Python
72 lines
2.5 KiB
Python
"""
|
|
Migration 0024 -- crawlerChannel
|
|
"""
|
|
from btrixcloud.crawlmanager import CrawlManager
|
|
from btrixcloud.migrations import BaseMigration
|
|
from btrixcloud.models import CrawlConfig, UpdateCrawlConfig
|
|
|
|
|
|
MIGRATION_VERSION = "0024"
|
|
|
|
|
|
class Migration(BaseMigration):
|
|
"""Migration class."""
|
|
|
|
def __init__(self, mdb, migration_version=MIGRATION_VERSION):
|
|
super().__init__(mdb, migration_version)
|
|
|
|
async def migrate_up(self):
|
|
"""Perform migration up.
|
|
|
|
Add crawlerChannel to existing workflows and profiles, and update configmaps
|
|
"""
|
|
# pylint: disable=duplicate-code
|
|
mdb_crawl_configs = self.mdb["crawl_configs"]
|
|
mdb_profiles = self.mdb["profiles"]
|
|
|
|
async for config in mdb_crawl_configs.find(
|
|
{"crawlerChannel": {"$in": ["", None]}}
|
|
):
|
|
config_id = config["_id"]
|
|
try:
|
|
await mdb_crawl_configs.find_one_and_update(
|
|
{"_id": config_id},
|
|
{"$set": {"crawlerChannel": "default"}},
|
|
)
|
|
# pylint: disable=broad-except
|
|
except Exception as err:
|
|
print(
|
|
f"Error adding crawlerChannel 'default' to workflow {config_id}: {err}",
|
|
flush=True,
|
|
)
|
|
|
|
async for profile in mdb_profiles.find({"crawlerChannel": {"$in": ["", None]}}):
|
|
profile_id = profile["_id"]
|
|
try:
|
|
await mdb_profiles.find_one_and_update(
|
|
{"_id": profile_id},
|
|
{"$set": {"crawlerChannel": "default"}},
|
|
)
|
|
# pylint: disable=broad-except
|
|
except Exception as err:
|
|
print(
|
|
f"Error adding crawlerChannel 'default' to profile {profile_id}: {err}",
|
|
flush=True,
|
|
)
|
|
|
|
# Update configmaps
|
|
crawl_manager = CrawlManager()
|
|
match_query = {"crawlerChannel": {"$in": ["", None]}}
|
|
async for config_dict in mdb_crawl_configs.find(match_query):
|
|
config = CrawlConfig.from_dict(config_dict)
|
|
try:
|
|
await crawl_manager.update_crawl_config(
|
|
config, UpdateCrawlConfig(crawlerChannel="default")
|
|
)
|
|
# pylint: disable=broad-except
|
|
except Exception as exc:
|
|
print(
|
|
"Skip configmap migration due to error, likely missing config",
|
|
exc,
|
|
)
|