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/bundles/app-thumbnail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Add `thumbnail_path` to the `apps` resource, so `bundle deploy` sets, updates and deletes the thumbnail shown for the app in the Apps UI. ([#7728](https://github.com/databricks/cli/pull/7728))
3 changes: 3 additions & 0 deletions acceptance/bundle/refschema/output/apps.txt
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ resources.apps.*.telemetry_export_destinations[*].unity_catalog *apps.UnityCatal
resources.apps.*.telemetry_export_destinations[*].unity_catalog.logs_table string ALL
resources.apps.*.telemetry_export_destinations[*].unity_catalog.metrics_table string ALL
resources.apps.*.telemetry_export_destinations[*].unity_catalog.traces_table string ALL
resources.apps.*.thumbnail string STATE
resources.apps.*.thumbnail_content string INPUT
resources.apps.*.thumbnail_path string INPUT
resources.apps.*.thumbnail_url string ALL
resources.apps.*.update_time string ALL
resources.apps.*.updater string ALL
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
bundle:
name: test-bundle

resources:
apps:
myapp:
name: myappname
source_code_path: .
thumbnail_path: $THUMBNAIL_PATH
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Cloud = false
EnvMatrix.DMS = ["", "true"]
48 changes: 48 additions & 0 deletions acceptance/bundle/resources/apps/thumbnail-invalid/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

=== thumbnail_path: ./thumbnail.gif

>>> [CLI] bundle validate
Error: app thumbnail thumbnail.gif must be a PNG or JPEG image, got image/gif
in databricks.yml:9:23

Name: test-bundle
Target: default
Workspace:
User: [USERNAME]
Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default

Found 1 error

Exit code: 1

=== thumbnail_path: ./large.png

>>> [CLI] bundle validate
Error: app thumbnail large.png is 250001 bytes, larger than the limit of 250000 bytes
in databricks.yml:9:23

Name: test-bundle
Target: default
Workspace:
User: [USERNAME]
Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default

Found 1 error

Exit code: 1

=== thumbnail_path: ./missing.png

>>> [CLI] bundle validate
Error: failed to read app thumbnail missing.png: open missing.png: no such file or directory
in databricks.yml:9:23

Name: test-bundle
Target: default
Workspace:
User: [USERNAME]
Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default

Found 1 error

Exit code: 1
9 changes: 9 additions & 0 deletions acceptance/bundle/resources/apps/thumbnail-invalid/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# One byte over the 250,000-byte limit, with a PNG signature.
python3 -c "import sys; sys.stdout.buffer.write(b'\x89PNG\r\n\x1a\n' + bytes(250_001 - 8))" > large.png

for THUMBNAIL_PATH in ./thumbnail.gif ./large.png ./missing.png; do
title "thumbnail_path: $THUMBNAIL_PATH"
export THUMBNAIL_PATH
envsubst < databricks.yml.tmpl > databricks.yml
errcode trace $CLI bundle validate
done
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
RecordRequests = false
Ignore = ["large.png"]

[[Repls]]
Old = 'The system cannot find the file specified.'
New = 'no such file or directory'
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
bundle:
name: test-bundle

resources:
apps:
mykey:
name: myappname
source_code_path: .
thumbnail_path: ./thumbnail.png
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Cloud = false
EnvMatrix.DMS = ["", "true"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

=== A failed upload after create keeps the app in state and leaves the thumbnail out of it

>>> [CLI] bundle deploy
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files...
Warning: failed to upload the thumbnail of app myappname, the next deploy retries it: Unsupported image
Created apps.mykey
Files: 2 uploaded, 0 deleted
Resources: 1 created, 0 changed, 0 deleted, 0 unchanged

>>> jq .state["resources.apps.mykey"].state.thumbnail .databricks/bundle/default/resources.json
null

=== The next deploy retries the upload

>>> [CLI] bundle plan
update apps.mykey

Plan: 0 to add, 1 to change, 0 to delete, 0 unchanged

>>> [CLI] bundle deploy
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files...
Error: cannot update resources.apps.mykey: updating id=myappname: Unsupported image (400 INVALID_PARAMETER_VALUE)

Endpoint: PATCH [DATABRICKS_URL]/api/2.0/apps/myappname/thumbnail
HTTP Status: 400 Bad Request
API error_code: INVALID_PARAMETER_VALUE
API message: Unsupported image

Files: 0 uploaded, 0 deleted

Exit code: 1

>>> [CLI] bundle destroy --auto-approve
The following resources will be deleted:
delete resources.apps.mykey

All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default

Destroy: 1 deleted
12 changes: 12 additions & 0 deletions acceptance/bundle/resources/apps/thumbnail-upload-fails/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cleanup() {
trace $CLI bundle destroy --auto-approve
}
trap cleanup EXIT

title "A failed upload after create keeps the app in state and leaves the thumbnail out of it"
trace $CLI bundle deploy
trace jq '.state["resources.apps.mykey"].state.thumbnail' .databricks/bundle/default/resources.json

title "The next deploy retries the upload"
trace $CLI bundle plan
errcode trace $CLI bundle deploy
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
RecordRequests = false
Ignore = [".databricks"]

[[Server]]
Pattern = "PATCH /api/2.0/apps/{name}/thumbnail"
Response.StatusCode = 400
Response.Body = '''{"error_code": "INVALID_PARAMETER_VALUE", "message": "Unsupported image"}'''
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions acceptance/bundle/resources/apps/thumbnail/app/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("Hello world!")
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions acceptance/bundle/resources/apps/thumbnail/databricks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
bundle:
name: test-bundle

resources:
apps:
mykey:
name: myappname
source_code_path: ./app
thumbnail_path: ./thumbnail.png
37 changes: 37 additions & 0 deletions acceptance/bundle/resources/apps/thumbnail/out.requests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"method": "POST",
"path": "/api/2.0/apps",
"q": {
"no_compute": "true"
},
"body": {
"description": "",
"name": "myappname"
}
}
{
"method": "PATCH",
"path": "/api/2.0/apps/myappname/thumbnail",
"body": {
"app_thumbnail": {
"thumbnail": "iVBORw0KGgoAAAANSUhEUgAAACAAAAASCAIAAAC1qksFAAAAHklEQVR42mNgYPhPYzRqwagFoxaMWjBqwagFdLAAAM9QPd+sTeHpAAAAAElFTkSuQmCC"
}
}
}
{
"method": "PATCH",
"path": "/api/2.0/apps/myappname/thumbnail",
"body": {
"app_thumbnail": {
"thumbnail": "iVBORw0KGgoAAAANSUhEUgAAACAAAAASCAIAAAC1qksFAAAAH0lEQVR42mP4z8BAU8QwasGoBaMWjFowasGoBfSwAABLGz3fTe+jHwAAAABJRU5ErkJggg=="
}
}
}
{
"method": "DELETE",
"path": "/api/2.0/apps/myappname/thumbnail"
}
{
"method": "DELETE",
"path": "/api/2.0/apps/myappname"
}
2 changes: 2 additions & 0 deletions acceptance/bundle/resources/apps/thumbnail/out.test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Cloud = false
EnvMatrix.DMS = ["", "true"]
84 changes: 84 additions & 0 deletions acceptance/bundle/resources/apps/thumbnail/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@

=== Deploy with a thumbnail: the image is uploaded after the app is created

>>> [CLI] bundle deploy
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files...
Created apps.mykey
Files: 5 uploaded, 0 deleted
Resources: 1 created, 0 changed, 0 deleted, 0 unchanged

>>> print_requests

>>> [CLI] apps get myappname
"/ajax-api/2.0/thumbnails/raw/apps/1000/SMALL_DEFAULT.png"

=== State keeps only a hash of the image

>>> jq .state["resources.apps.mykey"].state.thumbnail .databricks/bundle/default/resources.json
"sha256:[HASH]"

=== Redeploy with an unchanged image: no thumbnail request

>>> [CLI] bundle plan
Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged

>>> [CLI] bundle deploy
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files...
Files: 1 uploaded, 0 deleted
Resources: 0 created, 0 changed, 0 deleted, 1 unchanged

>>> print_requests

=== New content at the same path: only the thumbnail is uploaded

>>> [CLI] bundle plan
update apps.mykey

Plan: 0 to add, 1 to change, 0 to delete, 0 unchanged

>>> [CLI] bundle deploy
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files...
Updated apps.mykey
Files: 1 uploaded, 0 deleted
Resources: 0 created, 1 changed, 0 deleted, 0 unchanged

>>> print_requests

=== Deploy from a saved plan: the plan carries the image, not its hash

>>> [CLI] bundle deploy --plan tmp.plan.json
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files...
Updated apps.mykey
Files: 3 uploaded, 0 deleted
Resources: 0 created, 1 changed, 0 deleted, 0 unchanged

>>> print_requests.py //apps ^//api/2.0/bundle
iVBORw0KGgoA

=== Remove thumbnail_path: the thumbnail is deleted

>>> [CLI] bundle plan
update apps.mykey

Plan: 0 to add, 1 to change, 0 to delete, 0 unchanged

>>> [CLI] bundle deploy
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files...
Updated apps.mykey
Files: 1 uploaded, 0 deleted
Resources: 0 created, 1 changed, 0 deleted, 0 unchanged

>>> print_requests

>>> [CLI] apps get myappname
null

>>> [CLI] bundle destroy --auto-approve
The following resources will be deleted:
delete resources.apps.mykey

All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default

Destroy: 1 deleted

>>> print_requests
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 44 additions & 0 deletions acceptance/bundle/resources/apps/thumbnail/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
print_requests() {
print_requests.py //apps '^//api/2.0/bundle'
}

cleanup() {
trace $CLI bundle destroy --auto-approve
trace print_requests >> out.requests.json
}
trap cleanup EXIT

cp blue.png thumbnail.png

title "Deploy with a thumbnail: the image is uploaded after the app is created"
trace $CLI bundle deploy
trace print_requests > out.requests.json
trace $CLI apps get myappname | jq .thumbnail_url

title "State keeps only a hash of the image"
trace jq '.state["resources.apps.mykey"].state.thumbnail' .databricks/bundle/default/resources.json

title "Redeploy with an unchanged image: no thumbnail request"
trace $CLI bundle plan
trace $CLI bundle deploy
trace print_requests >> out.requests.json

title "New content at the same path: only the thumbnail is uploaded"
cp red.png thumbnail.png
trace $CLI bundle plan
trace $CLI bundle deploy
trace print_requests >> out.requests.json

title "Deploy from a saved plan: the plan carries the image, not its hash"
cp blue.png thumbnail.png
$CLI bundle plan -o json > tmp.plan.json
trace $CLI bundle deploy --plan tmp.plan.json
trace print_requests.py //apps '^//api/2.0/bundle' | jq -r '.body.app_thumbnail.thumbnail | .[0:12]'

title "Remove thumbnail_path: the thumbnail is deleted"
grep -v thumbnail_path databricks.yml > databricks.yml.new
mv databricks.yml.new databricks.yml
trace $CLI bundle plan
trace $CLI bundle deploy
trace print_requests >> out.requests.json
trace $CLI apps get myappname | jq .thumbnail_url
1 change: 1 addition & 0 deletions acceptance/bundle/resources/apps/thumbnail/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ignore = [".databricks", "thumbnail.png", "databricks.yml.new", "tmp.plan.json"]
18 changes: 16 additions & 2 deletions bundle/config/mutator/paths/app_paths_visitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,28 @@ import (
)

func VisitAppPaths(value dyn.Value, fn VisitFunc) (dyn.Value, error) {
pattern := dyn.NewPattern(
sourceCodePattern := dyn.NewPattern(
dyn.Key("resources"),
dyn.Key("apps"),
dyn.AnyKey(),
dyn.Key("source_code_path"),
)

return dyn.MapByPattern(value, pattern, func(path dyn.Path, value dyn.Value) (dyn.Value, error) {
value, err := dyn.MapByPattern(value, sourceCodePattern, func(path dyn.Path, value dyn.Value) (dyn.Value, error) {
return fn(path, TranslateModeDirectory, value)
})
if err != nil {
return dyn.InvalidValue, err
}

thumbnailPattern := dyn.NewPattern(
dyn.Key("resources"),
dyn.Key("apps"),
dyn.AnyKey(),
dyn.Key("thumbnail_path"),
)

return dyn.MapByPattern(value, thumbnailPattern, func(path dyn.Path, value dyn.Value) (dyn.Value, error) {
return fn(path, TranslateModeLocalRelative, value)
})
}
2 changes: 2 additions & 0 deletions bundle/config/mutator/paths/app_paths_visitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func TestAppPathsVisitor(t *testing.T) {
App: apps.App{
SourceCodePath: "foo",
},
ThumbnailPath: "thumbnail.png",
},
},
},
Expand All @@ -26,6 +27,7 @@ func TestAppPathsVisitor(t *testing.T) {
actual := collectVisitedPaths(t, root, VisitAppPaths)
expected := []dyn.Path{
dyn.MustPathFromString("resources.apps.app0.source_code_path"),
dyn.MustPathFromString("resources.apps.app0.thumbnail_path"),
}

assert.ElementsMatch(t, expected, actual)
Expand Down
Loading
Loading