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-size-limit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Print the source image size in `databricks air images push`, and after the push the compressed size and layer count from the pushed manifest, with a link to the Databricks Artifact Registry image limits. ([#7868](https://github.com/databricks/cli/pull/7868))
16 changes: 14 additions & 2 deletions acceptance/air/image-push/docker
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,18 @@ 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|7140000000\n' ;;
bad-size) printf 'linux/amd64|\n' ;;
*) printf 'linux/amd64|7140000000\n' ;;
esac
;;
"manifest inspect")
if [ "$DOCKER_TEST_MODE" = bad-size ]; then
printf 'no such manifest: %s\n' "$4" >&2
exit 1
fi
printf '{"Descriptor":{"platform":{"architecture":"amd64","os":"linux"}},"OCIManifest":{"layers":[{"size":2900000000},{"size":240000000}]}}\n'
;;
pull\ *)
if [ "$DOCKER_TEST_MODE" = pull-error ]; then
printf 'Docker pull failed\n' >&2
Expand All @@ -33,6 +41,10 @@ case "$1 $2" in
exit 0
;;
push\ *)
if [ "$DOCKER_TEST_MODE" = push-error ]; then
printf 'denied: image exceeds the registry size limit\n' >&2
exit 1
fi
printf 'Docker push progress\n'
;;
*)
Expand Down
73 changes: 66 additions & 7 deletions acceptance/air/image-push/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ Configured Docker credential helper for [WORKSPACE_ID].container.us-west-2.local
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 nvidia/cuda:13.4.1
Source image nvidia/cuda:13.4.1 is 7.1 GB uncompressed.
Tagging image as [WORKSPACE_ID].container.us-west-2.localhost/my-catalog.my-schema.cuda:13.4.1-cudnn-devel-ubuntu26.04
Pushing image to [WORKSPACE_ID].container.us-west-2.localhost/my-catalog.my-schema.cuda:13.4.1-cudnn-devel-ubuntu26.04
Docker push progress
Pushed image.
Compressed image size: 3.1 GB in 2 layers.
For Databricks Artifact Registry image limits, see https://docs.databricks.com/aws/en/artifact-registry/#limitations
Now you can set `environment.unity_catalog_image = my-catalog.my-schema.cuda:13.4.1-cudnn-devel-ubuntu26.04` in your YAML config and create a workload with `databricks air run -f config.yaml`.

=== inferred region and workspace ID requests
Expand All @@ -31,9 +34,10 @@ 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}}|{{.Size}} 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
manifest inspect --verbose [WORKSPACE_ID].container.us-west-2.localhost/my-catalog.my-schema.cuda:13.4.1-cudnn-devel-ubuntu26.04

=== missing image is pulled for AIR; destination defaults to source

Expand All @@ -45,10 +49,13 @@ Updated Docker config: [TEST_TMP_DIR]/home/docker/config.json
Installed Docker credential helper: [TEST_TMP_DIR]/home/bin/docker-credential-databricks
Pulling source image example/image:v1 for linux/amd64
Docker pull progress
Source image example/image:v1 is 7.1 GB uncompressed.
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.
Compressed image size: 3.1 GB in 2 layers.
For Databricks Artifact Registry image limits, see https://docs.databricks.com/aws/en/artifact-registry/#limitations
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`.

=== forced pull and JSON output
Expand All @@ -61,10 +68,13 @@ Updated Docker config: [TEST_TMP_DIR]/home/docker/config.json
Installed Docker credential helper: [TEST_TMP_DIR]/home/bin/docker-credential-databricks
Pulling source image example/image:v1 for linux/amd64
Docker pull progress
Source image example/image:v1 is 7.1 GB uncompressed.
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.
Compressed image size: 3.1 GB in 2 layers.
For Databricks Artifact Registry image limits, see https://docs.databricks.com/aws/en/artifact-registry/#limitations

>>> jq -e {v, data} [TEST_TMP_DIR]/home/result.json
{
Expand Down Expand Up @@ -98,6 +108,24 @@ Using local source image example/image:v1
Docker inspect failed
Error: inspect source image example/image:v1: exit status 1

=== unreadable image sizes warn but the image 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: could not read the uncompressed size of source image example/image:v1 (got "").
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.
Warning: could not read the compressed size of [WORKSPACE_ID].container.us-west-2.localhost/main.training.image:v1: no such manifest: [WORKSPACE_ID].container.us-west-2.localhost/main.training.image:v1
For Databricks Artifact Registry image limits, see https://docs.databricks.com/aws/en/artifact-registry/#limitations
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`.

=== incompatible local image must not be pushed

>>> musterr databricks air images push -p docker-test -s example/image:v1 --catalog main --schema training
Expand All @@ -121,6 +149,22 @@ Pulling source image example/image:v1 for linux/amd64
Docker pull progress
Error: source image example/image:v1 has platform "linux/arm64"; AIR requires linux/amd64: use --pull to fetch a compatible image, or rebuild the source for linux/amd64

=== rejected push still links the registry limits

>>> musterr 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
Source image example/image:v1 is 7.1 GB uncompressed.
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
denied: image exceeds the registry size limit
For Databricks Artifact Registry image limits, see https://docs.databricks.com/aws/en/artifact-registry/#limitations
Error: push image [WORKSPACE_ID].container.us-west-2.localhost/main.training.image:v1: exit status 1

=== pull failure must not be pushed

>>> musterr databricks air images push -p docker-test -s example/image:v1 --catalog main --schema training --pull
Expand Down Expand Up @@ -193,25 +237,37 @@ 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}}|{{.Size}} 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
manifest inspect --verbose [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}}|{{.Size}} 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
manifest inspect --verbose [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}}|{{.Size}} 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
manifest inspect --verbose [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}}|{{.Size}} example/image:v1
image ls --quiet example/image:v1
image inspect --format {{.Os}}/{{.Architecture}} example/image:v1
image inspect --format {{.Os}}/{{.Architecture}}|{{.Size}} 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
manifest inspect --verbose [WORKSPACE_ID].container.us-west-2.localhost/main.training.image:v1
image ls --quiet example/image:v1
image inspect --format {{.Os}}/{{.Architecture}} example/image:v1
image inspect --format {{.Os}}/{{.Architecture}}|{{.Size}} example/image:v1
pull --platform linux/amd64 example/image:v1
image inspect --format {{.Os}}/{{.Architecture}} example/image:v1
image inspect --format {{.Os}}/{{.Architecture}}|{{.Size}} example/image:v1
image ls --quiet example/image:v1
image inspect --format {{.Os}}/{{.Architecture}}|{{.Size}} 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

=== in a Claude Code session the auth docker configure child adds no install hint
Expand All @@ -225,10 +281,13 @@ Configured Docker credential helper for [WORKSPACE_ID].container.us-west-2.local
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
Source image example/image:v1 is 7.1 GB uncompressed.
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.
Compressed image size: 3.1 GB in 2 layers.
For Databricks Artifact Registry image limits, see https://docs.databricks.com/aws/en/artifact-registry/#limitations
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`.

>>> musterr databricks air images push -p pat-test -s example/image:v1 --catalog main --schema training
Expand Down
8 changes: 8 additions & 0 deletions acceptance/air/image-push/script
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,21 @@ title "inspect failure must not pull"
export DOCKER_TEST_MODE=inspect-error
trace musterr databricks air images push -p docker-test -s example/image:v1 --catalog main --schema training

title "unreadable image sizes warn but the image is pushed"
export DOCKER_TEST_MODE=bad-size
trace databricks air images push -p docker-test -s example/image:v1 --catalog main --schema training

title "incompatible local image must not be pushed"
export DOCKER_TEST_MODE=arm64
trace musterr databricks air images push -p docker-test -s example/image:v1 --catalog main --schema training

title "incompatible pulled image must not be pushed"
trace musterr databricks air images push -p docker-test -s example/image:v1 --catalog main --schema training --pull

title "rejected push still links the registry limits"
export DOCKER_TEST_MODE=push-error
trace musterr databricks air images push -p docker-test -s example/image:v1 --catalog main --schema training

title "pull failure must not be pushed"
export DOCKER_TEST_MODE=pull-error
trace musterr databricks air images push -p docker-test -s example/image:v1 --catalog main --schema training --pull
Expand Down
116 changes: 112 additions & 4 deletions cmd/air/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package aircmd
import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"os"
"os/exec"
"regexp"
"strconv"
"strings"
"sync"

Expand All @@ -17,6 +19,7 @@ import (
"github.com/databricks/cli/libs/cmdctx"
"github.com/databricks/cli/libs/cmdio"
"github.com/databricks/cli/libs/flags"
"github.com/databricks/databricks-sdk-go/config"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -154,6 +157,99 @@ The destination --artifact ARTIFACT[:TAG] defaults to the source image name and
return cmd
}

// formatImageSize renders a byte count in decimal MB or GB, the units docker images uses.
func formatImageSize(sizeBytes int64) string {
if sizeBytes < 1e9 {
Comment thread
vinchenzo-db marked this conversation as resolved.
Resolved
Comment thread
vinchenzo-db marked this conversation as resolved.
Resolved
Comment thread
vinchenzo-db marked this conversation as resolved.
Resolved
return fmt.Sprintf("%.1f MB", float64(sizeBytes)/1e6)
}
return fmt.Sprintf("%.1f GB", float64(sizeBytes)/1e9)
}

// logCompressedImageSize prints the compressed size and layer count from the pushed manifest of the
// given platform. The registry stores compressed layers; the local image store only knows the uncompressed size.
func logCompressedImageSize(ctx context.Context, deps imagePushDeps, dockerPath, target, platform string) {
var manifest, errOut bytes.Buffer
if err := deps.runCommand(ctx, nil, &manifest, &errOut, dockerPath, "manifest", "inspect", "--verbose", target); err != nil {
detail, _, _ := strings.Cut(strings.TrimSpace(errOut.String()), "\n")
if detail == "" {
detail = err.Error()
}
cmdio.LogString(ctx, fmt.Sprintf("Warning: could not read the compressed size of %s: %s", target, detail))
return
}
sizeBytes, layers, err := compressedImageSize(manifest.Bytes(), platform)
if err != nil {
cmdio.LogString(ctx, fmt.Sprintf("Warning: could not read the compressed size of %s: %v", target, err))
return
}
cmdio.LogString(ctx, fmt.Sprintf("Compressed image size: %s in %d layers.", formatImageSize(sizeBytes), layers))
Comment thread
vinchenzo-db marked this conversation as resolved.
Resolved
Comment thread
vinchenzo-db marked this conversation as resolved.
Resolved
}

type manifestLayers struct {
Layers []struct {
Size int64 `json:"size"`
} `json:"layers"`
}

type verboseManifest struct {
Descriptor struct {
Platform *struct {
OS string `json:"os"`
Architecture string `json:"architecture"`
} `json:"platform"`
}
SchemaV2Manifest *manifestLayers
OCIManifest *manifestLayers
}

// compressedImageSize sums the layer sizes in `docker manifest inspect --verbose` output. That
// output is one object for an image manifest and an array for an index, whose entry for platform is used.
func compressedImageSize(output []byte, platform string) (int64, int, error) {
output = bytes.TrimSpace(output)
var entries []verboseManifest
if bytes.HasPrefix(output, []byte("[")) {
if err := json.Unmarshal(output, &entries); err != nil {
return 0, 0, err
}
} else {
var entry verboseManifest
if err := json.Unmarshal(output, &entry); err != nil {
return 0, 0, err
}
entries = []verboseManifest{entry}
}
for _, e := range entries {
if p := e.Descriptor.Platform; p != nil && p.OS+"/"+p.Architecture != platform {
continue
}
m := e.OCIManifest
if m == nil {
m = e.SchemaV2Manifest
}
if m == nil || len(m.Layers) == 0 {
continue
}
var sizeBytes int64
for _, l := range m.Layers {
sizeBytes += l.Size
}
return sizeBytes, len(m.Layers), nil
}
return 0, 0, fmt.Errorf("no %s image manifest with layers", platform)
}

// darLimitationsURL returns the DAR limitations docs for the workspace's cloud.
func darLimitationsURL(cfg *config.Config) string {
switch {
case cfg.IsAzure():
return "https://learn.microsoft.com/azure/databricks/artifact-registry/#limitations"
case cfg.IsGcp():
return "https://docs.databricks.com/gcp/en/artifact-registry/#limitations"
default:
return "https://docs.databricks.com/aws/en/artifact-registry/#limitations"
}
}

// runImagePush validates inputs, prepares a compatible source image, and pushes it to DAR.
func runImagePush(cmd *cobra.Command, opts *imagePushOptions, deps imagePushDeps) error {
ctx := cmd.Context()
Expand Down Expand Up @@ -198,24 +294,36 @@ 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}}|{{.Size}}", 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, size, _ := 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)
}
// Sizes are informational only: a size that can't be read never blocks the push.
if sizeBytes, err := strconv.ParseInt(size, 10, 64); err == nil {
cmdio.LogString(ctx, fmt.Sprintf("Source image %s is %s uncompressed.", resolved.source, formatImageSize(sizeBytes)))
} else {
Comment thread
vinchenzo-db marked this conversation as resolved.
Resolved
cmdio.LogString(ctx, fmt.Sprintf("Warning: could not read the uncompressed size of source image %s (got %q).", resolved.source, size))
}

cmdio.LogProgress(ctx, "Tagging image as "+target)
if err := deps.runCommand(ctx, cmd.InOrStdin(), cmd.ErrOrStderr(), cmd.ErrOrStderr(), dockerPath, "tag", resolved.source, target); err != nil {
return fmt.Errorf("tag source image %s: %w", resolved.source, err)
}
// DAR sets and may change its own limits, so the CLI links them instead of enforcing one.
limitsLink := "For Databricks Artifact Registry image limits, see " + darLimitationsURL(w.Config)
cmdio.LogProgress(ctx, "Pushing image to "+target)
if err := deps.runCommand(ctx, cmd.InOrStdin(), cmd.ErrOrStderr(), cmd.ErrOrStderr(), dockerPath, "push", target); err != nil {
cmdio.LogString(ctx, limitsLink)
return fmt.Errorf("push image %s: %w", target, err)
}

cmdio.LogString(ctx, "Pushed image.")
logCompressedImageSize(ctx, deps, dockerPath, target, platform)
cmdio.LogString(ctx, limitsLink)
if root.OutputType(cmd) == flags.OutputJSON {
return renderEnvelope(ctx, struct {
UnityCatalogImage string `json:"unity_catalog_image"`
Expand Down
Loading
Loading