forked from ForAllSecure/rootfs_builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
42 lines (39 loc) · 950 Bytes
/
main.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
package main
import (
"os"
"github.com/ForAllSecure/rootfs_builder/log"
"github.com/ForAllSecure/rootfs_builder/rootfs"
)
func main() {
if len(os.Args) > 3 || len(os.Args) < 2 {
log.Fatal("Usage: rootfs_builder <config.json>\n" +
"\t\t\t\t\t--digest-only: only print the digest")
}
// Initialize pullable image from config
pullableImage, err := rootfs.NewPullableImage(os.Args[1])
if err != nil {
log.Errorf("Failed to initialize image from config: %+v", err)
os.Exit(1)
}
pulledImage, err := pullableImage.Pull()
if err != nil {
log.Errorf("Failed to pull image: %+v", err)
os.Exit(1)
}
// Extract rootfs
if len(os.Args) == 2 {
err = pulledImage.Extract()
if err != nil {
log.Errorf("Failed to extract rootfs: %+v", err)
os.Exit(1)
}
} else {
// Digest only
digest, err := pulledImage.Digest()
if err != nil {
log.Errorf("Failed to get digest: %+v", err)
os.Exit(1)
}
log.Info(digest)
}
}