From 166573d4172798eaf154f276db74b01594dd1681 Mon Sep 17 00:00:00 2001 From: Nick Sweeting Date: Tue, 31 Oct 2023 00:23:19 -0700 Subject: [PATCH] autodetect qemu and warn about broken chrome in emulated containers --- archivebox/config.py | 1 + archivebox/main.py | 4 +++- bin/docker_entrypoint.sh | 8 ++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/archivebox/config.py b/archivebox/config.py index e07af3d7..67d84d93 100644 --- a/archivebox/config.py +++ b/archivebox/config.py @@ -77,6 +77,7 @@ CONFIG_SCHEMA: Dict[str, ConfigDefaultDict] = { 'USE_COLOR': {'type': bool, 'default': lambda c: c['IS_TTY']}, 'SHOW_PROGRESS': {'type': bool, 'default': lambda c: (c['IS_TTY'] and platform.system() != 'Darwin')}, # progress bars are buggy on mac, disable for now 'IN_DOCKER': {'type': bool, 'default': False}, + 'IN_QEMU': {'type': bool, 'default': False}, 'PUID': {'type': int, 'default': os.getuid()}, 'PGID': {'type': int, 'default': os.getgid()}, # TODO: 'SHOW_HINTS': {'type: bool, 'default': True}, diff --git a/archivebox/main.py b/archivebox/main.py index 83adaba8..5ce1e288 100755 --- a/archivebox/main.py +++ b/archivebox/main.py @@ -71,6 +71,7 @@ from .config import ( IS_TTY, DEBUG, IN_DOCKER, + IN_QEMU, PUID, PGID, USER, @@ -218,7 +219,7 @@ def version(quiet: bool=False, if not quiet: # 0.6.3 # ArchiveBox v0.6.3 Cpython Linux Linux-4.19.121-linuxkit-x86_64-with-glibc2.28 x86_64 (in Docker) (in TTY) - # DEBUG=False IN_DOCKER=True IS_TTY=True TZ=UTC FS_ATOMIC=True FS_REMOTE=False FS_PERMS=644 FS_USER=501:20 SEARCH_BACKEND=ripgrep + # DEBUG=False IN_DOCKER=True IN_QEMU=False IS_TTY=True TZ=UTC FS_ATOMIC=True FS_REMOTE=False FS_PERMS=644 FS_USER=501:20 SEARCH_BACKEND=ripgrep p = platform.uname() print( @@ -233,6 +234,7 @@ def version(quiet: bool=False, print( f'DEBUG={DEBUG}', f'IN_DOCKER={IN_DOCKER}', + f'IN_QEMU={IN_QEMU}', f'IS_TTY={IS_TTY}', f'TZ={TIMEZONE}', #f'DB=django.db.backends.sqlite3 (({CONFIG["SQLITE_JOURNAL_MODE"]})', # add this if we have more useful info to show eventually diff --git a/bin/docker_entrypoint.sh b/bin/docker_entrypoint.sh index 92fb46a6..35e3c365 100755 --- a/bin/docker_entrypoint.sh +++ b/bin/docker_entrypoint.sh @@ -41,6 +41,14 @@ fi chown $PUID:$PGID "$DATA_DIR" chown $PUID:$PGID "$DATA_DIR"/* + +export IN_QEMU="$(pmap 1 | grep qemu | wc -l | grep -E '^0$' >/dev/null && echo 'False' || echo 'True')" +if [[ "$IN_QEMU" == 'True' ]]; then + echo -e "\n[!] Warning: Running $(uname -m) emulated container in QEMU, some things will break!" >&2 + echo -e " chromium (screenshot, pdf, dom), singlefile, and any dependencies that rely on inotify will not run in QEMU." >&2 + echo -e " See here for more info: https://github.com/microsoft/playwright/issues/17395#issuecomment-1250830493\n" >&2 +fi + # Drop permissions to run commands as the archivebox user if [[ "$1" == /* || "$1" == "bash" || "$1" == "sh" || "$1" == "echo" || "$1" == "cat" || "$1" == "archivebox" ]]; then # handle "docker run archivebox /some/non-archivebox/command" by executing args as direct bash command