github.com/turbot/steampipe@v1.7.0-rc.0.0.20240517123944-7cef272d4458/pkg/ociinstaller/assets.go (about) 1 package ociinstaller 2 3 import ( 4 "context" 5 "fmt" 6 "log" 7 "path/filepath" 8 9 "github.com/turbot/steampipe/pkg/constants" 10 "github.com/turbot/steampipe/pkg/filepaths" 11 ) 12 13 // InstallAssets installs the Steampipe report server assets 14 func InstallAssets(ctx context.Context, assetsLocation string) error { 15 tempDir := NewTempDir(assetsLocation) 16 defer func() { 17 if err := tempDir.Delete(); err != nil { 18 log.Printf("[TRACE] Failed to delete temp dir '%s' after installing assets: %s", tempDir, err) 19 } 20 }() 21 22 // download the blobs 23 imageDownloader := NewOciDownloader() 24 image, err := imageDownloader.Download(ctx, NewSteampipeImageRef(constants.DashboardAssetsImageRef), ImageTypeAssets, tempDir.Path) 25 if err != nil { 26 return err 27 } 28 29 // install the files 30 if err = installAssetsFiles(image, tempDir.Path, assetsLocation); err != nil { 31 return err 32 } 33 34 return nil 35 } 36 37 func installAssetsFiles(image *SteampipeImage, tempdir string, dest string) error { 38 fileName := image.Assets.ReportUI 39 sourcePath := filepath.Join(tempdir, fileName) 40 if err := moveFolderWithinPartition(sourcePath, filepaths.EnsureDashboardAssetsDir()); err != nil { 41 return fmt.Errorf("could not install %s to %s", sourcePath, filepaths.EnsureDashboardAssetsDir()) 42 } 43 return nil 44 }