diff --git a/Dockerfile b/Dockerfile index 821125ba..197844ae 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,9 @@ # This is the Dockerfile for ArchiveBox, it includes the following major pieces: # git, curl, wget, python3, youtube-dl, google-chrome-stable, ArchiveBox # Usage: -# docker build . -t archivebox:latest -# docker run -v=$PWD/data:/data archivebox:latest archivebox init -# echo 'https://example.com' | docker run -v=$PWD/data:/data -i archivebox:latest archivebox add +# docker build . -t archivebox +# docker run -v "$PWD/data":/data archivebox init +# docker run -v "$PWD/data":/data archivebox add 'https://example.com' # Documentation: # https://github.com/pirate/ArchiveBox/wiki/Docker#docker @@ -43,8 +43,7 @@ RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selectio fonts-symbola \ fonts-noto \ fonts-freefont-ttf \ - && rm -rf /var/lib/apt/lists/* \ - && pip install --upgrade --no-cache-dir pip setuptools + && rm -rf /var/lib/apt/lists/* # Run everything from here on out as non-privileged user RUN groupadd --system archivebox \ @@ -54,6 +53,7 @@ ADD . "$CODE_PATH" WORKDIR "$CODE_PATH" ENV PATH="$VENV_PATH/bin:${PATH}" RUN python -m venv --clear --symlinks "$VENV_PATH" \ + && pip install --upgrade pip setuptools \ && pip install -e . VOLUME "$DATA_PATH" @@ -62,5 +62,7 @@ EXPOSE 8000 ENV CHROME_BINARY=google-chrome \ CHROME_SANDBOX=False -ENTRYPOINT ["dumb-init", "--", "/app/bin/entrypoint.sh", "archivebox"] +RUN env ALLOW_ROOT=True archivebox version + +ENTRYPOINT ["dumb-init", "--", "/app/bin/docker_entrypoint.sh", "archivebox"] CMD ["server", "0.0.0.0:8000"] diff --git a/bin/entrypoint.sh b/bin/docker_entrypoint.sh similarity index 54% rename from bin/entrypoint.sh rename to bin/docker_entrypoint.sh index a970bfa0..e9b399ec 100755 --- a/bin/entrypoint.sh +++ b/bin/docker_entrypoint.sh @@ -1,22 +1,24 @@ #!/usr/bin/env bash -# detect userid:groupid of contents of data folder +COMMAND="$*" + +# Autodetect UID,GID of host user based on ownership of files in the data volume DATA_DIR="${DATA_DIR:-/data}" ARCHIVEBOX_USER="${ARCHIVEBOX_USER:-archivebox}" -# Autodetect UID and GID of host user based on ownership of files in the volume USID=$(stat --format="%u" "$DATA_DIR") GRID=$(stat --format="%g" "$DATA_DIR") -COMMAND="$*" - -# run django as the host user's uid:gid so that any files touched have the same permissions as outside the container -# e.g. ./manage.py runserver - -chown "$USID":"$GRID" "$DATA_DIR" +# If user is not root, modify the archivebox user+files to have the same uid,gid if [[ "$USID" != 0 && "$GRID" != 0 ]]; then + chown "$USID":"$GRID" "$DATA_DIR" usermod -u "$USID" "$ARCHIVEBOX_USER" groupmod -g "$GRID" "$ARCHIVEBOX_USER" chown -R "$USID":"$GRID" "/home/$ARCHIVEBOX_USER" fi + +# run django as the new archivebox user +# any files touched will have the same uid,gid +# inside docker and outside docker on the host gosu "$ARCHIVEBOX_USER" bash -c "$COMMAND" +# e.g. "archivebox server" diff --git a/bin/archivebox-export-browser-history b/bin/export_browser_history.sh similarity index 100% rename from bin/archivebox-export-browser-history rename to bin/export_browser_history.sh diff --git a/bin/lint.sh b/bin/lint.sh new file mode 100755 index 00000000..fad7fda9 --- /dev/null +++ b/bin/lint.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +### Bash Environment Setup +# http://redsymbol.net/articles/unofficial-bash-strict-mode/ +# https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html +# set -o xtrace +set -o errexit +set -o errtrace +set -o nounset +set -o pipefail +IFS=$'\n' + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && cd .. && pwd )" + +source "$DIR/.venv/bin/activate" + +flake8 archivebox +mypy archivebox diff --git a/bin/archivebox-setup b/bin/setup.sh similarity index 100% rename from bin/archivebox-setup rename to bin/setup.sh diff --git a/bin/test.sh b/bin/test.sh new file mode 100755 index 00000000..f19ca14a --- /dev/null +++ b/bin/test.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +### Bash Environment Setup +# http://redsymbol.net/articles/unofficial-bash-strict-mode/ +# https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html +# set -o xtrace +set -o errexit +set -o errtrace +set -o nounset +set -o pipefail +IFS=$'\n' + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && cd .. && pwd )" + +source "$DIR/.venv/bin/activate" + +pytest