mirror of
https://github.com/bellingcat/auto-archiver.git
synced 2026-06-12 21:28:29 +03:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ef5b39c4f1 | ||
|
|
24ceafcb64 | ||
|
|
9fd4bb56a8 | ||
|
|
5324d562ba |
@@ -90,7 +90,9 @@ class ArchivingOrchestrator:
|
|||||||
if cached_result:
|
if cached_result:
|
||||||
logger.debug("Found previously archived entry")
|
logger.debug("Found previously archived entry")
|
||||||
for d in self.databases:
|
for d in self.databases:
|
||||||
d.done(cached_result, cached=True)
|
try: d.done(cached_result, cached=True)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"ERROR database {d.name}: {e}: {traceback.format_exc()}")
|
||||||
return cached_result
|
return cached_result
|
||||||
|
|
||||||
# 3 - call archivers until one succeeds
|
# 3 - call archivers until one succeeds
|
||||||
@@ -120,6 +122,9 @@ class ArchivingOrchestrator:
|
|||||||
result.status = "nothing archived"
|
result.status = "nothing archived"
|
||||||
|
|
||||||
# signal completion to databases and archivers
|
# signal completion to databases and archivers
|
||||||
for d in self.databases: d.done(result)
|
for d in self.databases:
|
||||||
|
try: d.done(result)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"ERROR database {d.name}: {e}: {traceback.format_exc()}")
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|||||||
@@ -38,15 +38,19 @@ class WaczArchiverEnricher(Enricher, Archiver):
|
|||||||
|
|
||||||
def setup(self) -> None:
|
def setup(self) -> None:
|
||||||
self.use_docker = os.environ.get('WACZ_ENABLE_DOCKER') or not os.environ.get('RUNNING_IN_DOCKER')
|
self.use_docker = os.environ.get('WACZ_ENABLE_DOCKER') or not os.environ.get('RUNNING_IN_DOCKER')
|
||||||
|
self.docker_in_docker = os.environ.get('WACZ_ENABLE_DOCKER') and os.environ.get('RUNNING_IN_DOCKER')
|
||||||
|
|
||||||
|
self.cwd_dind = f"/crawls/crawls{random_str(8)}"
|
||||||
self.browsertrix_home_host = os.environ.get('BROWSERTRIX_HOME_HOST')
|
self.browsertrix_home_host = os.environ.get('BROWSERTRIX_HOME_HOST')
|
||||||
|
self.browsertrix_home_container = os.environ.get('BROWSERTRIX_HOME_CONTAINER') or self.browsertrix_home_host
|
||||||
# create crawls folder if not exists, so it can be safely removed in cleanup
|
# create crawls folder if not exists, so it can be safely removed in cleanup
|
||||||
if self.use_docker and self.browsertrix_home_host:
|
if self.docker_in_docker:
|
||||||
os.makedirs(self.browsertrix_home_host, exist_ok=True)
|
os.makedirs(self.cwd_dind, exist_ok=True)
|
||||||
|
|
||||||
def cleanup(self) -> None:
|
def cleanup(self) -> None:
|
||||||
if self.use_docker and self.browsertrix_home_host:
|
if self.docker_in_docker:
|
||||||
logger.debug(f"Removing {self.browsertrix_home_host=}")
|
logger.debug(f"Removing {self.cwd_dind=}")
|
||||||
shutil.rmtree(self.browsertrix_home_host, ignore_errors=True)
|
shutil.rmtree(self.cwd_dind, ignore_errors=True)
|
||||||
|
|
||||||
def download(self, item: Metadata) -> Metadata:
|
def download(self, item: Metadata) -> Metadata:
|
||||||
# this new Metadata object is required to avoid duplication
|
# this new Metadata object is required to avoid duplication
|
||||||
@@ -64,7 +68,7 @@ class WaczArchiverEnricher(Enricher, Archiver):
|
|||||||
|
|
||||||
collection = random_str(8)
|
collection = random_str(8)
|
||||||
browsertrix_home_host = self.browsertrix_home_host or os.path.abspath(ArchivingContext.get_tmp_dir())
|
browsertrix_home_host = self.browsertrix_home_host or os.path.abspath(ArchivingContext.get_tmp_dir())
|
||||||
browsertrix_home_container = os.environ.get('BROWSERTRIX_HOME_CONTAINER') or browsertrix_home_host
|
browsertrix_home_container = self.browsertrix_home_container or browsertrix_home_host
|
||||||
|
|
||||||
cmd = [
|
cmd = [
|
||||||
"crawl",
|
"crawl",
|
||||||
@@ -79,6 +83,9 @@ class WaczArchiverEnricher(Enricher, Archiver):
|
|||||||
"--behaviors", "autoscroll,autoplay,autofetch,siteSpecific",
|
"--behaviors", "autoscroll,autoplay,autofetch,siteSpecific",
|
||||||
"--behaviorTimeout", str(self.timeout),
|
"--behaviorTimeout", str(self.timeout),
|
||||||
"--timeout", str(self.timeout)]
|
"--timeout", str(self.timeout)]
|
||||||
|
|
||||||
|
if self.docker_in_docker:
|
||||||
|
cmd.extend(["--cwd", self.cwd_dind])
|
||||||
|
|
||||||
# call docker if explicitly enabled or we are running on the host (not in docker)
|
# call docker if explicitly enabled or we are running on the host (not in docker)
|
||||||
if self.use_docker:
|
if self.use_docker:
|
||||||
@@ -113,7 +120,10 @@ class WaczArchiverEnricher(Enricher, Archiver):
|
|||||||
logger.error(f"WACZ generation failed: {e}")
|
logger.error(f"WACZ generation failed: {e}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if self.use_docker:
|
|
||||||
|
if self.docker_in_docker:
|
||||||
|
wacz_fn = os.path.join(self.cwd_dind, "collections", collection, f"{collection}.wacz")
|
||||||
|
elif self.use_docker:
|
||||||
wacz_fn = os.path.join(browsertrix_home_container, "collections", collection, f"{collection}.wacz")
|
wacz_fn = os.path.join(browsertrix_home_container, "collections", collection, f"{collection}.wacz")
|
||||||
else:
|
else:
|
||||||
wacz_fn = os.path.join("collections", collection, f"{collection}.wacz")
|
wacz_fn = os.path.join("collections", collection, f"{collection}.wacz")
|
||||||
@@ -126,7 +136,9 @@ class WaczArchiverEnricher(Enricher, Archiver):
|
|||||||
if self.extract_media or self.extract_screenshot:
|
if self.extract_media or self.extract_screenshot:
|
||||||
self.extract_media_from_wacz(to_enrich, wacz_fn)
|
self.extract_media_from_wacz(to_enrich, wacz_fn)
|
||||||
|
|
||||||
if self.use_docker:
|
if self.docker_in_docker:
|
||||||
|
jsonl_fn = os.path.join(self.cwd_dind, "collections", collection, "pages", "pages.jsonl")
|
||||||
|
elif self.use_docker:
|
||||||
jsonl_fn = os.path.join(browsertrix_home_container, "collections", collection, "pages", "pages.jsonl")
|
jsonl_fn = os.path.join(browsertrix_home_container, "collections", collection, "pages", "pages.jsonl")
|
||||||
else:
|
else:
|
||||||
jsonl_fn = os.path.join("collections", collection, "pages", "pages.jsonl")
|
jsonl_fn = os.path.join("collections", collection, "pages", "pages.jsonl")
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ _MAJOR = "0"
|
|||||||
_MINOR = "9"
|
_MINOR = "9"
|
||||||
# On main and in a nightly release the patch should be one ahead of the last
|
# On main and in a nightly release the patch should be one ahead of the last
|
||||||
# released build.
|
# released build.
|
||||||
_PATCH = "3"
|
_PATCH = "7"
|
||||||
# This is mainly for nightly builds which have the suffix ".dev$DATE". See
|
# This is mainly for nightly builds which have the suffix ".dev$DATE". See
|
||||||
# https://semver.org/#is-v123-a-semantic-version for the semantics.
|
# https://semver.org/#is-v123-a-semantic-version for the semantics.
|
||||||
_SUFFIX = ""
|
_SUFFIX = ""
|
||||||
|
|||||||
Reference in New Issue
Block a user