Skip to content

Commit c357b25

Browse files
aledbfclaude
andcommitted
fix(cli): tag an image's Features build per workspace in up
`up` of an image configuration with Features tagged the build `<image>-features`, so every workspace on the same image shared one tag. Concurrent runs retagged it under each other and could start a container from another workspace's image, with that workspace's lifecycle commands in its metadata label. The official CLI tags it `vsc-<folder>-<hash>-features` (getFolderImageName in extendImage), and `build` already did; `up` now does too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 4660f5f commit c357b25

3 files changed

Lines changed: 41 additions & 2 deletions

File tree

‎docs/migration.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ runs the official CLI is unaffected:
111111
build. `up` of a Dockerfile configuration with Features now tags the image
112112
`vsc-<folder>-<hash>`, not `vsc-<folder>-<hash>-features`; a script that looked
113113
the image up by the old name should use the new one.
114+
- `up` of an image configuration with Features tags the image
115+
`vsc-<folder>-<hash>-features`, as the official CLI tags it, instead of
116+
`<image>-features` (for example
117+
`mcr.microsoft.com/devcontainers/base:ubuntu-features`). Every workspace on the
118+
same image shared the old tag, so concurrent `up` runs could start a container
119+
from another workspace's image. A script that looked the image up by the old
120+
name should use the new one, or read it from the container.
114121
- When the workspace is a Git worktree and the configuration sets both
115122
`workspaceMount` and `workspaceFolder`, `up` no longer mounts the main
116123
repository's Git common directory, and `read-configuration` no longer reports

‎internal/cli/dockerfile_build_held_test.go‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,37 @@ func TestUpDockerfileBuildsOnce(t *testing.T) {
176176
}
177177
}
178178

179+
func TestUpImageFeaturesTagsFolderImage(t *testing.T) {
180+
t.Setenv("TMPDIR", t.TempDir())
181+
ws := writeFixture(t, map[string]string{
182+
".devcontainer/devcontainer.json": `{"image":"alpine:3","features":{"./hello":{}}}`,
183+
".devcontainer/hello/devcontainer-feature.json": `{"id":"hello","version":"1.0.0"}`,
184+
".devcontainer/hello/install.sh": "#!/bin/sh\n",
185+
})
186+
loadResult, err := config.LoadDevContainerConfig(ws, "", "")
187+
if err != nil {
188+
t.Fatal(err)
189+
}
190+
r := &fakeDockerRunner{}
191+
run := &upRunner{
192+
log: log.Null,
193+
docker: fakeDockerClient(r),
194+
engine: &docker.EngineClient{API: &fakeDockerAPI{version: "25.0.0", imageConfig: &dockerspec.DockerOCIImageConfig{}}},
195+
opts: &upOpts{workspaceFolder: ws, noLockfile: true, updateRemoteUserUIDDefault: "never"},
196+
substitute: func(*[]imagemeta.Entry) error { return errStopAfterBuild },
197+
}
198+
if _, err := run.fromImage(t.Context(), loadResult.Config, loadResult, ws, nil, true); !errors.Is(err, errStopAfterBuild) {
199+
t.Fatalf("up of an image with a Feature: %v, want it to reach the container", err)
200+
}
201+
builds := imageBuilds(r.calls)
202+
if len(builds) != 1 {
203+
t.Fatalf("docker builds = %v, want one", builds)
204+
}
205+
if got, want := tagsOf(builds[0]), []string{folderImageName(ws) + "-features"}; !slices.Equal(got, want) {
206+
t.Errorf("tags = %v, want %v, as the official CLI names it", got, want)
207+
}
208+
}
209+
179210
type dockerfileBuildRun struct {
180211
files map[string]string
181212
config config.DevContainer

‎internal/cli/up.go‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,8 @@ func (r *upRunner) fromDockerfile(ctx context.Context, cfg *config.DevContainer,
577577

578578
// mutate-lane: TestParityMatrix - up.image-success, up.image-with-features-success,
579579
// up.image-with-git-feature-success and up.update-uid-amd64-platform-option-success
580-
// start through it; also TestE2E_BuildUpExec_Image and TestE2E_FeatureUserHomeAndLocalEnv.
580+
// start through it; also TestUpImageFeaturesTagsFolderImage, TestE2E_BuildUpExec_Image and
581+
// TestE2E_FeatureUserHomeAndLocalEnv.
581582
func (r *upRunner) fromImage(ctx context.Context, cfg *config.DevContainer, loadResult *config.LoadResult, workspaceFolder string, idLabels []string, useBuildx bool) (string, error) {
582583
logger, dockerClient, engine, opts := r.log, r.docker, r.engine, r.opts
583584
if cfg.Image == "" {
@@ -600,7 +601,7 @@ func (r *upRunner) fromImage(ctx context.Context, cfg *config.DevContainer, load
600601
imageName := cfg.Image
601602
if len(cfg.Features) > 0 {
602603
r.lockfileRead = !opts.noLockfile
603-
names, err := extendImageWithFeatures(ctx, logger, dockerClient, engine, cfg.Image, cfg.Features, useBuildx, nil, r.featureBuildOptions(cfg, loadResult, platform))
604+
names, err := extendImageWithFeatures(ctx, logger, dockerClient, engine, cfg.Image, cfg.Features, useBuildx, []string{folderImageName(workspaceFolder) + "-features"}, r.featureBuildOptions(cfg, loadResult, platform))
604605
if err != nil {
605606
return "", fmt.Errorf("install features: %w", err)
606607
}

0 commit comments

Comments
 (0)