Просмотр исходного кода

build(env): add pinned Debian verification container

root 3 месяцев назад
Родитель
Сommit
baf13a637f
7 измененных файлов с 235 добавлено и 0 удалено
  1. 43 0
      containers/Containerfile.dev
  2. 7 0
      dev.ps1
  3. 3 0
      dev.sh
  4. 20 0
      docs/toolchain-setup.md
  5. 10 0
      receipts/environment/container-image.json
  6. 11 0
      requirements/dev.txt
  7. 141 0
      tools/dev_container.py

+ 43 - 0
containers/Containerfile.dev

@@ -0,0 +1,43 @@
+FROM docker.io/library/golang@sha256:3b4a11519ad929d1e1d261a12cff056f0c85b735253d7d861346b9c6f8b36437
+
+ENV DEBIAN_FRONTEND=noninteractive \
+    PATH=/opt/sby:/usr/local/go/bin:/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
+    PYTHONDONTWRITEBYTECODE=1 \
+    PIP_DISABLE_PIP_VERSION_CHECK=1
+
+RUN apt-get update \
+    && apt-get install -y --no-install-recommends \
+        boolector \
+        ca-certificates \
+        curl \
+        git \
+        iverilog \
+        jq \
+        libffi-dev \
+        libxml2-dev \
+        libxslt1-dev \
+        make \
+        ninja-build \
+        pkg-config \
+        python3 \
+        python3-dev \
+        python3-pip \
+        python3-venv \
+        ripgrep \
+        shellcheck \
+        unzip \
+        verilator \
+        xz-utils \
+        yosys \
+        z3 \
+        zip \
+    && rm -rf /var/lib/apt/lists/*
+
+COPY requirements/dev.txt /tmp/prod2u-dev-requirements.txt
+RUN python3 -m pip install --break-system-packages --no-cache-dir -r /tmp/prod2u-dev-requirements.txt
+RUN git clone https://github.com/YosysHQ/sby.git /opt/sby \
+    && git -C /opt/sby checkout --detach b1a1e98cba941ec8433f8dc27f416cd7bb7f14be \
+    && make -C /opt/sby install PREFIX=/usr/local
+
+WORKDIR /workspace/cpld-temperature-control
+CMD ["./dev.sh", "doctor"]

+ 7 - 0
dev.ps1

@@ -0,0 +1,7 @@
+param(
+    [Parameter(ValueFromRemainingArguments = $true)]
+    [string[]] $CommandArgs
+)
+
+& wsl.exe -d Debian13 -- /root/workspaces/thermal-system/cpld-temperature-control/dev.sh @CommandArgs
+exit $LASTEXITCODE

+ 3 - 0
dev.sh

@@ -0,0 +1,3 @@
+#!/bin/sh
+set -eu
+exec python3 "$(dirname "$0")/tools/dev_container.py" "$@"

+ 20 - 0
docs/toolchain-setup.md

@@ -0,0 +1,20 @@
+# Debian development toolchain
+
+The editable authority is `/root/workspaces/thermal-system`; the container only mounts it at `/workspace`. The image is Debian-based and digest-pinned. It never accesses COM/JTAG or programs hardware.
+
+```sh
+./dev.sh build
+./dev.sh doctor
+./dev.sh run pytest -q
+./dev.sh shell
+```
+
+Windows is a dispatcher only:
+
+```powershell
+.\dev.ps1 doctor
+```
+
+Durable OSS CAD Suite and Anlogic TD files belong under `/data/prod2u` (or `PRODU2_TOOLCHAIN_BASE`). `td2026` must be invoked through its wrapper so vendor Qt and `LD_LIBRARY_PATH` values exist only for the TD child process.
+
+The generated `receipts/environment/container-image.json` binds the built image ID/digest, base digest, Containerfile hash, Python requirement hash, and SymbiYosys commit. Rebuild and review the receipt after any dependency change.

+ 10 - 0
receipts/environment/container-image.json

@@ -0,0 +1,10 @@
+{
+  "base": "docker.io/library/golang@sha256:3b4a11519ad929d1e1d261a12cff056f0c85b735253d7d861346b9c6f8b36437",
+  "containerfile_sha256": "055fbab4e348d28921608f888053c9fa6b23b13e8747cd06e1fab88daad125c7",
+  "digest": "sha256:ef99a7e44d610dab1b98b9379016a5b59cb64c328cd7256a89f74acdfede8191",
+  "image": "localhost/prod2u-thermal-dev:2026-08-22",
+  "image_id": "f2269397755cb8c03a55537b40c480e88fadc94631a5e8e099da826f85d2f503",
+  "requirements_sha256": "f828119b075191e743366387ee66001594458e966970fa83a581adef3424cc26",
+  "sby_commit": "b1a1e98cba941ec8433f8dc27f416cd7bb7f14be",
+  "schema": "prod2u-container-image-v1"
+}

+ 11 - 0
requirements/dev.txt

@@ -0,0 +1,11 @@
+cocotb==1.9.2
+grpcio==1.71.0
+grpcio-tools==1.71.0
+hypothesis==6.131.9
+jsonschema==4.23.0
+numpy==2.2.4
+pandas==2.2.3
+pyarrow==19.0.1
+pytest==8.3.5
+pytest-timeout==2.3.1
+PyYAML==6.0.2

+ 141 - 0
tools/dev_container.py

@@ -0,0 +1,141 @@
+#!/usr/bin/env python3
+"""Thin, deterministic Podman entrypoint for the Linux-native workspace."""
+
+from __future__ import annotations
+
+import argparse
+import hashlib
+import json
+import os
+from pathlib import Path
+import subprocess
+import sys
+
+
+REPO = Path(__file__).resolve().parents[1]
+WORKSPACE = REPO.parent
+IMAGE = "localhost/prod2u-thermal-dev:2026-08-22"
+CONTAINERFILE = REPO / "containers" / "Containerfile.dev"
+RECEIPT = REPO / "receipts" / "environment" / "container-image.json"
+TOOL_BASE = Path(os.environ.get("PRODU2_TOOLCHAIN_BASE", "/data/prod2u"))
+
+
+def run(argv: list[str], *, capture: bool = False) -> subprocess.CompletedProcess[str]:
+    return subprocess.run(
+        argv,
+        cwd=REPO,
+        check=True,
+        text=True,
+        stdout=subprocess.PIPE if capture else None,
+        stderr=subprocess.STDOUT if capture else None,
+    )
+
+
+def image_digest() -> tuple[str, str]:
+    result = run(
+        ["podman", "image", "inspect", IMAGE, "--format", "{{.Id}} {{.Digest}}"],
+        capture=True,
+    )
+    image_id, digest = result.stdout.strip().split(maxsplit=1)
+    return image_id, digest
+
+
+def container_args() -> list[str]:
+    TOOL_BASE.mkdir(parents=True, exist_ok=True)
+    return [
+        "podman",
+        "run",
+        "--rm",
+        "--pull=never",
+        "--security-opt",
+        "label=disable",
+        "-e",
+        "XDG_CACHE_HOME=/tmp/xdg-cache",
+        "-e",
+        "XDG_STATE_HOME=/tmp/xdg-state",
+        "-e",
+        "XDG_RUNTIME_DIR=/tmp/xdg-runtime",
+        "-v",
+        f"{WORKSPACE}:/workspace",
+        "-v",
+        f"{TOOL_BASE}:/data/prod2u",
+        "-w",
+        "/workspace/cpld-temperature-control",
+        IMAGE,
+    ]
+
+
+def build() -> None:
+    run(
+        [
+            "podman",
+            "build",
+            "--pull=never",
+            "--tag",
+            IMAGE,
+            "--file",
+            str(CONTAINERFILE),
+            str(REPO),
+        ]
+    )
+    image_id, digest = image_digest()
+    payload = {
+        "schema": "prod2u-container-image-v1",
+        "image": IMAGE,
+        "image_id": image_id,
+        "digest": digest,
+        "base": "docker.io/library/golang@sha256:3b4a11519ad929d1e1d261a12cff056f0c85b735253d7d861346b9c6f8b36437",
+        "containerfile_sha256": hashlib.sha256(CONTAINERFILE.read_bytes()).hexdigest(),
+        "requirements_sha256": hashlib.sha256((REPO / "requirements/dev.txt").read_bytes()).hexdigest(),
+        "sby_commit": "b1a1e98cba941ec8433f8dc27f416cd7bb7f14be",
+    }
+    RECEIPT.parent.mkdir(parents=True, exist_ok=True)
+    RECEIPT.write_text(json.dumps(payload, indent=2, sort_keys=True) + "\n", encoding="utf-8")
+    print(json.dumps(payload, indent=2, sort_keys=True))
+
+
+def in_container(command: list[str]) -> None:
+    run(container_args() + command)
+
+
+def doctor() -> None:
+    probe = [
+        "sh",
+        "-c",
+        "set -eu; "
+        "cat /etc/os-release; "
+        "python3 --version; go version; git --version; "
+        "iverilog -V | head -1; verilator --version; yosys -V; sby --version; "
+        "boolector --version; z3 --version; pytest --version; "
+        "python3 -c 'import cocotb,hypothesis,jsonschema,numpy,pandas,pyarrow,yaml; print(\"python-deps=ok\")'",
+    ]
+    in_container(probe)
+
+
+def main() -> int:
+    parser = argparse.ArgumentParser()
+    sub = parser.add_subparsers(dest="command", required=True)
+    sub.add_parser("build")
+    sub.add_parser("doctor")
+    run_parser = sub.add_parser("run")
+    run_parser.add_argument("argv", nargs=argparse.REMAINDER)
+    shell_parser = sub.add_parser("shell")
+    shell_parser.add_argument("argv", nargs=argparse.REMAINDER)
+    args = parser.parse_args()
+
+    if args.command == "build":
+        build()
+    elif args.command == "doctor":
+        doctor()
+    elif args.command == "run":
+        if not args.argv:
+            parser.error("run requires a command")
+        in_container(args.argv)
+    else:
+        command = args.argv or ["bash"]
+        run(container_args()[:-1] + ["-it", container_args()[-1]] + command)
+    return 0
+
+
+if __name__ == "__main__":
+    sys.exit(main())