forked from taskcluster/taskcluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindexeddockerimage.go
59 lines (50 loc) · 1.51 KB
/
indexeddockerimage.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package d2g
import (
"fmt"
"path/filepath"
"strings"
"github.com/taskcluster/shell"
"github.com/taskcluster/taskcluster/v54/tools/d2g/genericworker"
)
func (idi *IndexedDockerImage) PrepareCommands() []string {
findArtifactURL := fmt.Sprintf("${TASKCLUSTER_PROXY_URL}/index/v1/task/%s/artifacts/%s", idi.Namespace, idi.Path)
filename := filepath.Base(idi.Path)
commands := []string{
fmt.Sprintf(`curl -fsSL -o %s "%s"`, filename, findArtifactURL),
}
handleFileExtentions(filename, &commands)
return commands
}
func (idi *IndexedDockerImage) FileMounts() ([]genericworker.FileMount, error) {
return []genericworker.FileMount{}, nil
}
func (idi *IndexedDockerImage) String() (string, error) {
return `"${IMAGE_NAME}"`, nil
}
func handleFileExtentions(filename string, commands *[]string) {
switch lowerExt := strings.ToLower(filepath.Ext(filename)); lowerExt {
case ".lz4":
*commands = append(
*commands,
// TODO handle spaces in file name
"unlz4 "+shell.Escape(filename),
// TODO handle spaces in file name
"rm "+shell.Escape(filename),
)
filename = filename[:len(filename)-len(lowerExt)]
case ".zst":
*commands = append(
*commands,
// TODO handle spaces in file name
"unzstd "+shell.Escape(filename),
// TODO handle spaces in file name
"rm "+shell.Escape(filename),
)
filename = filename[:len(filename)-len(lowerExt)]
}
*commands = append(
*commands,
// TODO handle spaces in file name
"IMAGE_NAME=$(podman load -i "+shell.Escape(filename)+" | sed -n 's/.*: //p')",
)
}