diff --git a/make.go b/make.go index bf5547548..ebd9407e1 100644 --- a/make.go +++ b/make.go @@ -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 /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 diff --git a/misc/docker/camlistored/Makefile b/misc/docker/camlistored/Makefile index 6a40996bc..fc7e3dc79 100644 --- a/misc/docker/camlistored/Makefile +++ b/misc/docker/camlistored/Makefile @@ -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