Skip to content

perf(devcontainer): keep the Feature layers under the project layer #6470

Done

Description

@dan-petty

Problem

The Dev Containers CLI adds the layers of the Dev Container Features after the last stage of .devcontainer/Dockerfile. After #6414, the project layer (COPY --link of the package) is the last layer of the Dockerfile, so a change of src/ builds the two Feature layers again. In a local cold build of #6414, common-utils took 47 s and podman-in-podman took 20 s, and the two layers are 44 MiB and 2 MiB compressed. Each release then pushes them as new layers, so GHCR does not show only the project layer as new between two releases (Proof of #6414).

Expected

  • A release that changes only src/ builds and pushes only the project layer, and the Feature layers keep their digests.
  • One option: the build action builds the image with its Features but without the project, then a second BuildKit build adds the project layer FROM that digest, and the release flow keeps push-by-digest, the metadata file and the smoke test before the tag.

Proof

  • Two releases in a row that change only src/: docker buildx imagetools inspect --raw shows the same digest for every layer except the project layer.
  • The DevContainer Image job stays under 5 min plus 1 min.

Source: #6414

Alternatives check of 2026-11-20: not-applicable.
Class: perf, no search.
Tool: none found.

Proposed design

Problem statement

Build the Feature image first from a base stage, then add the project layer in a second docker buildx build from its digest. Each release now rebuilds the Dev Container Feature layers, because the Dev Containers CLI adds them after the last stage of .devcontainer/Dockerfile and the project layer is below them. A release that changes only src/ then pushes only the project layer.

Acceptance criteria

Requirement: Base stage without the project

The .devcontainer/Dockerfile SHALL define a base stage that holds the base image, the tools and the dependencies, and SHALL keep the project package and its install out of that stage.

Scenario: The base stage builds without the project

  • WHEN A person runs docker buildx build --target base --load -t devcontainer-base -f .devcontainer/Dockerfile .
  • THEN The build succeeds and docker run --rm --entrypoint python devcontainer-base -c 'import devops_cli' exits non-zero.

Requirement: Project stage on the base image

The .devcontainer/Dockerfile SHALL define a project stage that starts FROM ${BASE_IMAGE} and SHALL put the project COPY and its install in that stage.

Scenario: The project stage builds on a base image

  • WHEN A person runs docker buildx build --target project --build-arg BASE_IMAGE=devcontainer-base --load -t devcontainer-project -f .devcontainer/Dockerfile .
  • THEN The build succeeds and docker run --rm --entrypoint devops devcontainer-project --version exits zero.

Requirement: Action builds the Feature image first

The .github/actions/devcontainer-image/action.yml SHALL run the Dev Containers CLI build with the base target, push the Feature image by digest, and run docker buildx build --target project --build-arg BASE_IMAGE=<feature digest> after that build.

Scenario: The action runs the Feature build before the project build

  • WHEN A person runs the DevContainer Image job with workflow_dispatch on the changed branch
  • THEN The job succeeds, the Feature build step completes before the project build step, and the smoke step starts the digest of the project build.

Requirement: Project build keeps push-by-digest and metadata

The project build SHALL push with push-by-digest=true and SHALL write the final digest to a metadata file that the action reads for its digest output.

Scenario: The action reads the final digest from the metadata file

  • WHEN The DevContainer Image job runs on a pull request that changes .github/actions/devcontainer-image/**
  • THEN The image step output equals the containerimage.digest value in the project build's metadata file, and the push uses push-by-digest=true.

Requirement: Release tags the smoke-tested project digest

release.yml SHALL pass the digest of the project build to the smoke test, the attestation and the tag, and SHALL NOT tag the Feature build digest.

Scenario: The release tags the smoke-tested project digest

  • WHEN A person runs docker buildx imagetools inspect ghcr.io/dan-petty/devops-cli/devcontainer:<release-tag> --format '{{json .Manifest}}' after a release
  • THEN The tag resolves to the digest that the Smoke-Test DevContainer Image job started and the Attest & Tag DevContainer Image job attested.

Requirement: Feature build keeps the registry cache

The action SHALL pass cache-from to both builds and cache-to to the Feature build, so a release that changes only src/ reads the Feature layers from the registry cache.

Scenario: A source-only release reads the Feature layers from the cache

  • WHEN The Build DevContainer Image job runs on a release that changes only files under src/ with the registry cache populated
  • THEN The Feature build reports a cache hit for the Feature layers and the job completes in under 5 minutes plus 1 minute.

Requirement: The static checks pass

The changed .github/actions/devcontainer-image/action.yml, .github/workflows/devcontainer-image.yml and .github/workflows/release.yml SHALL pass actionlint and zizmor.

Scenario: The static checks pass on the changed workflows

  • WHEN A person runs uv run devops ci --check --only actionlint,zizmor
  • THEN The actionlint and zizmor rows pass.

Existing Tool Considered

The alternatives check of 2026-11-20 records not-applicable (class perf, no search, no tool found). The change adds no new tool. It keeps the pinned Dev Containers CLI 0.90.0 for the Feature build and uses docker buildx for the project stage. The CLI lacks a way to add a layer after the Feature layers, so the project layer is a second build.

Key questions

  • Does the change wait on fix(devcontainer): build the devcontainer image FROM devtools #6414 or its replacement?: No. fix(devcontainer): build the devcontainer image FROM devtools #6414 is closed and the commit being refined does not hold its devtools base, lock stage or COPY --link project layer. The change adds its own base and project stages to the current .devcontainer/Dockerfile, so it needs no dependency. (best practice) [sources: .github/actions/devcontainer-image/action.yml]
  • Which build layout keeps the Feature layers under the project layer?: Build the Feature image first from a named base stage with devcontainer build --target base, push it by digest, then run docker buildx build --target project --build-arg BASE_IMAGE=<feature digest> to add the project COPY and its install. The Dev Containers CLI adds the Features after the last stage, so the project layer must be in the second build. (best practice) [sources: .github/actions/devcontainer-image/action.yml:47-88]
    • Chosen: Two builds: Feature base image, then the project stage on its digest. The Dev Containers CLI adds the Features after the last stage, so no single build can put the project above them.
    • Rejected: Set build.target to a stage before the project COPY. That is the first build only; it produces an image with no project package, so a second build is still needed.
    • Rejected: Keep the project layer under the Features and accept the rebuild. That is the current defect: each src/ change rebuilds the Feature layers.
    • Rejected: Install the Features in the Dockerfile as stages. The Dev Containers CLI owns the Feature install and the devcontainer.metadata label; a hand-built copy would duplicate the tool and lose the label.
  • Where do the two builds run?: Both builds are steps of the shared .github/actions/devcontainer-image/action.yml, which the DevContainer Image job of devcontainer-image.yml and the Build DevContainer Image job of release.yml call. The Feature digest stays in the one job. The smoke test stays in its own job in release.yml and as the last step in devcontainer-image.yml. (best practice) [sources: .github/actions/devcontainer-image/action.yml:33-93, .github/workflows/devcontainer-image.yml:97-108, .github/workflows/release.yml:212-260]
    • Chosen: Both builds in the shared action, one job. The second build needs the first build's digest, and both workflows already call the one action; no artifact passes the digest between jobs.
    • Rejected: Two jobs, with the digest passed by an artifact. A passed digest adds a job, an artifact and a second metadata file.
    • Rejected: A second reusable workflow. It adds moving parts for one image, and the release reads one flow.
  • Which digest does the release tag, and where does the smoke test run?: The tag names the digest of the project build, which is the image with the Features and the current package. The action outputs that digest from the project build's metadata file. The smoke test starts that digest before the attestation and the tag. (best practice) [sources: .github/actions/devcontainer-image/action.yml:28-31, .github/workflows/release.yml:260, .github/workflows/release.yml:290, .github/workflows/release.yml:298-306]
    • Chosen: Tag the project build digest. It is the image that holds the Features and the current package, so the smoke test checks what the release ships.
    • Rejected: Tag the Feature build digest. It has no project layer, so the tag would ship an older package.
    • Rejected: Tag both digests. Two tags for one release confuse the pull of a release.
  • Which build input does the second build use?: The second build uses the project stage of the same .devcontainer/Dockerfile, which starts FROM ${BASE_IMAGE} and is selected with docker buildx build --target project --build-arg BASE_IMAGE=<feature digest>. The base stage is the default BASE_IMAGE, so a plain build still works. (best practice) [sources: .devcontainer/image/devcontainer.json:3-6, .github/actions/devcontainer-image/action.yml:47-88]
    • Chosen: A stage of the same Dockerfile, selected with --target. One Dockerfile holds both builds, so the project COPY stays in one place; ARG BASE_IMAGE lets the stage start from the Feature digest.
    • Rejected: A second Dockerfile. Two files hold the project layer, and they drift apart.
    • Rejected: The existing last stage with a build argument. The Features still land on top of the project layer, so the defect stays.
  • How does the change keep the job under its time budget?: The Feature build keeps the registry cache: cache-from reads it in both workflows and cache-to writes it in release.yml. A release that changes only src/ finds the Feature layers in the cache, so only the project build runs. The project build reads the same cache and writes none. (best practice) [sources: .github/actions/devcontainer-image/action.yml:19-26, .github/actions/devcontainer-image/action.yml:76-79, .github/workflows/release.yml:210-219]
    • Chosen: Registry cache on the Feature build. An unchanged Feature build is a cache hit, so the project build is the only work of a source-only release.
    • Rejected: No cache. A cold build of the Feature layers took 47 s and 20 s, and that cost comes back each release.
    • Rejected: GitHub Actions cache. The release job needs the runtime token that a run: step does not get without a helper; the project already uses a registry cache.
  • Which tool covers the build and the Features?: The official Dev Containers CLI 0.90.0, pinned at src/devops_cli/tools_lock/tools.lock:605-609, builds the image with its Features. docker buildx builds the project stage. The CLI lacks a way to add a layer after the Features, so the change uses the second build. [sources: src/devops_cli/tools_lock/tools.lock:605-609, .github/actions/devcontainer-image/action.yml:47-88]
  • Which documents must the pull request update?: The pull request must update docs/SDLC.md and docs/DEVCONTAINER_USAGE.md to name the Feature build and the project build. (best practice) [sources: docs/SDLC.md, docs/DEVCONTAINER_USAGE.md]
    • Chosen: Update both documents. Both describe the build flow that the two builds change.
    • Rejected: Update only docs/SDLC.md. The usage guide would still give the old single build command.
    • Rejected: Update no document. The docs would stay wrong after the change.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    type/infra
    source/agent
    status/new
    value/medium
    effort/medium
    on Nov 19, 2026
  2. added
    scope/devcontainer
    on Nov 19, 2026
  3. dan-petty commented on Nov 19, 2026

    @dan-petty
    OwnerAuthor
  4. added
    priority/p2-medium
    on Nov 19, 2026
  5. devops-cli-service commented on Nov 20, 2026

    @devops-cli-service
    Contributor

    Next step: the alternatives check records a verdict. See the section Proposed design of the body.

  6. added
    status/ready
    and removed
    status/new
    on Nov 20, 2026
  7. devops-cli-service commented on Nov 20, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See the section Proposed design of the body.

  8. added
    owner/agent
    status/in-progress
    and removed
    status/ready
    on Nov 24, 2026
  9. added
    status/in-review
    and removed
    status/in-progress
    on Nov 24, 2026
  10. removed
    status/in-review
    owner/agent
    on Nov 24, 2026
  11. devops-cli-service commented on Nov 24, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-24 13:45 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/mediumpriority/p2-mediumscope/devcontainersource/agenttype/infravalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions