-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
71 lines (56 loc) · 1.53 KB
/
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"flag"
"log"
)
func main() {
pImage := flag.String("image", "", "the user specified os base image")
pConfig := flag.String("config", "", "the yaml config")
pOut := flag.String("output", "disk.img", "the output bootable disk image")
pDebug := flag.Bool("debug", false, "enable debug message")
layoutFile := flag.String("diskLayout", "", "disk partitions layout, if not provided use the default")
flag.Parse()
if *pImage == "" && *pConfig == "" {
log.Printf("Error: should specify either -image or -config")
flag.Usage()
}
if *pImage == "" {
config, _ := getConfigFromFile(*pConfig)
log.Printf("config %#v\n", config)
imageId, err := BuildImageFromConfig(config)
if err != nil {
log.Fatalf("Fail to create image %s with built-in setup\n", err)
}
*pImage = imageId
}
log.Printf("[Info] Create boot image from docker image %s\n", *pImage)
var layout *DiskLayout
if *layoutFile != "" {
layout = parseDisklayout(*layoutFile)
} else {
layout = NewDefaultLayout()
}
if err := layout.validate(); err != nil {
log.Fatalf("invalid paritions setting %s", err)
}
const GB = 1024 * 1024 * 1024
// output disk
disk := Disk{
Name: *pOut,
Size: 2 * GB,
}
// build the imgage from the config
outTar, err := UnpackDockerImage(*pImage)
if err != nil {
log.Fatalf("Fail to unpack docker image %s\n", err)
}
// root filesystem content
content := &[]Content{
{
source: outTar,
sourceType: "tar",
destDir: "/",
},
}
CreateBootableImage(disk, layout, content, *pDebug)
}