-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
build.go
68 lines (55 loc) · 1.33 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 (
"os"
"os/exec"
"path"
"strings"
"github.com/rafecolton/docker-builder/conf"
"github.com/winchman/builder-core"
"github.com/winchman/builder-core/unit-config"
"github.com/codegangsta/cli"
"github.com/onsi/gocleanup"
)
func build(c *cli.Context) {
builderfile := c.Args().First()
if builderfile == "" {
builderfile = "Bobfile"
}
unitConfig, err := unitconfig.ReadFromFile("./" + builderfile)
if err != nil {
if c.Bool("force") {
if err := forceBuild(); err != nil {
Logger.Warn(err.Error())
}
}
gocleanup.Exit(0)
}
globals := unitconfig.ConfigGlobals{
SkipPush: c.Bool("skip-push") || conf.Config.SkipPush,
CfgUn: conf.Config.CfgUn,
CfgPass: conf.Config.CfgPass,
CfgEmail: conf.Config.CfgEmail,
}
unitConfig.SetGlobals(globals)
if err := runner.RunBuildSynchronously(runner.Options{
UnitConfig: unitConfig,
ContextDir: os.Getenv("PWD"),
LogLevel: Logger.Level,
}); err != nil {
exitErr(1, "unable to build", err)
}
}
func forceBuild() error {
pwd, err := os.Getwd()
if err != nil {
return err
}
basename := path.Base(pwd)
args := []string{"docker", "build", "-t", basename, "."}
cmd := exec.Command("docker")
cmd.Args = args
cmd.Stdout = os.Stdout
cmd.Stdin = os.Stdin
Logger.Info("running command --> " + strings.Join(args, " "))
return cmd.Run()
}