Add make.go support for building the camlistored Docker binary.

Change-Id: I2f8ad914b217843749c0aee57c24ce44c1c619f1
This commit is contained in:
Brad Fitzpatrick 2014-08-16 14:56:40 -07:00
parent d36efd7434
commit 274f838f6f
2 changed files with 31 additions and 4 deletions

31
make.go
View File

@ -60,6 +60,7 @@ var (
ifModsSince = flag.Int64("if_mods_since", 0, "If non-zero return immediately without building if there aren't any filesystem modifications past this time (in unix seconds)")
buildARCH = flag.String("arch", runtime.GOARCH, "Architecture to build for.")
buildOS = flag.String("os", runtime.GOOS, "Operating system to build for.")
dockerMode = flag.Bool("docker_camlistored", false, "If true, only build camlistored suitable for a Linux Docker image.")
)
var (
@ -79,6 +80,17 @@ func main() {
verifyGoVersion()
if *dockerMode {
if *sqlFlag != "auto" || *targets != "" {
log.Fatalf("Incompatible set of flags with --docker_camlistored")
}
*targets = "camlistore.org/server/camlistored"
*buildOS = "linux"
*buildARCH = "amd64"
*sqlFlag = "false"
*all = true
}
sql := withSQLite()
if useEnvGoPath, _ := strconv.ParseBool(os.Getenv("CAMLI_MAKE_USEGOPATH")); useEnvGoPath {
*useGoPath = true
@ -170,9 +182,12 @@ func main() {
if *race {
baseArgs = append(baseArgs, "-race")
}
baseArgs = append(baseArgs,
"--ldflags=-X camlistore.org/pkg/buildinfo.GitInfo "+version,
"--tags="+tags)
ldFlags := "-X camlistore.org/pkg/buildinfo.GitInfo " + version
if *dockerMode {
tags = "netgo"
ldFlags = "-w " + ldFlags
}
baseArgs = append(baseArgs, "--ldflags="+ldFlags, "--tags="+tags)
// First install command: build just the final binaries, installed to a GOBIN
// under <camlistore_root>/bin:
@ -191,6 +206,12 @@ func main() {
cmd.Env = append(cleanGoEnv(),
"GOPATH="+buildGoPath,
)
if *dockerMode {
cmd.Env = append(cmd.Env,
"GOBIN="+filepath.Join(camRoot, "misc", "docker", "camlistored"),
"CGO_ENABLED=0",
)
}
var output bytes.Buffer
if *quiet {
cmd.Stdout = &output
@ -205,6 +226,10 @@ func main() {
if err := cmd.Run(); err != nil {
log.Fatalf("Error building main binaries: %v\n%s", err, output.String())
}
if *dockerMode {
log.Printf("Wrote docker camlistored binary to misc/docker/camlistored")
return
}
// Copy the binaries from $CAMROOT/tmp/build-gopath-foo/bin to $CAMROOT/bin.
// This is necessary (instead of just using GOBIN environment variable) so

View File

@ -1,8 +1,10 @@
docker: Dockerfile camlistored
docker build -t camlistore/camlistored .
.PHONY: camlistored
camlistored:
CGO_ENABLED=0 GOOS=linux go build -a -tags netgo -ldflags '-w' -o camlistored camlistore.org/server/camlistored
(cd ../../../; go run make.go --docker_camlistored)
push: docker
docker push camlistore/camlistored