Dockerfile 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. # This is the Dockerfile for ArchiveBox, it bundles the following dependencies:
  2. # python3, ArchiveBox, curl, wget, git, chromium, youtube-dl, yt-dlp, single-file
  3. # Usage:
  4. # git submodule update --init --recursive
  5. # git pull --recurse-submodules
  6. # docker build . -t archivebox --no-cache
  7. # docker run -v "$PWD/data":/data archivebox init
  8. # docker run -v "$PWD/data":/data archivebox add 'https://example.com'
  9. # docker run -v "$PWD/data":/data -it archivebox manage createsuperuser
  10. # docker run -v "$PWD/data":/data -p 8000:8000 archivebox server
  11. # Multi-arch build:
  12. # docker buildx create --use
  13. # docker buildx build . --platform=linux/amd64,linux/arm64--push -t archivebox/archivebox:latest -t archivebox/archivebox:dev
  14. #
  15. # Read more about [developing Archivebox](https://github.com/ArchiveBox/ArchiveBox#archivebox-development).
  16. # Use Debian 12 w/ faster package updates: https://packages.debian.org/bookworm-backports/
  17. FROM python:3.11-slim-bookworm
  18. LABEL name="archivebox" \
  19. maintainer="Nick Sweeting <[email protected]>" \
  20. description="All-in-one self-hosted internet archiving solution" \
  21. homepage="https://github.com/ArchiveBox/ArchiveBox" \
  22. documentation="https://github.com/ArchiveBox/ArchiveBox/wiki/Docker" \
  23. org.opencontainers.image.title="ArchiveBox" \
  24. org.opencontainers.image.vendor="ArchiveBox" \
  25. org.opencontainers.image.description="All-in-one self-hosted internet archiving solution" \
  26. org.opencontainers.image.source="https://github.com/ArchiveBox/ArchiveBox" \
  27. com.docker.image.source.entrypoint="Dockerfile" \
  28. # TODO: release ArchiveBox as a Docker Desktop extension (requires these labels):
  29. # https://docs.docker.com/desktop/extensions-sdk/architecture/metadata/
  30. com.docker.desktop.extension.api.version=">= 1.4.7" \
  31. com.docker.desktop.extension.icon="https://archivebox.io/icon.png" \
  32. com.docker.extension.publisher-url="https://archivebox.io" \
  33. com.docker.extension.screenshots='[{"alt": "Screenshot of Admin UI", "url": "https://github.com/ArchiveBox/ArchiveBox/assets/511499/e8e0b6f8-8fdf-4b7f-8124-c10d8699bdb2"}]' \
  34. com.docker.extension.detailed-description='See here for detailed documentation: https://wiki.archivebox.io' \
  35. com.docker.extension.changelog='See here for release notes: https://github.com/ArchiveBox/ArchiveBox/releases' \
  36. com.docker.extension.categories='database,utility-tools'
  37. ARG TARGETPLATFORM
  38. ARG TARGETOS
  39. ARG TARGETARCH
  40. ARG TARGETVARIANT
  41. ######### Environment Variables #################################
  42. # Global system-level config
  43. ENV TZ=UTC \
  44. LANGUAGE=en_US:en \
  45. LC_ALL=C.UTF-8 \
  46. LANG=C.UTF-8 \
  47. DEBIAN_FRONTEND=noninteractive \
  48. APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=1 \
  49. PYTHONIOENCODING=UTF-8 \
  50. PYTHONUNBUFFERED=1 \
  51. PIP_DISABLE_PIP_VERSION_CHECK=1 \
  52. npm_config_loglevel=error
  53. # Version config
  54. ENV PYTHON_VERSION=3.11 \
  55. NODE_VERSION=20
  56. # User config
  57. ENV ARCHIVEBOX_USER="archivebox" \
  58. DEFAULT_PUID=911 \
  59. DEFAULT_PGID=911
  60. # Global paths
  61. ENV CODE_DIR=/app \
  62. DATA_DIR=/data \
  63. GLOBAL_VENV=/venv \
  64. PLAYWRIGHT_BROWSERS_PATH=/browsers
  65. # Application-level paths
  66. ENV APP_VENV=/app/.venv \
  67. NODE_MODULES=/app/node_modules
  68. # Build shell config
  69. ENV PATH="$PATH:$GLOBAL_VENV/bin:$APP_VENV/bin:$NODE_MODULES/.bin"
  70. SHELL ["/bin/bash", "-o", "pipefail", "-o", "errexit", "-o", "errtrace", "-o", "nounset", "-c"]
  71. ######### System Environment ####################################
  72. # Detect ArchiveBox version number by reading package.json
  73. COPY --chown=root:root --chmod=755 package.json "$CODE_DIR/"
  74. RUN grep '"version": ' "${CODE_DIR}/package.json" | awk -F'"' '{print $4}' > /VERSION.txt
  75. # Force apt to leave downloaded binaries in /var/cache/apt (massively speeds up Docker builds)
  76. RUN echo 'Binary::apt::APT::Keep-Downloaded-Packages "1";' > /etc/apt/apt.conf.d/99keep-cache \
  77. && echo 'APT::Install-Recommends "0";' > /etc/apt/apt.conf.d/99no-intall-recommends \
  78. && echo 'APT::Install-Suggests "0";' > /etc/apt/apt.conf.d/99no-intall-suggests \
  79. && rm -f /etc/apt/apt.conf.d/docker-clean
  80. # Print debug info about build and save it to disk, for human eyes only, not used by anything else
  81. RUN (echo "[i] Docker build for ArchiveBox $(cat /VERSION.txt) starting..." \
  82. && echo "PLATFORM=${TARGETPLATFORM} ARCH=$(uname -m) ($(uname -s) ${TARGETARCH} ${TARGETVARIANT})" \
  83. && echo "BUILD_START_TIME=$(date +"%Y-%m-%d %H:%M:%S %s") TZ=${TZ} LANG=${LANG}" \
  84. && echo \
  85. && echo "GLOBAL_VENV=${GLOBAL_VENV} APP_VENV=${APP_VENV} NODE_MODULES=${NODE_MODULES}" \
  86. && echo "PYTHON=${PYTHON_VERSION} NODE=${NODE_VERSION} PATH=${PATH}" \
  87. && echo "CODE_DIR=${CODE_DIR} DATA_DIR=${DATA_DIR}" \
  88. && echo \
  89. && uname -a \
  90. && cat /etc/os-release | head -n7 \
  91. && which bash && bash --version | head -n1 \
  92. && which dpkg && dpkg --version | head -n1 \
  93. && echo -e '\n\n' && env && echo -e '\n\n' \
  94. ) | tee -a /VERSION.txt
  95. # Create non-privileged user for archivebox and chrome
  96. RUN echo "[*] Setting up $ARCHIVEBOX_USER user uid=${DEFAULT_PUID}..." \
  97. && groupadd --system $ARCHIVEBOX_USER \
  98. && useradd --system --create-home --gid $ARCHIVEBOX_USER --groups audio,video $ARCHIVEBOX_USER \
  99. && usermod -u "$DEFAULT_PUID" "$ARCHIVEBOX_USER" \
  100. && groupmod -g "$DEFAULT_PGID" "$ARCHIVEBOX_USER" \
  101. && echo -e "\nARCHIVEBOX_USER=$ARCHIVEBOX_USER PUID=$(id -u $ARCHIVEBOX_USER) PGID=$(id -g $ARCHIVEBOX_USER)\n\n" \
  102. | tee -a /VERSION.txt
  103. # DEFAULT_PUID and DEFAULT_PID are overriden by PUID and PGID in /bin/docker_entrypoint.sh at runtime
  104. # https://docs.linuxserver.io/general/understanding-puid-and-pgid
  105. # Install system apt dependencies (adding backports to access more recent apt updates)
  106. RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=apt-$TARGETARCH$TARGETVARIANT \
  107. echo "[+] Installing APT base system dependencies for $TARGETPLATFORM..." \
  108. && echo 'deb https://deb.debian.org/debian bookworm-backports main contrib non-free' > /etc/apt/sources.list.d/backports.list \
  109. && mkdir -p /etc/apt/keyrings \
  110. && apt-get update -qq \
  111. && apt-get install -qq -y -t bookworm-backports \
  112. # 1. packaging dependencies
  113. apt-transport-https ca-certificates apt-utils gnupg2 curl wget \
  114. # 2. docker and init system dependencies
  115. zlib1g-dev dumb-init gosu cron unzip grep \
  116. # 3. frivolous CLI helpers to make debugging failed archiving easier
  117. # nano iputils-ping dnsutils htop procps jq yq
  118. && rm -rf /var/lib/apt/lists/*
  119. ######### Language Environments ####################################
  120. # Install Python environment
  121. RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=apt-$TARGETARCH$TARGETVARIANT --mount=type=cache,target=/root/.cache/pip,sharing=locked,id=pip-$TARGETARCH$TARGETVARIANT \
  122. echo "[+] Setting up Python $PYTHON_VERSION runtime..." \
  123. # && apt-get update -qq \
  124. # && apt-get install -qq -y -t bookworm-backports --no-upgrade \
  125. # python${PYTHON_VERSION} python${PYTHON_VERSION}-minimal python3-pip \
  126. # && rm -rf /var/lib/apt/lists/* \
  127. # tell PDM to allow using global system python site packages
  128. # && rm /usr/lib/python3*/EXTERNALLY-MANAGED \
  129. # create global virtual environment GLOBAL_VENV to use (better than using pip install --global)
  130. # && python3 -m venv --system-site-packages --symlinks $GLOBAL_VENV \
  131. # && python3 -m venv --system-site-packages $GLOBAL_VENV \
  132. # && python3 -m venv $GLOBAL_VENV \
  133. # install global dependencies / python build dependencies in GLOBAL_VENV
  134. # && pip install --upgrade pip setuptools wheel \
  135. # Save version info
  136. && ( \
  137. which python3 && python3 --version | grep " $PYTHON_VERSION" \
  138. && which pip && pip --version \
  139. # && which pdm && pdm --version \
  140. && echo -e '\n\n' \
  141. ) | tee -a /VERSION.txt
  142. # Install Node environment
  143. RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=apt-$TARGETARCH$TARGETVARIANT --mount=type=cache,target=/root/.npm,sharing=locked,id=npm-$TARGETARCH$TARGETVARIANT \
  144. echo "[+] Installing Node $NODE_VERSION environment in $NODE_MODULES..." \
  145. && echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODE_VERSION}.x nodistro main" >> /etc/apt/sources.list.d/nodejs.list \
  146. && curl -fsSL "https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key" | gpg --dearmor | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
  147. && apt-get update -qq \
  148. && apt-get install -qq -y -t bookworm-backports --no-upgrade libatomic1 \
  149. && apt-get install -y -t bookworm-backports --no-upgrade \
  150. nodejs \
  151. && rm -rf /var/lib/apt/lists/* \
  152. # Update NPM to latest version
  153. && npm i -g npm --cache /root/.npm \
  154. # Save version info
  155. && ( \
  156. which node && node --version \
  157. && which npm && npm --version \
  158. && echo -e '\n\n' \
  159. ) | tee -a /VERSION.txt
  160. ######### Extractor Dependencies ##################################
  161. # Install apt dependencies
  162. RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=apt-$TARGETARCH$TARGETVARIANT --mount=type=cache,target=/root/.cache/pip,sharing=locked,id=pip-$TARGETARCH$TARGETVARIANT \
  163. echo "[+] Installing APT extractor dependencies globally using apt..." \
  164. && apt-get update -qq \
  165. && apt-get install -qq -y -t bookworm-backports \
  166. curl wget git yt-dlp ffmpeg ripgrep \
  167. # Packages we have also needed in the past:
  168. # youtube-dl wget2 aria2 python3-pyxattr rtmpdump libfribidi-bin mpv \
  169. && rm -rf /var/lib/apt/lists/* \
  170. # Save version info
  171. && ( \
  172. which curl && curl --version | head -n1 \
  173. && which wget && wget --version 2>&1 | head -n1 \
  174. && which yt-dlp && yt-dlp --version 2>&1 | head -n1 \
  175. && which git && git --version 2>&1 | head -n1 \
  176. && which rg && rg --version 2>&1 | head -n1 \
  177. && echo -e '\n\n' \
  178. ) | tee -a /VERSION.txt
  179. # Install chromium browser using playwright
  180. RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=apt-$TARGETARCH$TARGETVARIANT --mount=type=cache,target=/root/.cache/pip,sharing=locked,id=pip-$TARGETARCH$TARGETVARIANT --mount=type=cache,target=/root/.cache/ms-playwright,sharing=locked,id=browsers-$TARGETARCH$TARGETVARIANT \
  181. echo "[+] Installing Browser binary dependencies to $PLAYWRIGHT_BROWSERS_PATH..." \
  182. && apt-get update -qq \
  183. && apt-get install -qq -y -t bookworm-backports \
  184. fontconfig fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-khmeros fonts-kacst fonts-symbola fonts-noto fonts-freefont-ttf \
  185. at-spi2-common fonts-liberation fonts-noto-color-emoji fonts-tlwg-loma-otf fonts-unifont libatk-bridge2.0-0 libatk1.0-0 libatspi2.0-0 libavahi-client3 \
  186. libavahi-common-data libavahi-common3 libcups2 libfontenc1 libice6 libnspr4 libnss3 libsm6 libunwind8 \
  187. libxaw7 libxcomposite1 libxdamage1 libxfont2 \
  188. libxkbfile1 libxmu6 libxpm4 libxt6 x11-xkb-utils xfonts-encodings \
  189. # xfonts-scalable xfonts-utils xserver-common xvfb \
  190. # chrome can run without dbus/upower technically, it complains about missing dbus but should run ok anyway
  191. # libxss1 dbus dbus-x11 upower \
  192. # && service dbus start \
  193. # install Chromium using playwright
  194. && pip install playwright \
  195. && cp -r /root/.cache/ms-playwright "$PLAYWRIGHT_BROWSERS_PATH" \
  196. && playwright install chromium \
  197. && export CHROME_BINARY="$(python -c 'from playwright.sync_api import sync_playwright; print(sync_playwright().start().chromium.executable_path)')" \
  198. && rm -rf /var/lib/apt/lists/* \
  199. && ln -s "$CHROME_BINARY" /usr/bin/chromium-browser \
  200. && mkdir -p "/home/${ARCHIVEBOX_USER}/.config/chromium/Crash Reports/pending/" \
  201. && chown -R $ARCHIVEBOX_USER "/home/${ARCHIVEBOX_USER}/.config" \
  202. && mkdir -p "$PLAYWRIGHT_BROWSERS_PATH" \
  203. && chown -R $ARCHIVEBOX_USER "$PLAYWRIGHT_BROWSERS_PATH" \
  204. # Save version info
  205. && ( \
  206. which chromium-browser && /usr/bin/chromium-browser --version || /usr/lib/chromium/chromium --version \
  207. && echo -e '\n\n' \
  208. ) | tee -a /VERSION.txt
  209. # Install Node dependencies
  210. WORKDIR "$CODE_DIR"
  211. COPY --chown=root:root --chmod=755 "package.json" "package-lock.json" "$CODE_DIR"/
  212. RUN --mount=type=cache,target=/root/.npm,sharing=locked,id=npm-$TARGETARCH$TARGETVARIANT \
  213. echo "[+] Installing NPM extractor dependencies from package.json into $NODE_MODULES..." \
  214. && npm ci --prefer-offline --no-audit --cache /root/.npm \
  215. && ( \
  216. which node && node --version \
  217. && which npm && npm version \
  218. && echo -e '\n\n' \
  219. ) | tee -a /VERSION.txt
  220. ######### Build Dependencies ####################################
  221. # Install ArchiveBox Python dependencies
  222. WORKDIR "$CODE_DIR"
  223. COPY --chown=root:root --chmod=755 "./pyproject.toml" "requirements.txt" "$CODE_DIR"/
  224. RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=apt-$TARGETARCH$TARGETVARIANT --mount=type=cache,target=/root/.cache/pip,sharing=locked,id=pip-$TARGETARCH$TARGETVARIANT \
  225. echo "[+] Installing PIP ArchiveBox dependencies from requirements.txt for ${TARGETPLATFORM}..." \
  226. && apt-get update -qq \
  227. && apt-get install -qq -y -t bookworm-backports \
  228. build-essential \
  229. libssl-dev libldap2-dev libsasl2-dev \
  230. python3-ldap python3-msgpack python3-mutagen python3-regex python3-pycryptodome procps \
  231. # && ln -s "$GLOBAL_VENV" "$APP_VENV" \
  232. # && pdm use --venv in-project \
  233. # && pdm run python -m ensurepip \
  234. # && pdm sync --fail-fast --no-editable --group :all --no-self \
  235. # && pdm export -o requirements.txt --without-hashes \
  236. # && source $GLOBAL_VENV/bin/activate \
  237. && pip install -r requirements.txt \
  238. && apt-get purge -y \
  239. build-essential \
  240. && apt-get autoremove -y \
  241. && rm -rf /var/lib/apt/lists/*
  242. # Install ArchiveBox Python package from source
  243. COPY --chown=root:root --chmod=755 "." "$CODE_DIR/"
  244. RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=apt-$TARGETARCH$TARGETVARIANT --mount=type=cache,target=/root/.cache/pip,sharing=locked,id=pip-$TARGETARCH$TARGETVARIANT \
  245. echo "[*] Installing PIP ArchiveBox package from $CODE_DIR..." \
  246. # && apt-get update -qq \
  247. # install C compiler to build deps on platforms that dont have 32-bit wheels available on pypi
  248. # && apt-get install -qq -y -t bookworm-backports \
  249. # build-essential \
  250. # INSTALL ARCHIVEBOX python package globally from CODE_DIR, with all optional dependencies
  251. && pip install -e "$CODE_DIR"[sonic,ldap] \
  252. # save docker image size and always remove compilers / build tools after building is complete
  253. # && apt-get purge -y build-essential \
  254. # && apt-get autoremove -y \
  255. && rm -rf /var/lib/apt/lists/*
  256. ####################################################
  257. # Setup ArchiveBox runtime config
  258. WORKDIR "$DATA_DIR"
  259. ENV IN_DOCKER=True \
  260. DISPLAY=novnc:0.0 \
  261. CUSTOM_TEMPLATES_DIR=/data/templates \
  262. GOOGLE_API_KEY=no \
  263. GOOGLE_DEFAULT_CLIENT_ID=no \
  264. GOOGLE_DEFAULT_CLIENT_SECRET=no \
  265. ALLOWED_HOSTS=*
  266. ## No need to set explicitly, these values will be autodetected by archivebox in docker:
  267. # WGET_BINARY="wget" \
  268. # YOUTUBEDL_BINARY="yt-dlp" \
  269. # CHROME_BINARY="/usr/bin/chromium-browser" \
  270. # USE_SINGLEFILE=True \
  271. # SINGLEFILE_BINARY="$NODE_MODULES/.bin/single-file" \
  272. # USE_READABILITY=True \
  273. # READABILITY_BINARY="$NODE_MODULES/.bin/readability-extractor" \
  274. # USE_MERCURY=True \
  275. # MERCURY_BINARY="$NODE_MODULES/.bin/postlight-parser"
  276. # Print version for nice docker finish summary
  277. RUN (echo -e "\n\n[√] Finished Docker build succesfully. Saving build summary in: /VERSION.txt" \
  278. && echo -e "PLATFORM=${TARGETPLATFORM} ARCH=$(uname -m) ($(uname -s) ${TARGETARCH} ${TARGETVARIANT})\n" \
  279. && echo -e "BUILD_END_TIME=$(date +"%Y-%m-%d %H:%M:%S %s")\n\n" \
  280. ) | tee -a /VERSION.txt
  281. RUN "$CODE_DIR"/bin/docker_entrypoint.sh version 2>&1 | tee -a /VERSION.txt
  282. ####################################################
  283. # Open up the interfaces to the outside world
  284. WORKDIR "$DATA_DIR"
  285. VOLUME "$DATA_DIR"
  286. EXPOSE 8000
  287. HEALTHCHECK --interval=30s --timeout=20s --retries=15 \
  288. CMD curl --silent 'http://localhost:8000/health/' | grep -q 'OK'
  289. ENTRYPOINT ["dumb-init", "--", "/app/bin/docker_entrypoint.sh"]
  290. CMD ["archivebox", "server", "--quick-init", "0.0.0.0:8000"]