From a3304397a1ba53178dc0befc62888c842218893a Mon Sep 17 00:00:00 2001 From: bilby91 <2201079+bilby91@users.noreply.github.com> Date: Thu, 19 Nov 2026 04:21:44 +0000 Subject: [PATCH] fix(config): resolve build.dockerfile against devcontainer.json, not the context The spec resolves build.dockerfile relative to the folder holding devcontainer.json, like build.context. We passed it through unchanged and the runtime asked Docker for it inside the context tar, so {"dockerfile": "Dockerfile", "context": ".."} looked for /Dockerfile and failed with "open Dockerfile: no such file or directory". - config: BuildSource.Dockerfile is now an absolute host path. Both dockerfile and context are resolved after variable substitution, so ${localWorkspaceFolder}/... is no longer joined onto the config folder. - runtime/docker: BuildSpec.Dockerfile may be absolute. Inside the context it becomes the context-relative name; outside it is appended to the context tar as .dockerfile., as `docker build -f` does for the reference CLI. prePullBaseImages reads the host path. - tests: config resolution cases, locateDockerfile / tar injection unit tests, the dcvm layout and an outside-context build end to end. Integration fixtures that relied on the bug now use "../Dockerfile". Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 15 +++ config/resolve.go | 26 ++++- config/resolve_test.go | 59 ++++++++++- config/resolved.go | 3 + design/resolved-config.md | 2 +- runtime/docker/build.go | 84 +++++++++++++--- runtime/docker/build_test.go | 97 ++++++++++++++++++- runtime/runtime.go | 16 +-- .../integration/build_context_symlink_test.go | 2 +- test/integration/build_source_test.go | 57 ++++++++++- test/integration/build_test.go | 4 +- .../integration/buildkit_trace_events_test.go | 2 +- test/integration/userenvprobe_test.go | 2 +- 13 files changed, 328 insertions(+), 41 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 691a3ed..0ba6c73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- **config** — `build.dockerfile` is resolved against the folder that + holds `devcontainer.json`, as the spec and the reference CLI do, not + against `build.context`. `{"dockerfile": "Dockerfile", "context": ".."}` + now builds `.devcontainer/Dockerfile` with the repo root as context, + instead of failing with `open Dockerfile: no such file or directory`. + `BuildSource.Dockerfile` is now an absolute host path. A config that + relied on the old behaviour (a `Dockerfile` in the context root + referenced as `"Dockerfile"` with `"context": ".."`) must use + `"../Dockerfile"`, as it already must for the reference CLI. Both + paths are now resolved after variable substitution, so + `"context": "${localWorkspaceFolder}"` is no longer joined onto the + config folder. `runtime.BuildSpec.Dockerfile` accepts an absolute path; one outside + the context is sent in the context tar under a reserved + `.dockerfile.` name, as `docker build -f` does. + - **features** — a feature option declared as a string (or untyped) that is given a non-string value is converted the way the reference CLI converts it, instead of failing with `option "packages" expects diff --git a/config/resolve.go b/config/resolve.go index ff44fae..698f4ef 100644 --- a/config/resolve.go +++ b/config/resolve.go @@ -356,9 +356,9 @@ func determineSource(raw *rawConfig, configDir string) (Source, []Warning, error if ctxPath == "" { ctxPath = "." } - if !filepath.IsAbs(ctxPath) { - ctxPath = filepath.Join(configDir, ctxPath) - } + // Dockerfile and Context stay as written here; substituteAll + // resolves them against the devcontainer.json folder after + // substitution, so ${localWorkspaceFolder}/… stays absolute. return &BuildSource{ Dockerfile: raw.Build.Dockerfile, Context: ctxPath, @@ -534,8 +534,16 @@ func substituteAll(out *ResolvedConfig, ctx SubstitutionContext, source string) case *ImageSource: s.Image = subStr(s.Image, "/image") case *BuildSource: - s.Dockerfile = subStr(s.Dockerfile, "/build/dockerfile") - s.Context = subStr(s.Context, "/build/context") + // The spec resolves both dockerfile and context against the + // devcontainer.json folder (dockerfile is NOT relative to + // context), after substitution, as the reference CLI does. The + // runtime re-expresses Dockerfile relative to the context it + // tars up. + configDir := filepath.Dir(source) + if df := subStr(s.Dockerfile, "/build/dockerfile"); df != "" { + s.Dockerfile = resolveAgainst(configDir, df) + } + s.Context = resolveAgainst(configDir, subStr(s.Context, "/build/context")) s.Target = subStr(s.Target, "/build/target") subMap(s.Args, "/build/args") s.CacheFrom = subSlice(s.CacheFrom, "/build/cacheFrom") @@ -546,6 +554,14 @@ func substituteAll(out *ResolvedConfig, ctx SubstitutionContext, source string) } } +// resolveAgainst returns p unchanged when absolute, else joined to dir. +func resolveAgainst(dir, p string) string { + if filepath.IsAbs(p) { + return p + } + return filepath.Join(dir, p) +} + func substituteLifecycle(lc *LifecycleCommands, sub func(s, path string) string) { pairs := []struct { cmds *[]LifecycleCommand diff --git a/config/resolve_test.go b/config/resolve_test.go index e2d9301..b0c47b3 100644 --- a/config/resolve_test.go +++ b/config/resolve_test.go @@ -74,8 +74,9 @@ func TestResolveBytes_BuildSource(t *testing.T) { if !ok { t.Fatalf("Source = %+v", cfg.Source) } - if bs.Dockerfile != "Dockerfile" { - t.Errorf("Dockerfile = %q", bs.Dockerfile) + // dockerfile resolves against configDir, not against context. + if bs.Dockerfile != "/home/u/proj/.devcontainer/Dockerfile" { + t.Errorf("Dockerfile = %q, want /home/u/proj/.devcontainer/Dockerfile", bs.Dockerfile) } // context "..", configDir "/home/u/proj/.devcontainer" → "/home/u/proj" if bs.Context != "/home/u/proj" { @@ -89,6 +90,60 @@ func TestResolveBytes_BuildSource(t *testing.T) { } } +func TestResolveBytes_BuildSourceDockerfilePath(t *testing.T) { + cases := []struct { + name, build, wantDockerfile, wantContext string + }{ + { + name: "default context", + build: `{"dockerfile": "Dockerfile"}`, + wantDockerfile: "/home/u/proj/.devcontainer/Dockerfile", + wantContext: "/home/u/proj/.devcontainer", + }, + { + name: "parent context, dockerfile beside config", + build: `{"dockerfile": "Dockerfile", "context": ".."}`, + wantDockerfile: "/home/u/proj/.devcontainer/Dockerfile", + wantContext: "/home/u/proj", + }, + { + name: "parent context, dockerfile in parent", + build: `{"dockerfile": "../build/Dockerfile", "context": ".."}`, + wantDockerfile: "/home/u/proj/build/Dockerfile", + wantContext: "/home/u/proj", + }, + { + name: "absolute dockerfile", + build: `{"dockerfile": "/srv/images/Dockerfile", "context": ".."}`, + wantDockerfile: "/srv/images/Dockerfile", + wantContext: "/home/u/proj", + }, + { + // Substitution runs before resolution, so a variable that + // expands to an absolute path is not joined to configDir. + name: "substituted absolute paths", + build: `{"dockerfile": "${localWorkspaceFolder}/docker/Dockerfile", "context": "${localWorkspaceFolder}"}`, + wantDockerfile: "/home/u/proj/docker/Dockerfile", + wantContext: "/home/u/proj", + }, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + cfg := resolveJSON(t, `{"build": `+tc.build+`}`, ResolveInput{}) + bs, ok := cfg.Source.(*BuildSource) + if !ok { + t.Fatalf("Source = %+v", cfg.Source) + } + if bs.Dockerfile != tc.wantDockerfile { + t.Errorf("Dockerfile = %q, want %q", bs.Dockerfile, tc.wantDockerfile) + } + if bs.Context != tc.wantContext { + t.Errorf("Context = %q, want %q", bs.Context, tc.wantContext) + } + }) + } +} + func TestResolveBytes_ComposeSource(t *testing.T) { cfg := resolveJSON(t, `{ "dockerComposeFile": ["docker-compose.yml","docker-compose.override.yml"], diff --git a/config/resolved.go b/config/resolved.go index b07013f..48605b1 100644 --- a/config/resolved.go +++ b/config/resolved.go @@ -133,6 +133,9 @@ func (*ImageSource) isSource() {} func (*ImageSource) Kind() SourceKind { return SourceImage } type BuildSource struct { + // Dockerfile is an absolute host path: the spec resolves + // build.dockerfile against the devcontainer.json folder, not + // against Context. Empty when the config leaves it unset. Dockerfile string Context string Args map[string]string diff --git a/design/resolved-config.md b/design/resolved-config.md index 9387665..48b33ee 100644 --- a/design/resolved-config.md +++ b/design/resolved-config.md @@ -123,7 +123,7 @@ type ImageSource struct { } type BuildSource struct { - Dockerfile string // path relative to context + Dockerfile string // absolute, host-side (spec: relative to devcontainer.json's folder) Context string // absolute, host-side Args map[string]string Target string diff --git a/runtime/docker/build.go b/runtime/docker/build.go index a679666..a8387ff 100644 --- a/runtime/docker/build.go +++ b/runtime/docker/build.go @@ -4,6 +4,8 @@ import ( "archive/tar" "bytes" "context" + "crypto/sha256" + "encoding/hex" "encoding/json" "fmt" "io" @@ -44,19 +46,19 @@ func (r *Runtime) BuildImage(ctx context.Context, spec runtime.BuildSpec, events return runtime.ImageRef{}, fmt.Errorf("BuildImage: spec.Tag required") } + dockerfilePath, dockerfile, injected, err := locateDockerfile(spec.ContextPath, spec.Dockerfile) + if err != nil { + return runtime.ImageRef{}, err + } + // Stream the context directory as a tar over an io.Pipe so we // don't buffer it all in memory. pr, pw := io.Pipe() go func() { - err := tarDirectory(spec.ContextPath, pw) + err := tarDirectory(spec.ContextPath, injected, pw) _ = pw.CloseWithError(err) }() - dockerfile := spec.Dockerfile - if dockerfile == "" { - dockerfile = "Dockerfile" - } - args := make(map[string]*string, len(spec.Args)) for k, v := range spec.Args { v := v @@ -71,7 +73,7 @@ func (r *Runtime) BuildImage(ctx context.Context, spec runtime.BuildSpec, events // (which is unaffected by the session requirement) seeds the local // store; BuildKit then picks up the cached manifest instead of // reaching for the registry. - prePullBaseImages(ctx, r, spec.ContextPath, dockerfile, spec.Args, events) + prePullBaseImages(ctx, r, dockerfilePath, spec.Args, events) res, err := r.api.ImageBuild(ctx, pr, client.ImageBuildOptions{ Dockerfile: dockerfile, @@ -178,8 +180,50 @@ func streamBuildOutput(ctx context.Context, body io.ReadCloser, events chan<- ru // avoids any reader special-casing the year-1 sentinel. var tarEpoch = time.Unix(0, 0) +// tarFile is a regular file appended to a build-context tar after the +// directory walk. +type tarFile struct { + Name string + Body []byte +} + +// locateDockerfile maps a BuildSpec.Dockerfile onto the host file to +// read (hostPath) and the name the daemon should open inside the +// context tar (tarName). dockerfile is either relative to contextPath +// (empty means "Dockerfile") or an absolute host path. +// +// An absolute path inside the context becomes its context-relative +// name. One outside the context can't be reached through the tar, so +// it is read and returned as injected, to be appended under a reserved +// name, matching `docker build -f ` (which the +// reference devcontainer CLI runs). The name carries a content hash +// rather than the docker CLI's random suffix so the tar stays +// reproducible. +func locateDockerfile(contextPath, dockerfile string) (hostPath, tarName string, injected *tarFile, err error) { + if dockerfile == "" { + dockerfile = "Dockerfile" + } + if !filepath.IsAbs(dockerfile) { + return filepath.Join(contextPath, dockerfile), filepath.ToSlash(dockerfile), nil, nil + } + absCtx, err := filepath.Abs(contextPath) + if err != nil { + return "", "", nil, fmt.Errorf("BuildImage: context path %s: %w", contextPath, err) + } + if rel, err := filepath.Rel(absCtx, dockerfile); err == nil && filepath.IsLocal(rel) { + return dockerfile, filepath.ToSlash(rel), nil, nil + } + body, err := os.ReadFile(dockerfile) + if err != nil { + return "", "", nil, fmt.Errorf("BuildImage: read dockerfile outside context: %w", err) + } + sum := sha256.Sum256(body) + name := ".dockerfile." + hex.EncodeToString(sum[:])[:12] + return dockerfile, name, &tarFile{Name: name, Body: body}, nil +} + // tarDirectory writes the contents of dir (recursively) into w as a -// non-gzipped tar archive. Symlinks are preserved as tar TypeSymlink +// non-gzipped tar archive, followed by extra when non-nil. Symlinks are preserved as tar TypeSymlink // entries with their original target text; the daemon-side BuildKit // frontend handles the resolution. // @@ -188,11 +232,11 @@ var tarEpoch = time.Unix(0, 0) // Linkname. Some downstream tar readers reject those as malformed and // abort the build mid-stream — common in compose-primary contexts // containing node_modules/.bin/* or similar bin-symlinks. -func tarDirectory(dir string, w io.Writer) error { +func tarDirectory(dir string, extra *tarFile, w io.Writer) error { tw := tar.NewWriter(w) defer func() { _ = tw.Close() }() - return filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error { + err := filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error { if err != nil { return err } @@ -258,9 +302,23 @@ func tarDirectory(dir string, w io.Writer) error { _ = f.Close() return err }) + if err != nil || extra == nil { + return err + } + if err := tw.WriteHeader(&tar.Header{ + Typeflag: tar.TypeReg, + Name: extra.Name, + Mode: 0o644, + Size: int64(len(extra.Body)), + ModTime: tarEpoch, + }); err != nil { + return err + } + _, err = tw.Write(extra.Body) + return err } -// prePullBaseImages reads the Dockerfile at contextPath/dockerfile, +// prePullBaseImages reads the Dockerfile at dockerfilePath, // extracts its frontend image (a `# syntax=` directive or the // BUILDKIT_SYNTAX build arg) and FROM image references (resolving // simple $ARG substitutions against ARG defaults in the file and the @@ -277,8 +335,8 @@ func tarDirectory(dir string, w io.Writer) error { // anonymous registry access when no session is attached, so this only // changes the outcome on older engines; there it is what makes public // images resolvable at all. -func prePullBaseImages(ctx context.Context, r *Runtime, contextPath, dockerfile string, buildArgs map[string]string, events chan<- runtime.BuildEvent) { - df, err := os.ReadFile(filepath.Join(contextPath, dockerfile)) +func prePullBaseImages(ctx context.Context, r *Runtime, dockerfilePath string, buildArgs map[string]string, events chan<- runtime.BuildEvent) { + df, err := os.ReadFile(dockerfilePath) if err != nil { return } diff --git a/runtime/docker/build_test.go b/runtime/docker/build_test.go index f5c9899..5a48e8c 100644 --- a/runtime/docker/build_test.go +++ b/runtime/docker/build_test.go @@ -7,6 +7,7 @@ import ( "os" "path/filepath" "reflect" + "strings" "testing" "time" ) @@ -115,7 +116,7 @@ func TestTarDirectoryNormalizesMetadata(t *testing.T) { } var buf bytes.Buffer - if err := tarDirectory(dir, &buf); err != nil { + if err := tarDirectory(dir, nil, &buf); err != nil { t.Fatalf("tarDirectory: %v", err) } @@ -172,10 +173,10 @@ func TestTarDirectoryDeterministic(t *testing.T) { b := mkContext(t, time.Unix(1_800_000_000, 0)) var bufA, bufB bytes.Buffer - if err := tarDirectory(a, &bufA); err != nil { + if err := tarDirectory(a, nil, &bufA); err != nil { t.Fatalf("tarDirectory a: %v", err) } - if err := tarDirectory(b, &bufB); err != nil { + if err := tarDirectory(b, nil, &bufB); err != nil { t.Fatalf("tarDirectory b: %v", err) } if !bytes.Equal(bufA.Bytes(), bufB.Bytes()) { @@ -240,3 +241,93 @@ func TestSyntaxFrontend(t *testing.T) { }) } } + +func TestLocateDockerfile(t *testing.T) { + root := t.TempDir() + ctxDir := filepath.Join(root, "repo") + outside := filepath.Join(root, "elsewhere", "Dockerfile") + if err := os.MkdirAll(filepath.Dir(outside), 0o755); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(outside, []byte("FROM alpine\n"), 0o644); err != nil { + t.Fatal(err) + } + + cases := []struct { + name, dockerfile, wantHost, wantTar string + }{ + {"empty defaults to Dockerfile", "", filepath.Join(ctxDir, "Dockerfile"), "Dockerfile"}, + {"relative to context", "sub/Dockerfile", filepath.Join(ctxDir, "sub", "Dockerfile"), "sub/Dockerfile"}, + {"absolute inside context", filepath.Join(ctxDir, ".devcontainer", "Dockerfile"), + filepath.Join(ctxDir, ".devcontainer", "Dockerfile"), ".devcontainer/Dockerfile"}, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + host, name, injected, err := locateDockerfile(ctxDir, tc.dockerfile) + if err != nil { + t.Fatal(err) + } + if host != tc.wantHost || name != tc.wantTar || injected != nil { + t.Errorf("got (%q, %q, %v), want (%q, %q, nil)", host, name, injected, tc.wantHost, tc.wantTar) + } + }) + } + + t.Run("absolute outside context is injected", func(t *testing.T) { + host, name, injected, err := locateDockerfile(ctxDir, outside) + if err != nil { + t.Fatal(err) + } + if host != outside { + t.Errorf("host = %q, want %q", host, outside) + } + if injected == nil || injected.Name != name || string(injected.Body) != "FROM alpine\n" { + t.Fatalf("injected = %+v, name %q", injected, name) + } + if !strings.HasPrefix(name, ".dockerfile.") { + t.Errorf("name = %q, want .dockerfile.", name) + } + // Deterministic: same content, same name. + _, again, _, _ := locateDockerfile(ctxDir, outside) + if again != name { + t.Errorf("name not stable: %q vs %q", name, again) + } + }) + + t.Run("missing outside dockerfile errors", func(t *testing.T) { + if _, _, _, err := locateDockerfile(ctxDir, filepath.Join(root, "nope", "Dockerfile")); err == nil { + t.Fatal("want error") + } + }) +} + +func TestTarDirectoryAppendsExtra(t *testing.T) { + dir := t.TempDir() + if err := os.WriteFile(filepath.Join(dir, "file.txt"), []byte("hello"), 0o644); err != nil { + t.Fatal(err) + } + var buf bytes.Buffer + if err := tarDirectory(dir, &tarFile{Name: ".dockerfile.abc", Body: []byte("FROM alpine\n")}, &buf); err != nil { + t.Fatalf("tarDirectory: %v", err) + } + got := map[string]string{} + tr := tar.NewReader(&buf) + for { + hdr, err := tr.Next() + if err == io.EOF { + break + } + if err != nil { + t.Fatalf("tar.Next: %v", err) + } + body, _ := io.ReadAll(tr) + got[hdr.Name] = string(body) + if !hdr.ModTime.Equal(time.Unix(0, 0)) { + t.Errorf("%s: ModTime not epoch", hdr.Name) + } + } + want := map[string]string{"file.txt": "hello", ".dockerfile.abc": "FROM alpine\n"} + if !reflect.DeepEqual(got, want) { + t.Errorf("entries = %v, want %v", got, want) + } +} diff --git a/runtime/runtime.go b/runtime/runtime.go index cea9c02..b9c323e 100644 --- a/runtime/runtime.go +++ b/runtime/runtime.go @@ -471,13 +471,15 @@ const ( // BuildSpec is the input to BuildImage. type BuildSpec struct { ContextPath string - Dockerfile string - Tag string - Args map[string]string - Target string - CacheFrom []string - NoCache bool - Platform string + // Dockerfile is relative to ContextPath (empty means "Dockerfile") + // or an absolute host path, which may lie outside ContextPath. + Dockerfile string + Tag string + Args map[string]string + Target string + CacheFrom []string + NoCache bool + Platform string } // TtySize is a pty geometry in character cells. A zero value means diff --git a/test/integration/build_context_symlink_test.go b/test/integration/build_context_symlink_test.go index 1d6e4c8..4cd87ad 100644 --- a/test/integration/build_context_symlink_test.go +++ b/test/integration/build_context_symlink_test.go @@ -53,7 +53,7 @@ RUN echo built > /etc/symlink-build-marker `) mustWrite(t, filepath.Join(dir, ".devcontainer", "devcontainer.json"), `{ - "build": { "dockerfile": "Dockerfile", "context": ".." } + "build": { "dockerfile": "../Dockerfile", "context": ".." } }`) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) diff --git a/test/integration/build_source_test.go b/test/integration/build_source_test.go index c092ba3..16f10fa 100644 --- a/test/integration/build_source_test.go +++ b/test/integration/build_source_test.go @@ -24,15 +24,18 @@ func writeBuildSourceWorkspace(t *testing.T) string { t.Helper() dir := t.TempDir() - // User-provided Dockerfile. - mustWrite(t, filepath.Join(dir, "Dockerfile"), ` + // User-provided Dockerfile beside devcontainer.json, with the repo + // root as the build context: the common layout. Per the spec, + // dockerfile resolves against the devcontainer.json folder, so this + // is .devcontainer/Dockerfile (not /Dockerfile). A root + // file proves the context really is the repo root. + mustWrite(t, filepath.Join(dir, ".devcontainer", "Dockerfile"), ` FROM alpine:3.20 +COPY root.txt /etc/root-marker RUN echo base-image > /etc/build-source-marker `) + mustWrite(t, filepath.Join(dir, "root.txt"), "from-repo-root\n") - // devcontainer.json points to a Dockerfile in the context root, with - // context = ".." so it resolves to the workspace dir (which contains - // Dockerfile). The Dockerfile path itself is relative to that context. mustWrite(t, filepath.Join(dir, ".devcontainer", "devcontainer.json"), `{ "build": { "dockerfile": "Dockerfile", "context": ".." }, "features": { @@ -129,6 +132,50 @@ func TestBuildSource_WithLocalFeature(t *testing.T) { if !strings.Contains(res.Stdout, "yes") { t.Errorf("FEATURE_INSTALLED not applied: stdout=%q", res.Stdout) } + + // COPY read root.txt from the repo-root context. + res, err = eng.Exec(ctx, wsObj, devcontainer.ExecOptions{ + Cmd: []string{"cat", "/etc/root-marker"}, + }) + if err != nil { + t.Fatalf("Exec root-marker: %v", err) + } + if !strings.Contains(res.Stdout, "from-repo-root") { + t.Errorf("root-marker contents = %q (context not the repo root?)", res.Stdout) + } +} + +// TestBuildSource_DockerfileOutsideContext: the Dockerfile sits beside +// devcontainer.json while the context is a sibling folder that doesn't +// contain it. Docker can't open a Dockerfile outside the context tar, +// so the runtime ships it in the tar under a reserved name, as +// `docker build -f` does for the reference CLI. +func TestBuildSource_DockerfileOutsideContext(t *testing.T) { + if testing.Short() { + t.Skip() + } + + eng, rt := newEngine(t) + defer rt.Close() + + dir := t.TempDir() + mustWrite(t, filepath.Join(dir, ".devcontainer", "Dockerfile"), + "FROM "+testImage+"\nCOPY app.txt /etc/app-marker\n") + mustWrite(t, filepath.Join(dir, "app", "app.txt"), "from-app-context\n") + mustWrite(t, filepath.Join(dir, ".devcontainer", "devcontainer.json"), + `{"build": {"dockerfile": "Dockerfile", "context": "../app"}}`) + + ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute) + defer cancel() + + const tag = "dc-go-build-test-outside-context:v1" + if _, err := eng.Build(ctx, devcontainer.BuildOptions{ + LocalWorkspaceFolder: dir, + ImageName: tag, + }); err != nil { + t.Fatalf("Build: %v", err) + } + t.Cleanup(func() { _ = rt.RemoveImage(context.Background(), tag) }) } func TestPrebakedImage_SkipsFeatureRebuild(t *testing.T) { diff --git a/test/integration/build_test.go b/test/integration/build_test.go index 30f2564..61bc61d 100644 --- a/test/integration/build_test.go +++ b/test/integration/build_test.go @@ -130,7 +130,7 @@ func TestEngineBuild_BuildSource_NoFeatures(t *testing.T) { dir := t.TempDir() mustWrite(t, filepath.Join(dir, "Dockerfile"), "FROM "+testImage+"\nRUN echo build-no-features > /etc/marker\n") mustWrite(t, filepath.Join(dir, ".devcontainer", "devcontainer.json"), - `{"build": {"dockerfile": "Dockerfile", "context": ".."}}`) + `{"build": {"dockerfile": "../Dockerfile", "context": ".."}}`) ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute) defer cancel() @@ -169,7 +169,7 @@ func TestEngineBuild_BuildSource_SyntaxDirective(t *testing.T) { "RUN --mount=type=tmpfs,target=/scratch hello > /etc/marker\n") mustWrite(t, filepath.Join(dir, "hello.sh"), "#!/bin/sh\necho syntax-directive\n") mustWrite(t, filepath.Join(dir, ".devcontainer", "devcontainer.json"), - `{"build": {"dockerfile": "Dockerfile", "context": ".."}}`) + `{"build": {"dockerfile": "../Dockerfile", "context": ".."}}`) ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute) defer cancel() diff --git a/test/integration/buildkit_trace_events_test.go b/test/integration/buildkit_trace_events_test.go index ff24c8a..d01bdc6 100644 --- a/test/integration/buildkit_trace_events_test.go +++ b/test/integration/buildkit_trace_events_test.go @@ -43,7 +43,7 @@ FROM alpine:3.20 RUN echo %s `, marker)) mustWrite(t, filepath.Join(dir, ".devcontainer", "devcontainer.json"), `{ - "build": { "dockerfile": "Dockerfile", "context": ".." } + "build": { "dockerfile": "../Dockerfile", "context": ".." } }`) evCh := make(chan events.Event, 1024) diff --git a/test/integration/userenvprobe_test.go b/test/integration/userenvprobe_test.go index 9ba6e55..c05b19c 100644 --- a/test/integration/userenvprobe_test.go +++ b/test/integration/userenvprobe_test.go @@ -84,7 +84,7 @@ RUN mkdir -p /opt/mytool/bin /etc/profile.d \ && printf 'export PATH=/opt/mytool/bin:$PATH\n' > /etc/profile.d/mytool.sh `) mustWrite(t, filepath.Join(dir, ".devcontainer", "devcontainer.json"), `{ - "build": { "dockerfile": "Dockerfile", "context": ".." }, + "build": { "dockerfile": "../Dockerfile", "context": ".." }, "postCreateCommand": "command -v mytool && mytool > /tmp/lifecycle-out" }`) ws := dir