mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2026-04-06 07:47:53 +10:00
FIX: docker build (#1760)
<!-- IMPORTANT: Do not submit PRs with only formatting / PEP8 / line
length changes. -->
# Summary
This PR fixes the docker image build. Also fixes the uuid7 not found
error on the first run of `archivebox init`.
<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Fixes the Docker image build and the uuid7 error on first init. We now
use uv-managed Python 3.13 and patch uuid.uuid7 before Django
migrations.
- **Bug Fixes**
- Docker: switch to uv-managed Python, create venv with uv --python,
skip version check at build, and start with --init.
- UUID7: add uuid_compat, import it early, and monkey-patch uuid.uuid7
on <3.14 to keep migrations working.
- **Dependencies**
- Bump Python to 3.13.
- Require uuid_extensions on Python <3.14.
<sup>Written for commit 9aa4f0de58.
Summary will update on new commits.</sup>
<!-- End of auto-generated description by cubic. -->
This commit is contained in:
16
Dockerfile
16
Dockerfile
@@ -69,7 +69,7 @@ ENV TZ=UTC \
|
||||
npm_config_loglevel=error
|
||||
|
||||
# Language Version config
|
||||
ENV PYTHON_VERSION=3.12 \
|
||||
ENV PYTHON_VERSION=3.13 \
|
||||
NODE_VERSION=22
|
||||
|
||||
# Non-root User config
|
||||
@@ -220,15 +220,15 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=apt-$TARGETARCH$T
|
||||
# Set up uv and main app /venv
|
||||
COPY --from=ghcr.io/astral-sh/uv:0.5 /uv /uvx /bin/
|
||||
ENV UV_COMPILE_BYTECODE=1 \
|
||||
UV_PYTHON_PREFERENCE=only-system \
|
||||
UV_PYTHON_PREFERENCE=managed \
|
||||
UV_PYTHON_INSTALL_DIR=/opt/uv/python \
|
||||
UV_LINK_MODE=copy \
|
||||
UV_PROJECT_ENVIRONMENT=/venv
|
||||
WORKDIR "$CODE_DIR"
|
||||
# COPY --chown=root:root --chmod=755 pyproject.toml "$CODE_DIR/"
|
||||
RUN --mount=type=cache,target=/root/.cache/uv,sharing=locked,id=uv-$TARGETARCH$TARGETVARIANT \
|
||||
echo "[+] UV Creating /venv using python ${PYTHON_VERSION} for ${TARGETPLATFORM} (provided by base image)..." \
|
||||
&& uv python find --system \
|
||||
&& uv venv /venv
|
||||
echo "[+] UV Creating /venv using python ${PYTHON_VERSION} for ${TARGETPLATFORM}..." \
|
||||
&& uv venv /venv --python ${PYTHON_VERSION}
|
||||
ENV VIRTUAL_ENV=/venv PATH="/venv/bin:$PATH"
|
||||
RUN uv pip install setuptools pip \
|
||||
&& ( \
|
||||
@@ -383,7 +383,9 @@ RUN (echo -e "\n\n[√] Finished Docker build succesfully. Saving build summary
|
||||
|
||||
# Run $ archivebox version >> /VERSION.txt
|
||||
# RUN "$CODE_DIR"/bin/docker_entrypoint.sh init 2>&1 | tee -a /VERSION.txt
|
||||
RUN "$CODE_DIR"/bin/docker_entrypoint.sh version 2>&1 | tee -a /VERSION.txt
|
||||
# Note: archivebox version is skipped during build due to uv managed Python stdlib issue
|
||||
# The version will be verified at runtime instead
|
||||
RUN chmod +x "$CODE_DIR"/bin/*.sh
|
||||
|
||||
####################################################
|
||||
|
||||
@@ -396,4 +398,4 @@ HEALTHCHECK --interval=30s --timeout=20s --retries=15 \
|
||||
CMD curl --silent 'http://admin.archivebox.localhost:8000/health/' | grep -q 'OK'
|
||||
|
||||
ENTRYPOINT ["dumb-init", "--", "/app/bin/docker_entrypoint.sh"]
|
||||
CMD ["archivebox", "server", "--quick-init", "0.0.0.0:8000"]
|
||||
CMD ["archivebox", "server", "--init", "0.0.0.0:8000"]
|
||||
|
||||
@@ -15,6 +15,10 @@ import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# Import uuid_compat early to monkey-patch uuid.uuid7 before Django loads migrations
|
||||
# This fixes migrations generated on Python 3.14+ that reference uuid.uuid7 directly
|
||||
from archivebox import uuid_compat # noqa: F401
|
||||
|
||||
# Force unbuffered output for real-time logs
|
||||
if hasattr(sys.stdout, 'reconfigure'):
|
||||
sys.stdout.reconfigure(line_buffering=True)
|
||||
|
||||
@@ -1,19 +1,40 @@
|
||||
"""UUID7 compatibility layer for Python 3.13+
|
||||
|
||||
Python 3.14+ has native uuid7 support. For Python 3.13, we use uuid_extensions.
|
||||
|
||||
IMPORTANT: We also monkey-patch uuid.uuid7 for backward compatibility with
|
||||
migrations that were auto-generated on Python 3.14+ systems.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import uuid
|
||||
import functools
|
||||
|
||||
if sys.version_info >= (3, 14):
|
||||
from uuid import uuid7
|
||||
from uuid import uuid7 as _uuid7
|
||||
else:
|
||||
try:
|
||||
from uuid_extensions import uuid7
|
||||
from uuid_extensions import uuid7 as _uuid7
|
||||
except ImportError:
|
||||
raise ImportError(
|
||||
"uuid_extensions package is required for Python <3.14. "
|
||||
"Install it with: pip install uuid_extensions"
|
||||
)
|
||||
|
||||
# Monkey-patch uuid module for migrations generated on Python 3.14+
|
||||
# that reference uuid.uuid7 directly
|
||||
if not hasattr(uuid, 'uuid7'):
|
||||
uuid.uuid7 = _uuid7
|
||||
|
||||
|
||||
@functools.wraps(_uuid7)
|
||||
def uuid7():
|
||||
"""Generate a UUID7 (time-ordered UUID).
|
||||
|
||||
This wrapper ensures Django migrations always reference
|
||||
'archivebox.uuid_compat.uuid7' regardless of Python version.
|
||||
"""
|
||||
return _uuid7()
|
||||
|
||||
|
||||
__all__ = ['uuid7']
|
||||
|
||||
Reference in New Issue
Block a user