-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.go
68 lines (56 loc) · 1.48 KB
/
build.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
package main
import (
"fmt"
"os"
)
type BuildCommand struct {
Type string `short:"t" long:"type" description:"Type of environment."`
Version string `short:"v" long:"version" description:"Version of environment type."`
Image string `short:"i" long:"image" description:"Image to use for creating environment."`
ForcePull bool `long:"force-pull" description:"Force pulling base image."`
TimeZone string `long:"tz" description:"Time zone for container, specify like 'America/Los_Angeles'. Defaults to local time zone, if detectable."`
}
var buildCommand BuildCommand
func (ccommand *BuildCommand) toBuildOpts(sc SystemClient) BuildOpts {
return BuildOpts{
Image: ImageOpts{
Type: ccommand.Type,
Version: ccommand.Version,
Image: ccommand.Image,
},
TimeZone: ccommand.TimeZone,
ForcePull: ccommand.ForcePull,
Username: sc.Username(),
UID: sc.UID(),
GID: sc.GID(),
}
}
func (x *BuildCommand) Execute(args []string) error {
dc, err := NewDockerClient(globalOptions.toConnectOpts())
if err != nil {
return err
}
sc, err := NewSystemClient()
if err != nil {
return err
}
key, err := sc.EnsureSSHKey()
if err != nil {
return err
}
image, err := BuildImage(dc, sc, key, buildCommand.toBuildOpts(sc), os.Stdout)
if err != nil {
return err
}
fmt.Println("Built image: ", image)
return nil
}
func init() {
_, err := parser.AddCommand("build",
"Build an image.",
"",
&buildCommand)
if err != nil {
fmt.Println(err)
}
}