@@ -14,7 +14,9 @@ import (
1414 "go.bug.st/f"
1515
1616 "github.com/bcmi-labs/orchestrator/internal/orchestrator/app"
17+ "github.com/bcmi-labs/orchestrator/internal/orchestrator/bricksindex"
1718 "github.com/bcmi-labs/orchestrator/internal/orchestrator/config"
19+ "github.com/bcmi-labs/orchestrator/internal/orchestrator/modelsindex"
1820)
1921
2022func TestCloneApp (t * testing.T ) {
@@ -355,7 +357,7 @@ func createApp(
355357 isExample bool ,
356358 idProvider * app.IDProvider ,
357359 cfg config.Configuration ,
358- ) {
360+ ) app. ID {
359361 t .Helper ()
360362
361363 res , err := CreateApp (t .Context (), CreateAppRequest {
@@ -371,7 +373,10 @@ func createApp(
371373 newID , err := idProvider .IDFromPath (newPath )
372374 require .NoError (t , err )
373375 assert .Empty (t , gCmp .Diff (f .Must (idProvider .ParseID ("examples:" + name )), newID ))
376+ res .ID = newID
374377 }
378+
379+ return res .ID
375380}
376381
377382func TestSortV4LVideoDevices (t * testing.T ) {
@@ -387,3 +392,88 @@ func TestSortV4LVideoDevices(t *testing.T) {
387392 assert .Equal (t , "usb-Generic_GENERAL_-_UVC-video-index1" , devices [1 ])
388393 assert .Equal (t , "usb-046d_0825-video-index2" , devices [2 ])
389394}
395+
396+ func TestGetAppEnvironmentVariablesWithDefaults (t * testing.T ) {
397+ cfg := setTestOrchestratorConfig (t )
398+ idProvider := app .NewAppIDProvider (cfg )
399+
400+ docker , err := dockerClient .NewClientWithOpts (
401+ dockerClient .FromEnv ,
402+ dockerClient .WithAPIVersionNegotiation (),
403+ )
404+ require .NoError (t , err )
405+ dockerCli , err := command .NewDockerCli (
406+ command .WithAPIClient (docker ),
407+ command .WithBaseContext (t .Context ()),
408+ )
409+ require .NoError (t , err )
410+
411+ err = dockerCli .Initialize (& flags.ClientOptions {})
412+ require .NoError (t , err )
413+
414+ appId := createApp (t , "app1" , false , idProvider , cfg )
415+ appDesc , err := app .Load (appId .ToPath ().String ())
416+ require .NoError (t , err )
417+ appDesc .Descriptor .Bricks = []app.Brick {
418+ {
419+ ID : "arduino:object_detection" ,
420+ Model : "" , // use the default model
421+ Variables : map [string ]string {}, // use the default variables
422+ },
423+ }
424+
425+ bricksIndexContent := []byte (`
426+ bricks:
427+ - id: arduino:object_detection
428+ name: Object Detection
429+ description: "Brick for object detection using a pre-trained model. It processes\
430+ \ images and returns the predicted class label, bounding-boxes and confidence\
431+ \ score.\nBrick is designed to work with pre-trained models provided by framework\
432+ \ or with custom object detection models trained on Edge Impulse platform. \n"
433+ require_container: true
434+ require_model: true
435+ require_devices: false
436+ ports: []
437+ category: video
438+ model_name: yolox-object-detection
439+ variables:
440+ - name: CUSTOM_MODEL_PATH
441+ default_value: /home/arduino/.arduino-bricks/ei-models
442+ description: path to the custom model directory
443+ - name: EI_OBJ_DETECTION_MODEL
444+ default_value: /models/ootb/ei/yolo-x-nano.eim
445+ description: path to the model file
446+ ` )
447+ err = cfg .AssetsDir ().Join ("bricks-list.yaml" ).WriteFile (bricksIndexContent )
448+ require .NoError (t , err )
449+ bricksIndex , err := bricksindex .GenerateBricksIndexFromFile (cfg .AssetsDir ())
450+ assert .NoError (t , err )
451+
452+ modelsIndexContent := []byte (`
453+ models:
454+ - yolox-object-detection:
455+ runner: brick
456+ name : "General purpose object detection - YoloX"
457+ description: "General purpose object detection model based on YoloX Nano. This model is trained on the COCO dataset and can detect 80 different object classes."
458+ model_configuration:
459+ "EI_OBJ_DETECTION_MODEL": "/models/ootb/ei/yolo-x-nano.eim"
460+ metadata:
461+ source: "edgeimpulse"
462+ ei-project-id: 717280
463+ source-model-id: "YOLOX-Nano"
464+ source-model-url: "https://github.com/Megvii-BaseDetection/YOLOX"
465+ bricks:
466+ - arduino:object_detection
467+ - arduino:video_object_detection
468+ ` )
469+ err = cfg .AssetsDir ().Join ("models-list.yaml" ).WriteFile (modelsIndexContent )
470+ require .NoError (t , err )
471+ modelIndex , err := modelsindex .GenerateModelsIndexFromFile (cfg .AssetsDir ())
472+ require .NoError (t , err )
473+
474+ env := getAppEnvironmentVariables (appDesc , bricksIndex , modelIndex )
475+ require .Equal (t , cfg .AppsDir ().Join ("app1" ).String (), env ["APP_HOME" ])
476+ require .Equal (t , "/models/ootb/ei/yolo-x-nano.eim" , env ["EI_OBJ_DETECTION_MODEL" ])
477+ require .Equal (t , "/home/arduino/.arduino-bricks/ei-models" , env ["CUSTOM_MODEL_PATH" ])
478+ // we ignore HOST_IP since it's dynamic
479+ }
0 commit comments