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