Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .nextchanges/air/images-push-workdir-warning.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Warn in `databricks air images push` when the source image sets `WORKDIR`, so commands and scripts use absolute paths. ([#7867](https://github.com/databricks/cli/pull/7867))
5 changes: 3 additions & 2 deletions acceptance/air/image-push/docker
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ case "$1 $2" in
printf 'Docker inspect failed\n' >&2
exit 1
;;
arm64) printf 'linux/arm64\n' ;;
*) printf 'linux/amd64\n' ;;
arm64) printf 'linux/arm64|\n' ;;
workdir) printf 'linux/amd64|/app\n' ;;
*) printf 'linux/amd64|\n' ;;
esac
;;
pull\ *)
Expand Down
34 changes: 27 additions & 7 deletions acceptance/air/image-push/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Now you can set `environment.unity_catalog_image = my-catalog.my-schema.cuda:13.

=== docker commands
image ls --quiet nvidia/cuda:13.4.1
image inspect --format {{.Os}}/{{.Architecture}} nvidia/cuda:13.4.1
image inspect --format {{.Os}}/{{.Architecture}}|{{.Config.WorkingDir}} nvidia/cuda:13.4.1
tag nvidia/cuda:13.4.1 [WORKSPACE_ID].container.us-west-2.localhost/my-catalog.my-schema.cuda:13.4.1-cudnn-devel-ubuntu26.04
push [WORKSPACE_ID].container.us-west-2.localhost/my-catalog.my-schema.cuda:13.4.1-cudnn-devel-ubuntu26.04

Expand Down Expand Up @@ -75,6 +75,22 @@ Pushed image.
}
}

=== image with WORKDIR warns but is pushed

>>> databricks air images push -p docker-test -s example/image:v1 --catalog main --schema training
Warning: This feature is in Preview. APIs may change, and the workspace must enable the Preview features.
Pushing example/image:v1 as main.training.image:v1 using profile docker-test
Configured Docker credential helper for [WORKSPACE_ID].container.us-west-2.localhost
Updated Docker config: [TEST_TMP_DIR]/home/docker/config.json
Installed Docker credential helper: [TEST_TMP_DIR]/home/bin/docker-credential-databricks
Using local source image example/image:v1
Warning: source image example/image:v1 sets WORKDIR /app; use absolute paths in your command and scripts.
Tagging image as [WORKSPACE_ID].container.us-west-2.localhost/main.training.image:v1
Pushing image to [WORKSPACE_ID].container.us-west-2.localhost/main.training.image:v1
Docker push progress
Pushed image.
Now you can set `environment.unity_catalog_image = main.training.image:v1` in your YAML config and create a workload with `databricks air run -f config.yaml`.

=== daemon failure must not pull

>>> musterr databricks air images push -p docker-test -s example/image:v1 --catalog main --schema training
Expand Down Expand Up @@ -193,25 +209,29 @@ Error: invalid image repository name: catalog.schema.artifact must be 255 charac

=== all docker commands
image ls --quiet nvidia/cuda:13.4.1
image inspect --format {{.Os}}/{{.Architecture}} nvidia/cuda:13.4.1
image inspect --format {{.Os}}/{{.Architecture}}|{{.Config.WorkingDir}} nvidia/cuda:13.4.1
tag nvidia/cuda:13.4.1 [WORKSPACE_ID].container.us-west-2.localhost/my-catalog.my-schema.cuda:13.4.1-cudnn-devel-ubuntu26.04
push [WORKSPACE_ID].container.us-west-2.localhost/my-catalog.my-schema.cuda:13.4.1-cudnn-devel-ubuntu26.04
image ls --quiet example/image:v1
pull --platform linux/amd64 example/image:v1
image inspect --format {{.Os}}/{{.Architecture}} example/image:v1
image inspect --format {{.Os}}/{{.Architecture}}|{{.Config.WorkingDir}} example/image:v1
tag example/image:v1 [WORKSPACE_ID].container.us-west-2.localhost/main.training.image:v1
push [WORKSPACE_ID].container.us-west-2.localhost/main.training.image:v1
pull --platform linux/amd64 example/image:v1
image inspect --format {{.Os}}/{{.Architecture}} example/image:v1
image inspect --format {{.Os}}/{{.Architecture}}|{{.Config.WorkingDir}} example/image:v1
tag example/image:v1 [WORKSPACE_ID].container.us-west-2.localhost/main.training.image:v1
push [WORKSPACE_ID].container.us-west-2.localhost/main.training.image:v1
image ls --quiet example/image:v1
image inspect --format {{.Os}}/{{.Architecture}}|{{.Config.WorkingDir}} example/image:v1
tag example/image:v1 [WORKSPACE_ID].container.us-west-2.localhost/main.training.image:v1
push [WORKSPACE_ID].container.us-west-2.localhost/main.training.image:v1
image ls --quiet example/image:v1
image ls --quiet example/image:v1
image inspect --format {{.Os}}/{{.Architecture}} example/image:v1
image inspect --format {{.Os}}/{{.Architecture}}|{{.Config.WorkingDir}} example/image:v1
image ls --quiet example/image:v1
image inspect --format {{.Os}}/{{.Architecture}} example/image:v1
image inspect --format {{.Os}}/{{.Architecture}}|{{.Config.WorkingDir}} example/image:v1
pull --platform linux/amd64 example/image:v1
image inspect --format {{.Os}}/{{.Architecture}} example/image:v1
image inspect --format {{.Os}}/{{.Architecture}}|{{.Config.WorkingDir}} example/image:v1
pull --platform linux/amd64 example/image:v1

=== in a Claude Code session the auth docker configure child adds no install hint
Expand Down
4 changes: 4 additions & 0 deletions acceptance/air/image-push/script
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ trace databricks air images push -p docker-test -s example/image:v1 --catalog ma
# Parsing the complete stdout fails if Docker progress or human-readable text leaks into it.
trace jq -e '{v, data}' "$HOME/result.json"

title "image with WORKDIR warns but is pushed"
export DOCKER_TEST_MODE=workdir
trace databricks air images push -p docker-test -s example/image:v1 --catalog main --schema training

title "daemon failure must not pull"
export DOCKER_TEST_MODE=daemon-error
trace musterr databricks air images push -p docker-test -s example/image:v1 --catalog main --schema training
Expand Down
13 changes: 9 additions & 4 deletions cmd/air/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,17 @@ func runImagePush(cmd *cobra.Command, opts *imagePushOptions, deps imagePushDeps
cmdio.LogString(ctx, "Using local source image "+resolved.source)
}

var platform bytes.Buffer
if err := deps.runCommand(ctx, nil, &platform, cmd.ErrOrStderr(), dockerPath, "image", "inspect", "--format", "{{.Os}}/{{.Architecture}}", resolved.source); err != nil {
var inspected bytes.Buffer
if err := deps.runCommand(ctx, nil, &inspected, cmd.ErrOrStderr(), dockerPath, "image", "inspect", "--format", "{{.Os}}/{{.Architecture}}|{{.Config.WorkingDir}}", resolved.source); err != nil {
return fmt.Errorf("inspect source image %s: %w", resolved.source, err)
}
if got := strings.TrimSpace(platform.String()); got != airImagePlatform {
return fmt.Errorf("source image %s has platform %q; AIR requires %s: use --pull to fetch a compatible image, or rebuild the source for %s", resolved.source, got, airImagePlatform, airImagePlatform)
platform, workingDir, _ := strings.Cut(strings.TrimSpace(inspected.String()), "|")
if platform != airImagePlatform {
return fmt.Errorf("source image %s has platform %q; AIR requires %s: use --pull to fetch a compatible image, or rebuild the source for %s", resolved.source, platform, airImagePlatform, airImagePlatform)
}
// / is Docker's default WORKDIR and cannot break relative paths.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[nit] The condition below skips both an empty WorkingDir (no WORKDIR in the image) and /, but the comment only mentions /. Its claim that / "cannot break relative paths" is about where AI Runtime starts the process, which the PR says the CLI doesn't know. Something like "Skip the warning when WORKDIR is unset or /: docker run starts in / for both, so relative paths are least likely to depend on it" would say what is actually decided.

if workingDir != "" && workingDir != "/" {
cmdio.LogString(ctx, fmt.Sprintf("Warning: source image %s sets WORKDIR %s; use absolute paths in your command and scripts.", resolved.source, workingDir))
}

cmdio.LogProgress(ctx, "Tagging image as "+target)
Expand Down
57 changes: 54 additions & 3 deletions cmd/air/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestRunImagePushTagsAndPushesLocalImage(t *testing.T) {
_, err := io.WriteString(out, "image-id\n")
return err
case "image inspect":
_, err := io.WriteString(out, "linux/amd64\n")
_, err := io.WriteString(out, "linux/amd64|\n")
return err
}
return nil
Expand All @@ -74,7 +74,7 @@ func TestRunImagePushTagsAndPushesLocalImage(t *testing.T) {
target := "123.container.us-west-2.cloud.databricks.test/main.training.cuda:13.4.1"
assert.Equal(t, []recordedImageCommand{
{executable: "/usr/bin/docker", args: []string{"image", "ls", "--quiet", "nvidia/cuda:13.4.1"}},
{executable: "/usr/bin/docker", args: []string{"image", "inspect", "--format", "{{.Os}}/{{.Architecture}}", "nvidia/cuda:13.4.1"}},
{executable: "/usr/bin/docker", args: []string{"image", "inspect", "--format", "{{.Os}}/{{.Architecture}}|{{.Config.WorkingDir}}", "nvidia/cuda:13.4.1"}},
{executable: "/usr/bin/docker", args: []string{"tag", "nvidia/cuda:13.4.1", target}},
{executable: "/usr/bin/docker", args: []string{"push", target}},
}, commands)
Expand All @@ -85,6 +85,57 @@ func TestRunImagePushTagsAndPushesLocalImage(t *testing.T) {
stderrLines := strings.Split(stderr.String(), "\n")
assert.Equal(t, "Warning: This feature is in Preview. APIs may change, and the workspace must enable the Preview features.", stderrLines[0])
assert.Contains(t, stderr.String(), "Pushed image")
assert.NotContains(t, stderr.String(), "WORKDIR")
}

func TestRunImagePushWarnsWhenImageSetsWorkingDir(t *testing.T) {
tests := []struct {
name string
workingDir string
warn bool
}{
{name: "unset", workingDir: ""},
{name: "root", workingDir: "/"},
{name: "set", workingDir: "/app", warn: true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cmd, _, stderr := newImagePushTestCommand(t, "workspace")
deps := imagePushDeps{
configureDocker: func(context.Context, string) (string, error) {
return "123.container.us-west-2.cloud.databricks.test", nil
},
lookPath: func(string) (string, error) { return "docker", nil },
runCommand: func(_ context.Context, _ io.Reader, out, _ io.Writer, _ string, args ...string) error {
switch strings.Join(args[:2], " ") {
case "image ls":
_, err := io.WriteString(out, "image-id\n")
return err
case "image inspect":
_, err := io.WriteString(out, "linux/amd64|"+tt.workingDir+"\n")
return err
}
return nil
},
}

err := runImagePush(cmd, &imagePushOptions{
source: "example/trainer:v1",
catalog: "main",
schema: "training",
artifact: "trainer",
}, deps)
require.NoError(t, err)

warning := "Warning: source image example/trainer:v1 sets WORKDIR /app; use absolute paths in your command and scripts."
if tt.warn {
assert.Contains(t, stderr.String(), warning)
} else {
assert.NotContains(t, stderr.String(), "WORKDIR")
}
assert.Contains(t, stderr.String(), "Pushed image")
})
}
}

func TestRegistryHostFromDockerConfigureOutput(t *testing.T) {
Expand All @@ -111,7 +162,7 @@ func TestRunImagePushPullsMissingImage(t *testing.T) {
runCommand: func(_ context.Context, _ io.Reader, out, _ io.Writer, executable string, args ...string) error {
commands = append(commands, recordedImageCommand{executable: executable, args: args})
if args[0] == "image" && args[1] == "inspect" {
_, err := io.WriteString(out, "linux/amd64\n")
_, err := io.WriteString(out, "linux/amd64|\n")
return err

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[nice to have] TestRunImagePushWarnsWhenImageSetsWorkingDir checks user-visible stderr by stubbing configureDocker, lookPath and every runCommand call. .agents/rules/testing.md points that kind of test at acceptance tests. Its set and unset cases already appear in acceptance/air/image-push: the new workdir mode shows the warning, and the default mode's golden output has none. Only the / case is new coverage. Could you add a / mode to the fake docker script (e.g. printf 'linux/amd64|/\n') and drop this test, or cut it down to the / case? The same applies to the NotContains("WORKDIR") assertion at line 163.

}
return nil
Expand Down
Loading