Skip to content

armgit / peach

Public Imported from GitHub
0

Peach: Local-first video metadata scraper and media manager.

fix(packaging): Docker 构建阶段带上 amane 桥资源

longmeidaoa61bf7ef8bb6
diff --git a/.dockerignore b/.dockerignore
index 79dfe2726..44a8b2ea2 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -13,5 +13,8 @@
!web/**
!resources/
!resources/**
+!tools/amane-bridge/bridge.py
+!tools/amane-bridge/pyproject.toml
+!tools/amane-bridge/uv.lock
**/__pycache__/
**/*.pyc
diff --git a/Dockerfile b/Dockerfile
index 3a9322d85..21e3be127 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -11,6 +11,7 @@ COPY src ./src
COPY migrations ./migrations
COPY web ./web
COPY resources ./resources
+COPY tools/amane-bridge ./tools/amane-bridge
RUN uv sync --locked --no-dev --no-editable
FROM python:3.14.8-slim-trixie
diff --git a/tests/test_dependency_policy.py b/tests/test_dependency_policy.py
index a70fac40a..3c635b63b 100644
--- a/tests/test_dependency_policy.py
+++ b/tests/test_dependency_policy.py
@@ -53,6 +53,45 @@ class NpmInstallTests(unittest.TestCase):
sleep.assert_not_called()
+def _docker_context_includes(rules, relative):
+ """按 .dockerignore 末条命中者为准判定路径是否进入构建上下文,父目录命中也算。"""
+ parts = relative.split('/')
+ included = True
+ for negated, pattern in rules:
+ if any(pattern.fullmatch('/'.join(parts[:depth])) for depth in range(1, len(parts) + 1)):
+ included = negated
+ return included
+
+
+class DockerBuildContextTests(unittest.TestCase):
+ def test_build_stage_receives_every_bundled_runtime_resource(self):
+ from peach.bundle_resources import data_files
+ rules = []
+ for line in (ROOT / '.dockerignore').read_text(encoding='utf-8').splitlines():
+ if line.strip() and not line.startswith('#'):
+ negated, pattern = line.startswith('!'), line.lstrip('!').rstrip('/')
+ regex = re.escape(pattern).replace(r'\*\*', '.*').replace(r'\*', '[^/]*')
+ rules.append((negated, re.compile(regex)))
+ stage = (ROOT / 'Dockerfile').read_text(encoding='utf-8').split(' AS build\n', 1)[1].split('\nFROM ', 1)[0]
+ with tempfile.TemporaryDirectory() as folder:
+ app = Path(folder)
+ for line in stage.splitlines():
+ words = line.split()
+ if not words or words[0] != 'COPY' or words[1].startswith('--'):
+ continue
+ *sources, destination = words[1:]
+ for source in sources:
+ origin = ROOT / source
+ files = [origin] if origin.is_file() else [p for p in origin.rglob('*') if p.is_file()]
+ for path in files:
+ if not _docker_context_includes(rules, path.relative_to(ROOT).as_posix()):
+ continue
+ target = app / destination / (path.name if origin.is_file() else path.relative_to(origin))
+ target.parent.mkdir(parents=True, exist_ok=True)
+ target.write_bytes(b'')
+ data_files(app)
+
+
class NpmAuditTests(unittest.TestCase):
def test_docker_dependency_updates_have_a_takeover_recipe(self):
for manifest in ('Dockerfile', '.github/actions/actionlint/Dockerfile'):