forked from d2iq-archive/cake-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
report.go
47 lines (37 loc) · 968 Bytes
/
report.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
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
)
type BuildReport struct {
Images []ImageBuildSummary
}
type ImageBuildSummary struct {
Id string
StableTag string
PublishedTags []string
}
func generateReport(image *Image, config BuildConfig) error {
var summaries []ImageBuildSummary
walkBuildGraph(image, func(image *Image) {
summary := ImageBuildSummary{
Id: image.ImageConfig.Id,
StableTag: fmt.Sprintf("%s:%s", image.getFullName(), image.getStableTag(config)),
PublishedTags: image.getDockerTags(config),
}
summaries = append(summaries, summary)
})
report := BuildReport{
Images: summaries,
}
reportJson, err := json.Marshal(report)
if err != nil {
return fmt.Errorf("failed to marshall build report to JSON: %v", err)
}
err = ioutil.WriteFile(config.OutputFile, reportJson, 0644)
if err != nil {
return fmt.Errorf("failed to save build report file: %v", err)
}
return nil
}