diff --git a/.dockerignore b/.dockerignore index 6d1eb8df85..7dee04e263 100644 --- a/.dockerignore +++ b/.dockerignore @@ -10,6 +10,8 @@ dev-docs/ !docs/** !SECURITY.md !TERMS.md +!ARCHITECTURE.md +!CONTRIBUTING.md # Binaries and build artifacts pulse diff --git a/Dockerfile b/Dockerfile index 75b7bbb698..6732aa67a1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,6 +18,7 @@ COPY frontend-modern/ ./ COPY scripts/exclusive-lock.mjs /app/scripts/exclusive-lock.mjs COPY docs/ /app/docs/ COPY SECURITY.md TERMS.md /app/ +COPY ARCHITECTURE.md CONTRIBUTING.md /app/ # Build frontend RUN --mount=type=cache,id=pulse-npm-cache,target=/root/.npm \ diff --git a/deploy/provider-msp/Dockerfile.control-plane b/deploy/provider-msp/Dockerfile.control-plane index f9e32a9318..b80700b97e 100644 --- a/deploy/provider-msp/Dockerfile.control-plane +++ b/deploy/provider-msp/Dockerfile.control-plane @@ -9,6 +9,7 @@ COPY frontend-modern/ ./ COPY scripts/exclusive-lock.mjs /app/scripts/exclusive-lock.mjs COPY docs/ /app/docs/ COPY SECURITY.md TERMS.md /app/ +COPY ARCHITECTURE.md CONTRIBUTING.md /app/ RUN --mount=type=cache,id=pulse-control-plane-npm-cache,target=/root/.npm \ npm run build diff --git a/scripts/tests/test_container_packaging.py b/scripts/tests/test_container_packaging.py index fc3da43ccb..3795035dd0 100644 --- a/scripts/tests/test_container_packaging.py +++ b/scripts/tests/test_container_packaging.py @@ -8,6 +8,7 @@ import importlib.util import io import json import os +import shutil import subprocess import tarfile import tempfile @@ -302,6 +303,110 @@ class DockerfileTests(unittest.TestCase): self.assertEqual(path.read_bytes(), before[path]) self.assertEqual(path.stat().st_mode & 0o777, 0o755 if executable else 0o644) + def test_frontend_builder_stages_every_mirrored_doc_source(self): + # Verify .dockerignore and every frontend-building Dockerfile stage all + # mirrored doc sources that sync-public-docs.mjs reads during npm run build. + mirror_spec = importlib.util.spec_from_file_location( + 'check_docs_mirror', ROOT/'scripts/check_docs_mirror.py' + ) + check_docs_mirror = importlib.util.module_from_spec(mirror_spec) + mirror_spec.loader.exec_module(check_docs_mirror) + expected_root_docs = set(check_docs_mirror.ROOT_SOURCED_DOCS) + self.assertTrue(expected_root_docs) + + ignore_lines = [ + line.strip() + for line in (ROOT/'.dockerignore').read_text().splitlines() + if line.strip() and not line.strip().startswith('#') + ] + self.assertIn('*.md', ignore_lines) + md_idx = ignore_lines.index('*.md') + allowed_root_md = { + line[1:] + for line in ignore_lines[md_idx + 1:] + if line.startswith('!') and '/' not in line[1:] and line.endswith('.md') + } + self.assertTrue( + expected_root_docs.issubset(allowed_root_md), + f'.dockerignore missing root-sourced doc allowlist entries: ' + f'{sorted(expected_root_docs - allowed_root_md)}', + ) + self.assertIn('!docs/', ignore_lines) + self.assertIn('!docs/**', ignore_lines) + + for df_path in (ROOT/'Dockerfile', ROOT/'deploy/provider-msp/Dockerfile.control-plane'): + with self.subTest(dockerfile=df_path.relative_to(ROOT).as_posix()): + text = df_path.read_text().replace('\\\n', '') + stage_lines = [] + in_frontend = False + for raw in text.splitlines(): + line = raw.strip() + if line.startswith('FROM '): + in_frontend = line.endswith(' AS frontend-builder') + continue + if not in_frontend or not line or line.startswith('#'): + continue + if line.startswith('RUN ') and 'npm run build' in line: + break + stage_lines.append(line) + + copied_docs_dir = False + copied_root_md = set() + for line in stage_lines: + if not line.startswith('COPY '): + continue + args = [p for p in line.split()[1:] if not p.startswith('--')] + if len(args) < 2: + continue + srcs, dst = args[:-1], args[-1] + if dst == '/app/docs/' and 'docs/' in srcs: + copied_docs_dir = True + if dst == '/app/': + for src in srcs: + if src.endswith('.md') and '/' not in src: + copied_root_md.add(src) + + self.assertTrue(copied_docs_dir, f'{df_path.name} frontend-builder must COPY docs/ /app/docs/') + self.assertTrue( + expected_root_docs.issubset(copied_root_md), + f'{df_path.name} frontend-builder missing COPY to /app/ for: ' + f'{sorted(expected_root_docs - copied_root_md)}', + ) + + with tempfile.TemporaryDirectory() as tmp: + app = Path(tmp)/'app' + fm = app/'frontend-modern' + (fm/'scripts').mkdir(parents=True) + shutil.copy2( + ROOT/'frontend-modern/scripts/sync-public-docs.mjs', + fm/'scripts/sync-public-docs.mjs', + ) + shutil.copytree(ROOT/'frontend-modern/public/docs', fm/'public/docs') + shutil.copytree(ROOT/'docs', app/'docs') + for doc in sorted(copied_root_md & allowed_root_md): + shutil.copy2(ROOT/doc, app/doc) + + ok = subprocess.run( + ['node', str(fm/'scripts/sync-public-docs.mjs')], + cwd=fm, + text=True, + capture_output=True, + check=False, + ) + self.assertEqual(ok.returncode, 0, ok.stderr or ok.stdout) + self.assertIn('(0 updated,', ok.stdout) + + (app/'ARCHITECTURE.md').unlink() + missing = subprocess.run( + ['node', str(fm/'scripts/sync-public-docs.mjs')], + cwd=fm, + text=True, + capture_output=True, + check=False, + ) + self.assertNotEqual(missing.returncode, 0) + self.assertIn('ARCHITECTURE.md', missing.stderr + missing.stdout) + if __name__ == '__main__': unittest.main()