Update-Content Phase
Hooks driven by repository content — lockfiles, manifests, checked-in configuration — that restore dependencies once the workspace is synchronised.
- Kind
- Lifecycle
- Domain
- Environment & Tooling
- Applies at
.devcontainer/lifecycle/update-content.d/- Status
- Stable
- Source · managed
.devcontainer/lifecycle/update-content.d/README.md
01 Defines
The updateContentCommand phase: scripts in update-content.d/ that run after repository content is synchronised into the workspace during creation, and again when that content is refreshed, before final post-create setup.
02 Applies when
- Dependencies are restored from a lockfile or manifest checked into the repository.
- Derived content is regenerated from checked-in configuration or source files.
- The work should rerun when workspace content is refreshed during creation or prebuilding.
03 Boundaries
- User-home setup such as
.zshrc,.npmrc, or cache directories belongs in on-create. - Background services and every-start runtime checks belong in post-start.
- Interactive authentication and onboarding prompts are out of scope.
Expected behaviour
- 01Scripts are driven by repository state, not by the container or the developer.
- 02Scripts are idempotent and safe when content is synchronised again.
- 03Restores use the lockfile when one is present.
- 04A failing script is reported and skipped by the runner; the workspace comes up with the failure named.
Behaviour#
Update-content is where the repository’s own files start to matter. It runs once the workspace content is available, and may run again when that content is refreshed during creation or prebuilding. Because the work is a function of the checked-in files, rerunning it after a content change brings the workspace back in line.
It sits between two easily confused neighbours. On-Create Phase prepares the container before content matters; Post-Create Phase finishes the workspace once everything is in place. Update-content is the step that responds to the content itself.
Reruns with the content#
Unlike the one-shot creation hooks, this phase is designed to run again: a
content refresh during prebuilding, or a dependency manifest changed while
the container slept, both come back here. That is why every hook takes the
repository’s own state as its only input. A restore that reads the lockfile
converges on the same node_modules either way; a hook that assumed “first
run” would drift.
The phase is also the natural place for the restore to be pinned: npm ci
over npm install when a lockfile exists, --frozen-lockfile for pnpm —
the workspace gets exactly what the repository committed, not what the
registry serves today.
Failure behaviour#
A failing restore is reported and skipped, and the container still comes up. The failure is visible twice: in the event summary, and in whatever command first needs the dependencies that were not restored. Rerunning the phase by hand repeats the same work against the same inputs, which is both the diagnostic and the fix — a restore that fails on retry is a repository problem, not a lifecycle problem.
Good uses
npm ciorpnpm install --frozen-lockfileonce the lockfile is availabledotnet restoreonce solution and project files are present- Downloading Hugo modules or regenerating derived site content
Avoid
- User-home setup such as
.zshrc,.npmrc, or cache directories - Background services or checks that must happen on every start
- Interactive authentication or onboarding prompts
Examples#
This repository restores its pinned Node tooling here — the hook that puts
Prettier, at the version CI uses, on PATH via node_modules/.bin:
#!/usr/bin/env bash
# Install the repository's pinned Node lint tooling (Prettier).
set -euo pipefail
repo_root="${WORKSPACE:-$(CDPATH= cd -- "$(dirname "$0")/../../.." && pwd)}"
cd "$repo_root"
if [ ! -f package.json ]; then
echo "skip: no root package.json"
exit 0
fi
if [ -f package-lock.json ]; then
npm ci
else
npm install
fi
printf 'ok: prettier -> %s\n' "$(./node_modules/.bin/prettier --version)"
Three details make it a textbook update-content hook: the skip: guard keeps
repositories without a manifest quiet instead of failing them, the lockfile
branch makes the restore reproducible, and the final version line reports
what the phase achieved, so a wrong version is visible in the run itself.
Connections