Repository navigation
[AIR] CNXT-2686: warn when a pushed image sets WORKDIR #7867
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
e94fd43
3031cd9
42e16c3
d48fc7f
0f620d5
ec6a35c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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)) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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) | ||
|
|
@@ -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) { | ||
|
|
@@ -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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nice to have] |
||
| } | ||
| return nil | ||
|
|
||
There was a problem hiding this comment.
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(noWORKDIRin 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 runstarts in/for both, so relative paths are least likely to depend on it" would say what is actually decided.