mirror of
https://github.com/ArchiveBox/ArchiveBox
synced 2024-11-22 12:13:05 +00:00
autodetect when running inside docker and provide hints
This commit is contained in:
parent
f24cb3dcbe
commit
33ab7fd4ec
5 changed files with 33 additions and 15 deletions
|
@ -71,11 +71,12 @@ RUN python -m venv --clear --symlinks "$VENV_PATH" \
|
||||||
VOLUME "$DATA_PATH"
|
VOLUME "$DATA_PATH"
|
||||||
WORKDIR "$DATA_PATH"
|
WORKDIR "$DATA_PATH"
|
||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
ENV CHROME_BINARY=google-chrome \
|
ENV IN_DOCKER=True \
|
||||||
|
CHROME_BINARY=google-chrome \
|
||||||
CHROME_SANDBOX=False \
|
CHROME_SANDBOX=False \
|
||||||
SINGLEFILE_BINARY="$EXTRA_PATH/SingleFile-master/cli/single-file"
|
SINGLEFILE_BINARY="$EXTRA_PATH/SingleFile-master/cli/single-file"
|
||||||
|
|
||||||
RUN env ALLOW_ROOT=True archivebox version
|
RUN env ALLOW_ROOT=True archivebox version
|
||||||
|
|
||||||
ENTRYPOINT ["dumb-init", "--", "/app/bin/docker_entrypoint.sh", "archivebox"]
|
ENTRYPOINT ["dumb-init", "--", "/app/bin/docker_entrypoint.sh"]
|
||||||
CMD ["server", "0.0.0.0:8000"]
|
CMD ["archivebox", "server", "0.0.0.0:8000"]
|
||||||
|
|
|
@ -45,6 +45,7 @@ CONFIG_DEFAULTS: Dict[str, ConfigDefaultDict] = {
|
||||||
'IS_TTY': {'type': bool, 'default': lambda _: sys.stdout.isatty()},
|
'IS_TTY': {'type': bool, 'default': lambda _: sys.stdout.isatty()},
|
||||||
'USE_COLOR': {'type': bool, 'default': lambda c: c['IS_TTY']},
|
'USE_COLOR': {'type': bool, 'default': lambda c: c['IS_TTY']},
|
||||||
'SHOW_PROGRESS': {'type': bool, 'default': lambda c: c['IS_TTY']},
|
'SHOW_PROGRESS': {'type': bool, 'default': lambda c: c['IS_TTY']},
|
||||||
|
'IN_DOCKER': {'type': bool, 'default': False},
|
||||||
# TODO: 'SHOW_HINTS': {'type: bool, 'default': True},
|
# TODO: 'SHOW_HINTS': {'type: bool, 'default': True},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ class ConfigDict(BaseConfig, total=False):
|
||||||
IS_TTY: bool
|
IS_TTY: bool
|
||||||
USE_COLOR: bool
|
USE_COLOR: bool
|
||||||
SHOW_PROGRESS: bool
|
SHOW_PROGRESS: bool
|
||||||
|
IN_DOCKER: bool
|
||||||
|
|
||||||
OUTPUT_DIR: str
|
OUTPUT_DIR: str
|
||||||
CONFIG_FILE: str
|
CONFIG_FILE: str
|
||||||
|
|
|
@ -57,7 +57,8 @@ from .config import (
|
||||||
stderr,
|
stderr,
|
||||||
ConfigDict,
|
ConfigDict,
|
||||||
ANSI,
|
ANSI,
|
||||||
# IS_TTY,
|
IS_TTY,
|
||||||
|
IN_DOCKER,
|
||||||
USER,
|
USER,
|
||||||
ARCHIVEBOX_BINARY,
|
ARCHIVEBOX_BINARY,
|
||||||
ONLY_NEW,
|
ONLY_NEW,
|
||||||
|
@ -178,6 +179,10 @@ def help(out_dir: str=OUTPUT_DIR) -> None:
|
||||||
else:
|
else:
|
||||||
print('{green}Welcome to ArchiveBox v{}!{reset}'.format(VERSION, **ANSI))
|
print('{green}Welcome to ArchiveBox v{}!{reset}'.format(VERSION, **ANSI))
|
||||||
print()
|
print()
|
||||||
|
if IN_DOCKER:
|
||||||
|
print('When using Docker, you need to mount a volume to use as your data dir:')
|
||||||
|
print(' docker run -v /some/path:/data archivebox ...')
|
||||||
|
print()
|
||||||
print('To import an existing archive (from a previous version of ArchiveBox):')
|
print('To import an existing archive (from a previous version of ArchiveBox):')
|
||||||
print(' 1. cd into your data dir OUTPUT_DIR (usually ArchiveBox/output) and run:')
|
print(' 1. cd into your data dir OUTPUT_DIR (usually ArchiveBox/output) and run:')
|
||||||
print(' 2. archivebox init')
|
print(' 2. archivebox init')
|
||||||
|
@ -186,9 +191,6 @@ def help(out_dir: str=OUTPUT_DIR) -> None:
|
||||||
print(' 1. Create an empty directory, then cd into it and run:')
|
print(' 1. Create an empty directory, then cd into it and run:')
|
||||||
print(' 2. archivebox init')
|
print(' 2. archivebox init')
|
||||||
print()
|
print()
|
||||||
print('If using Docker, you need to mount a volume to use as your data dir:')
|
|
||||||
print(' docker run -v /some/path:/data archivebox ...')
|
|
||||||
print()
|
|
||||||
print('For more information, see the documentation here:')
|
print('For more information, see the documentation here:')
|
||||||
print(' https://github.com/pirate/ArchiveBox/wiki')
|
print(' https://github.com/pirate/ArchiveBox/wiki')
|
||||||
|
|
||||||
|
@ -1060,10 +1062,14 @@ def manage(args: Optional[List[str]]=None, out_dir: str=OUTPUT_DIR) -> None:
|
||||||
"""Run an ArchiveBox Django management command"""
|
"""Run an ArchiveBox Django management command"""
|
||||||
|
|
||||||
check_data_folder(out_dir=out_dir)
|
check_data_folder(out_dir=out_dir)
|
||||||
|
|
||||||
setup_django(out_dir)
|
setup_django(out_dir)
|
||||||
from django.core.management import execute_from_command_line
|
from django.core.management import execute_from_command_line
|
||||||
|
|
||||||
|
if (args and "createsuperuser" in args) and (IN_DOCKER and not IS_TTY):
|
||||||
|
stderr('[!] Warning: you need to pass -it to use interactive commands in docker', color='lightyellow')
|
||||||
|
stderr(' docker run -it archivebox manage {}'.format(' '.join(args or ['...'])), color='lightyellow')
|
||||||
|
stderr()
|
||||||
|
|
||||||
execute_from_command_line([f'{ARCHIVEBOX_BINARY} manage', *(args or ['help'])])
|
execute_from_command_line([f'{ARCHIVEBOX_BINARY} manage', *(args or ['help'])])
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
COMMAND="$*"
|
|
||||||
|
|
||||||
# Autodetect UID,GID of host user based on ownership of files in the data volume
|
# Autodetect UID,GID of host user based on ownership of files in the data volume
|
||||||
DATA_DIR="${DATA_DIR:-/data}"
|
DATA_DIR="${DATA_DIR:-/data}"
|
||||||
ARCHIVEBOX_USER="${ARCHIVEBOX_USER:-archivebox}"
|
ARCHIVEBOX_USER="${ARCHIVEBOX_USER:-archivebox}"
|
||||||
|
@ -18,8 +16,19 @@ if [[ "$USID" != 0 && "$GRID" != 0 ]]; then
|
||||||
chown "$USID":"$GRID" "$DATA_DIR/*" > /dev/null 2>&1 || true
|
chown "$USID":"$GRID" "$DATA_DIR/*" > /dev/null 2>&1 || true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# run django as the new archivebox user
|
# Run commands as the new archivebox user in Docker.
|
||||||
# any files touched will have the same uid,gid
|
# Any files touched will have the same uid & gid
|
||||||
# inside docker and outside docker on the host
|
# inside Docker and outside on the host machine.
|
||||||
gosu "$ARCHIVEBOX_USER" bash -c "$COMMAND"
|
if [[ "$1" == /* || "$1" == "echo" || "$1" == "archivebox" ]]; then
|
||||||
# e.g. "archivebox server"
|
# arg 1 is a binary, execute it verbatim
|
||||||
|
# e.g. "archivebox init"
|
||||||
|
# "/bin/bash"
|
||||||
|
# "echo"
|
||||||
|
gosu "$ARCHIVEBOX_USER" bash -c "$*"
|
||||||
|
else
|
||||||
|
# no command given, assume args were meant to be passed to archivebox cmd
|
||||||
|
# e.g. "add https://example.com"
|
||||||
|
# "manage createsupseruser"
|
||||||
|
# "server 0.0.0.0:8000"
|
||||||
|
gosu "$ARCHIVEBOX_USER" bash -c "archivebox $*"
|
||||||
|
fi
|
||||||
|
|
Loading…
Reference in a new issue