Skip to content

fix(containers, build-lectures): trust the work tree so pages keep their "Last changed" header - #165

Merged
mmcky merged 3 commits into
mainfrom
fix/container-git-safe-directory
Sep 18, 2026
Merged

mmcky merged 3 commits into
mainfrom
fix/container-git-safe-directory

Conversation

@mmcky

@mmcky mmcky commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Closes #164.

Every page built in a container job loses its "Last changed" header and changelog without a warning. git refuses the runner-owned, bind-mounted work tree when steps run as root, and actions/checkout's own safe.directory entry lives only in a temporary HOME. None of lecture-dp's 52 live pages carries the header. The evidence is on #164.

What changes

File Change
containers/quantecon-build/Dockerfile, containers/quantecon/Dockerfile git config --system --add safe.directory '*': every step of every job can read its checkout, whatever HOME it sets
build-lectures/action.yml before HTML builds: find the work-tree root from source-dir, trust it only if git refuses it, and ::warning:: when git is missing, the source isn't a work tree, git still can't read it, or the clone is shallow. Never fails a build.
.github/workflows/test-container.yml assert git can read the checkout — fails in about a second on the exact condition
.github/workflows/test-containers-lectures.yml assert built pages carry qe-page__header-changed
templates/publish.yml, templates/cache.yml fetch-depth: 0
CHANGELOG.md Unreleased / Fixed

Why both the image and the action. The image entry is the fix; it also covers callers that don't use build-lectures and the preview change detection. The action step is the detector, and a fallback for callers on other images or pinned digests: the next time git breaks for any reason, the log says so instead of the pages going quiet.

The trusted path is the root found from source-dir, not $GITHUB_WORKSPACE. test-containers-lectures.yml checks out into $GITHUB_WORKSPACE/lecture-repo, and git ignores an entry for a directory above or below the root; reproduced on git 2.43.0 built from source. The shallow case warns rather than unshallowing, so the fetch-depth: 1 preview plans in #147–#149 stay a visible trade-off, not a silent one.

What this PR's CI can and cannot show

  • build-containers.yml never runs on a pull request. It runs on pushes to main, the Monday cron and manual dispatch. So the image fix is untested here.
  • test-container.yml and test-containers-lectures.yml run on workflow_run after an image build. They will first run after merge, against the freshly built image, which is the right order.
  • test-actions.yml exercises build-lectures on the bare runner, which proves the new step is a no-op where git already works.

After merge, :latest is rebuilt and every consumer picks it up, lecture-dp included. To confirm:

  1. The two new test assertions pass on the post-merge image build.
  2. The next lecture-dp publish shows "Last changed" on its pages.
  3. test-actions-lecture-intro's header returns.

Tested before opening

🤖 Generated with Claude Code

…eir "Last changed" header

In a container job the runner owns the bind-mounted workspace (uid 1001) while
steps run as root, so git refuses the work tree ("detected dubious ownership",
exit 128) in every step after actions/checkout, whose own safe.directory entry
lives only in a temporary HOME. quantecon-book-theme then drops each page's
"Last changed" header and changelog without a warning; none of lecture-dp's 52
live pages carries it.

- Both images set safe.directory '*' at system scope, so every step of every
  job can read its checkout, whatever HOME it sets.
- build-lectures trusts the work-tree root found from source-dir (not
  $GITHUB_WORKSPACE, which differs when the caller checks out into a
  subdirectory) when git cannot read it, and warns when git is missing, the
  source is not in a work tree, git still cannot read it, or the clone is
  shallow. It never fails a build.
- test-container.yml asserts git can read the checkout; test-containers-
  lectures.yml asserts built pages carry the header. Nothing checked either.
- The publish and cache templates check out with fetch-depth: 0.

See #164.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Copilot AI lite review requested due to automatic review settings September 18, 2026 04:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

It changes git trust/security behavior at image/system scope and the image-side fix cannot be fully validated in PR CI prior to merge.

Pull request overview

This PR addresses a regression where lectures built in container jobs silently lose the quantecon-book-theme “Last changed” header/changelog because git refuses the bind-mounted checkout as “dubious ownership” when steps run as root.

Changes:

  • Configure both container images to trust git work trees by default via a system-level safe.directory setting.
  • Add a pre-build guard in build-lectures to detect when git can’t read the work tree (and warn, without failing builds), including a warning for shallow clones.
  • Add CI assertions to catch the failure mode (git unreadable in container; HTML output missing the header) and update templates to use full-history checkouts (fetch-depth: 0).
File summaries
File Description
containers/quantecon/Dockerfile Adds system-level git safe.directory configuration in the base image.
containers/quantecon-build/Dockerfile Adds system-level git safe.directory configuration in the build image.
build-lectures/action.yml Adds a non-failing pre-build check that attempts to trust the repo and emits warnings when git metadata won’t be available.
.github/workflows/test-container.yml Adds a fast regression assertion that git can read the checkout in a container job.
.github/workflows/test-containers-lectures.yml Adds a regression assertion that built HTML contains the “Last changed” header marker.
templates/publish.yml Ensures full git history is available in consumers so per-page dates/changelog can be computed.
templates/cache.yml Ensures full git history is available in consumers so per-page dates/changelog can be computed.
CHANGELOG.md Documents the fix under Unreleased.
Review details
  • Files reviewed: 8/8 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread build-lectures/action.yml Resolved
Comment thread containers/quantecon-build/Dockerfile Resolved
Comment thread containers/quantecon/Dockerfile Resolved
mmcky and others added 2 commits September 18, 2026 14:33
…git's reason

Review feedback on #165.

The step wrote safe.directory into $HOME/.gitconfig with `git config
--global`. In a container job HOME is the per-job /github/home, but on a
long-lived runner the entry would outlive the job. It now passes the entry as
command-scope config through the environment -- GIT_CONFIG_COUNT/KEY/VALUE,
appended after any a caller set -- exported in the step and via $GITHUB_ENV
for the build and the rest of the job. Nothing is written to disk, and unlike
GIT_CONFIG_GLOBAL it leaves the real global config in force.

The "not in a git work tree" warning discarded git's stderr, so a malformed
GIT_CONFIG_COUNT or any other early failure was misreported. It now quotes
git's own first line.

Both Dockerfiles gain a line saying to revisit the image-wide entry if the
image is ever run on a shared, long-lived host with other users' volumes
mounted.

Tested with git 2.43.0 under GIT_TEST_ASSUME_DIFFERENT_OWNER=1 and GitHub's
shell (bash --noprofile --norc -eo pipefail): seven cases, all exit 0. With the
step's environment loaded, quantecon-book-theme's own helpers date intro.md
2023-12-21 with 8 changelog entries -- has_git_info true, matching
intro.quantecon.org -- and return nothing without it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…s HTML

The new git check in build-lectures warned that the runner's checkout of this
repository is a shallow clone, on each of the two jobs that build HTML with the
local action -- accurate, since actions/checkout defaults to depth 1, but noise
here: the fixture is an untracked copy, so its page dates are not what these
jobs test. Both now fetch full history and read "Git history available".

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@mmcky
mmcky merged commit 3adfcf3 into main Sep 18, 2026
17 checks passed
@mmcky
mmcky deleted the fix/container-git-safe-directory branch September 18, 2026 04:58
mmcky added a commit to QuantEcon/test-lecture-theme-sphinx that referenced this pull request Sep 18, 2026
…4) (#8)

* ci: pin the image by digest, fetch full history, upload PR builds

Decision D14 of the theme-parity project has both test corpora execute
in one image, so the theme is the only variable. All three workflows now
name ghcr.io/quantecon/quantecon-build by its index digest,
sha256:5d256c23..., which the `latest` and `main-3adfcf3` tags named on
2026-09-18, instead of `:latest`, which moves every Monday. A job-level
QE_CONTAINER carries the same ref, because container.image cannot read
env; build_info.md prints it.

Every page on the live site has lost its "Last changed" header: git
refused the runner-owned checkout from the root container, and the theme
drops the header silently when git fails. The image now trusts every
work tree at system scope (see QuantEcon/actions#165). Each workflow
also adds a global safe.directory entry for the checkout as a backstop
against an image that loses that entry, and fails if git still cannot
read the tree. Checkout fetches full history, because a shallow clone
dates every page to HEAD.

CI Preview uploads _build/html as the sphinx-html artefact on pull
requests, kept for 7 days, so a pull request can be inspected before it
merges; Netlify is not configured here, and its guarded step is
unchanged.

actions/checkout moves from v4 to v7, off Node 20 (end-of-life
2026-04-30) onto node24, as part of moving the fleet to Node 24. v6's
credential file does not matter here: nothing in these jobs pushes with
the job token.

environment.yml and lectures/ are untouched, so the build-cache key is
unchanged.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* ci: pin the Node 24 image (actions 195b9f2) instead of the Node 20 one

QuantEcon/actions#166 rebuilt the images with Node 24.21.0 from nodejs.org in
place of conda's end-of-life Node 20; the build asserts the version. All three
workflows move from sha256:5d256c23... to that image's index digest,
sha256:937af97c..., which `latest` and `main-195b9f2` name. The conda env is
unchanged apart from nodejs leaving it, so the kernel should be too; the
build_info page on this PR's artefact is the check.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* ci: build PR previews without the build cache, so build_info is true

After the image was re-pinned to the Node 24 digest, this PR's preview pulled
the new image and then restored the build cache from the previous preview
run; every notebook came from the cache ("Using cached notebook"), and the
build_info page reported the old image's digest, Node 20.17 and build date --
the environment of whichever run last executed it, not this one.

The cache key folds environment.yml, not the image digest, so changing the
image never invalidates it; and even on an unchanged image a cached build_info
shows another run's commit and build time. For a corpus whose purpose is
accurate provenance that is disqualifying. It is 14 pages and builds uncached
in about three minutes. publish.yml never restored the cache, so the live site
was always accurate; this brings pull-request previews into line.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
mmcky added a commit to QuantEcon/test-lecture-theme-mystmd that referenced this pull request Sep 18, 2026
* ci: build in the digest-pinned image on qe-v11, with Node 24

Decision D14 of the theme-parity project has both test corpora execute in
one image, so the theme is the only variable. The build job now runs inside
ghcr.io/quantecon/quantecon-build@sha256:5d256c23..., the image the Sphinx
corpus pins, and the code cells execute in that image's `quantecon` conda env
instead of a setup-python 3.12 env resolved from an unpinned requirements.txt.
requirements.txt is removed; nothing reads it.

The fork moves to qe-v11 (83685347, cut 2026-09-18). It changes no dependency
and, on this corpus, no rendered output once per-build ids are masked; the old
pin was c1f274b8, nine commits past qe-v10, which still printed "qe-v10". The
install step now checks that `myst --version` names the same qe-vN as the
fork's VERSION.yml -- qe-v11's VERSION.yml grew 13 comment lines, so the old
`head -40` would have printed nothing useful.

Three things the container needs, each of which fails silently without it:
- the Jupyter server refuses to start as root unless allow_root is set, and
  myst treats that as non-fatal -- the build went green with no executed
  output on any page;
- git refuses a runner-owned checkout from root, which drops every page's
  "Last changed" history; the image now trusts the tree itself
  (QuantEcon/actions#165) and a global safe.directory step is kept as a
  backstop;
- setup-bun needs unzip, which the image lacks, so bun is installed with npm
  at the fork's own packageManager version.
A check step then fails the job unless build-info shows the image's Python and
every page carries its git history.

Node is not taken from the image: it runs the engine and the theme server,
never a code cell, so it sits outside what D14 holds constant. It is pinned to
24 through setup-node, and the job fails if the image's Node 20 wins on PATH.
Every action here now runs on node24: checkout v7, setup-node v7,
upload-pages-artifact v5 (no dotfiles in this site to lose to v4's exclusion),
deploy-pages v5. The Netlify guard requires both credentials, and netlify-cli
is no longer capped at 26 now Node is 24.

Every edit is under jobs.build except QE_MYSTMD_SHA and its comment.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* ci: resolve localhost to IPv4 first for the HTML export, and diagnose it

The first build in the container executed every notebook and then failed at
HTML export: the theme's server could not fetch
http://localhost:3100/config.json from myst's content server, so every route
returned 404. The same step passes on the runner.

Both of myst's servers bind "localhost" (start.ts, DEFAULT_HOST, passed to the
theme as HOST), and the theme builds its content URL as
`http://localhost:${CONTENT_CDN_PORT}` and fetches it with a bundled
node-fetch v2 -- whose failure it swallows into "No site configuration
found". myst's own fetch to the theme on :3000 worked; the theme's fetch to
:3100 did not, which points at the two resolving localhost to different
address families. mystmd already pins HOST to 127.0.0.1 for ReadTheDocs, the
other containerised builder, for what looks like the same reason.

NODE_OPTIONS=--dns-result-order=ipv4first makes every Node process resolve
localhost to 127.0.0.1, so the bind and the fetch agree, without hard-coding
the content server's port. A temporary, non-fatal step records /etc/hosts,
how localhost resolves and whether loopback has IPv6, and reproduces the
bind-then-fetch pattern with and without the option; it goes once the cause
is confirmed.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* ci: pin the Node 24 image; the localhost cause is confirmed, drop the probe

The image moves from sha256:5d256c23... to sha256:937af97c..., the index
QuantEcon/actions#166 built with Node 24.21.0 in place of conda's end-of-life
Node 20 -- the same digest the Sphinx corpus now pins.

The diagnostic step confirmed why HTML export failed. In this container Node
resolves "localhost" to ::1 first, so a server bound to "localhost" listens on
IPv6 loopback only, while an http client dials 127.0.0.1 and is refused:
measured, the server bound ::1 and http.get(localhost) got ECONNREFUSED
127.0.0.1; with --dns-result-order=ipv4first it bound 127.0.0.1 and got 200.
That is myst's content server against the theme's node-fetch. The option stays,
with the measured mechanism in its comment; the probe step goes.

The README said to `pip install -r requirements.txt`, a file this PR deletes,
and named qe-v10. It now says qe-v11 and that the cells run in the image's
conda env (review feedback on this PR).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
mmcky added a commit to QuantEcon/test-actions-lecture-intro that referenced this pull request Sep 18, 2026
* ci: move actions/checkout from v4 to v7 (node24)

cache.yml, ci.yml and publish.yml pinned actions/checkout@v4, which
resolves to v4.4.0 and declares node20. v7 (v7.0.1) declares node24.
linkcheck.yml is already on @v5, a node24 major, and is left alone.

Supersedes the checkout part of Dependabot PR #11.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* ci: check out full history in publish.yml and cache.yml

Separate from the Node 24 bump, and droppable on its own.

The site builds in the quantecon-build container. Since the image change
in QuantEcon/actions#165 (safe.directory '*'), git can read the checkout,
so quantecon-book-theme renders each page's "Last changed" header and
changelog from git log. With the default depth-1 clone every page would
be dated to the checkout commit. fetch-depth: 0 matches lecture-dp and
the QuantEcon/actions publish and cache templates.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

containers, build-lectures: git refuses the work tree in container jobs, so every page silently loses its "Last changed" header

2 participants