-
Notifications
You must be signed in to change notification settings - Fork 250
/
indexeddockerimage.go
49 lines (43 loc) · 1.23 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
package d2g
import (
"encoding/json"
"fmt"
"path/filepath"
"strings"
"github.com/taskcluster/taskcluster/v59/tools/d2g/genericworker"
)
func (idi *IndexedDockerImage) FileMounts() ([]genericworker.FileMount, error) {
indexedContent := genericworker.IndexedContent{
Artifact: idi.Path,
Namespace: idi.Namespace,
}
raw, err := json.MarshalIndent(&indexedContent, "", " ")
if err != nil {
return nil, fmt.Errorf("cannot marshal indexed content %#v into json: %w", indexedContent, err)
}
return []genericworker.FileMount{
{
Content: json.RawMessage(raw),
// Instead of trying to preserve the artifact filename, we use a
// hardcoded name to prevent filename collisions.
// This _may_ cause issues once concurrent tasks are supported
// on generic worker (see https://bugzil.la/1609102).
File: "dockerimage",
Format: fileExtension(idi.Path),
},
}, nil
}
func (idi *IndexedDockerImage) String() (string, error) {
return "docker-archive:dockerimage", nil
}
func fileExtension(path string) string {
extensionFormats := map[string]string{
".bz2": "bz2",
".gz": "gz",
".lz4": "lz4",
".xz": "xz",
".zst": "zst",
}
lowerExt := strings.ToLower(filepath.Ext(path))
return extensionFormats[lowerExt]
}