mirror of https://github.com/perkeep/perkeep.git
Merge "misc/docker: stamp version as well to binaries"
This commit is contained in:
commit
1d7df7ceb4
2
make.go
2
make.go
|
@ -186,7 +186,7 @@ func main() {
|
|||
}
|
||||
var ldFlags string
|
||||
if *stampVersion {
|
||||
ldFlags = "-X camlistore.org/pkg/buildinfo.GitInfo=" + version
|
||||
ldFlags = "-X \"camlistore.org/pkg/buildinfo.GitInfo=" + version + "\""
|
||||
}
|
||||
baseArgs = append(baseArgs, "--ldflags="+ldFlags, "--tags="+strings.Join(tags, " "))
|
||||
|
||||
|
|
|
@ -114,10 +114,9 @@ func genCamlistore(ctxDir string) {
|
|||
"--volume=" + ctxDir + "/camlistore.org:/OUT",
|
||||
"--volume=" + path.Join(dockDir, "server/build-camlistore-server.go") + ":" + genCamliProgram + ":ro",
|
||||
}
|
||||
// TODO(mpl, bradfitz): pass the version to genCamliProgram so it can stamp it into camlistored when building it.
|
||||
if isWIP() {
|
||||
args = append(args, "--volume="+localCamliSource()+":/IN:ro",
|
||||
goDockerImage, goCmd, "run", genCamliProgram, "--rev="+rev(), "--camlisource=/IN")
|
||||
goDockerImage, goCmd, "run", genCamliProgram, "--rev=WIP:/IN")
|
||||
} else {
|
||||
args = append(args, goDockerImage, goCmd, "run", genCamliProgram, "--rev="+rev())
|
||||
}
|
||||
|
@ -140,10 +139,13 @@ func genBinaries(ctxDir string) {
|
|||
}
|
||||
if isWIP() {
|
||||
args = append(args, "--volume="+localCamliSource()+":/IN:ro",
|
||||
image, goCmd, "run", genBinariesProgram, "--rev="+rev(), "--camlisource=/IN", "--os="+*buildOS)
|
||||
image, goCmd, "run", genBinariesProgram, "--rev=WIP:/IN", "--os="+*buildOS)
|
||||
} else {
|
||||
args = append(args, image, goCmd, "run", genBinariesProgram, "--rev="+rev(), "--os="+*buildOS)
|
||||
}
|
||||
if *flagVersion != "" {
|
||||
args = append(args, "--version="+*flagVersion)
|
||||
}
|
||||
cmd := exec.Command("docker", args...)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
|
|
|
@ -31,19 +31,20 @@ import (
|
|||
"os/exec"
|
||||
"path"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
rev = flag.String("rev", "", "Camlistore revision to build (tag or commit hash)")
|
||||
localSrc = flag.String("camlisource", "", "(dev flag) Path to a local Camlistore source tree from which to build. It is ignored unless -rev=WORKINPROGRESS")
|
||||
outDir = flag.String("outdir", "/OUT/", "Output directory, where the binaries will be written")
|
||||
buildOS = flag.String("os", runtime.GOOS, "Operating system to build for.")
|
||||
flagRev = flag.String("rev", "", "Camlistore revision to build (tag or commit hash). For development purposes, you can instead specify the path to a local Camlistore source tree from which to build, with the form \"WIP:/path/to/dir\".")
|
||||
flagVersion = flag.String("version", "", "The optional version number (e.g. 0.9) that will be stamped into the binaries, in addition to the revision.")
|
||||
outDir = flag.String("outdir", "/OUT/", "Output directory, where the binaries will be written")
|
||||
buildOS = flag.String("os", runtime.GOOS, "Operating system to build for.")
|
||||
)
|
||||
|
||||
func usage() {
|
||||
fmt.Fprintf(os.Stderr, "Usage:\n")
|
||||
fmt.Fprintf(os.Stderr, "%s --rev=camlistore_revision\n", os.Args[0])
|
||||
fmt.Fprintf(os.Stderr, "%s --rev=WORKINPROGRESS --camlisource=/path/to/camli/source/dir\n", os.Args[0])
|
||||
fmt.Fprintf(os.Stderr, "%s --rev=WIP:/path/to/camli/source/dir\n", os.Args[0])
|
||||
flag.PrintDefaults()
|
||||
example(os.Args[0])
|
||||
os.Exit(1)
|
||||
|
@ -52,23 +53,47 @@ func usage() {
|
|||
func example(program string) {
|
||||
fmt.Fprintf(os.Stderr, "Examples:\n")
|
||||
fmt.Fprintf(os.Stderr, "\tdocker run --rm --volume=/tmp/camli-build/camlistore.org:/OUT camlistore/go %s --rev=4e8413c5012c\n", program)
|
||||
fmt.Fprintf(os.Stderr, "\tdocker run --rm --volume=/tmp/camli-build/camlistore.org:/OUT --volume=~/camlistore.org:/IN camlistore/go %s --rev=WORKINPROGRESS --camlisource=/IN\n", program)
|
||||
fmt.Fprintf(os.Stderr, "\tdocker run --rm --volume=/tmp/camli-build/camlistore.org:/OUT --volume=~/camlistore.org:/IN camlistore/go %s --rev=WIP:/IN\n", program)
|
||||
}
|
||||
|
||||
func isWIP() bool {
|
||||
return strings.HasPrefix(*flagRev, "WIP")
|
||||
}
|
||||
|
||||
// localCamliSource returns the path to the local Camlistore source tree
|
||||
// that should be specified in *flagRev if *flagRev starts with "WIP:",
|
||||
// empty string otherwise.
|
||||
func localCamliSource() string {
|
||||
if !isWIP() {
|
||||
return ""
|
||||
}
|
||||
return strings.TrimPrefix(*flagRev, "WIP:")
|
||||
}
|
||||
|
||||
func rev() string {
|
||||
if isWIP() {
|
||||
return "WORKINPROGRESS"
|
||||
}
|
||||
return *flagRev
|
||||
}
|
||||
|
||||
func version() string {
|
||||
if *flagVersion != "" {
|
||||
return fmt.Sprintf("%v (git rev %v)", *flagVersion, rev())
|
||||
}
|
||||
return rev()
|
||||
}
|
||||
|
||||
func getCamliSrc() {
|
||||
if *localSrc != "" {
|
||||
mirrorCamliSrc(*localSrc)
|
||||
if localCamliSource() != "" {
|
||||
mirrorCamliSrc(localCamliSource())
|
||||
} else {
|
||||
fetchCamliSrc()
|
||||
}
|
||||
// if missing, we insert a VERSION FILE, so make.go does no need git in the container to detect the Camlistore version.
|
||||
// we insert the version in the VERSION file, so make.go does no need git
|
||||
// in the container to detect the Camlistore version.
|
||||
check(os.Chdir("/gopath/src/camlistore.org"))
|
||||
if _, err := os.Stat("VERSION"); err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
log.Fatal(err)
|
||||
}
|
||||
check(ioutil.WriteFile("VERSION", []byte(*rev), 0777))
|
||||
}
|
||||
check(ioutil.WriteFile("VERSION", []byte(version()), 0777))
|
||||
}
|
||||
|
||||
func mirrorCamliSrc(srcDir string) {
|
||||
|
@ -85,7 +110,7 @@ func fetchCamliSrc() {
|
|||
check(os.MkdirAll("/gopath/src/camlistore.org", 0777))
|
||||
check(os.Chdir("/gopath/src/camlistore.org"))
|
||||
|
||||
res, err := http.Get("https://camlistore.googlesource.com/camlistore/+archive/" + *rev + ".tar.gz")
|
||||
res, err := http.Get("https://camlistore.googlesource.com/camlistore/+archive/" + *flagRev + ".tar.gz")
|
||||
check(err)
|
||||
defer res.Body.Close()
|
||||
gz, err := gzip.NewReader(res.Body)
|
||||
|
@ -142,17 +167,8 @@ func checkArgs() {
|
|||
if flag.NArg() != 0 {
|
||||
usage()
|
||||
}
|
||||
if *rev == "" {
|
||||
usage()
|
||||
}
|
||||
if *rev == "WORKINPROGRESS" {
|
||||
if *localSrc == "" {
|
||||
usage()
|
||||
}
|
||||
return
|
||||
}
|
||||
if *localSrc != "" {
|
||||
fmt.Fprintf(os.Stderr, "Usage error: --camlisource can only be used with --rev WORKINPROGRESS.\n")
|
||||
if *flagRev == "" {
|
||||
fmt.Fprintf(os.Stderr, "Usage error: --rev is required.\n")
|
||||
usage()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,16 +35,14 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
// TODO(mpl): make the flags the same as in dock.go
|
||||
rev = flag.String("rev", "", "Camlistore revision to build (tag or commit hash)")
|
||||
localSrc = flag.String("camlisource", "", "(dev flag) Path to a local Camlistore source tree from which to build. It is ignored unless -rev=WORKINPROGRESS")
|
||||
outDir = flag.String("outdir", "/OUT/", "Output directory, where camlistored and all the resources will be written")
|
||||
flagRev = flag.String("rev", "", "Camlistore revision to build (tag or commit hash). For development purposes, you can instead specify the path to a local Camlistore source tree from which to build, with the form \"WIP:/path/to/dir\".")
|
||||
outDir = flag.String("outdir", "/OUT/", "Output directory, where camlistored and all the resources will be written")
|
||||
)
|
||||
|
||||
func usage() {
|
||||
fmt.Fprintf(os.Stderr, "Usage:\n")
|
||||
fmt.Fprintf(os.Stderr, "%s --rev=camlistore_revision\n", os.Args[0])
|
||||
fmt.Fprintf(os.Stderr, "%s --rev=WORKINPROGRESS --camlisource=/path/to/camli/source/dir\n", os.Args[0])
|
||||
fmt.Fprintf(os.Stderr, "%s --rev=WIP:/path/to/camli/source/dir\n", os.Args[0])
|
||||
flag.PrintDefaults()
|
||||
example(os.Args[0])
|
||||
os.Exit(1)
|
||||
|
@ -53,12 +51,33 @@ func usage() {
|
|||
func example(program string) {
|
||||
fmt.Fprintf(os.Stderr, "Examples:\n")
|
||||
fmt.Fprintf(os.Stderr, "\tdocker run --rm --volume=/tmp/camli-build/camlistore.org:/OUT camlistore/go %s --rev=4e8413c5012c\n", program)
|
||||
fmt.Fprintf(os.Stderr, "\tdocker run --rm --volume=/tmp/camli-build/camlistore.org:/OUT --volume=~/camlistore.org:/IN camlistore/go %s --rev=WORKINPROGRESS --camlisource=/IN\n", program)
|
||||
fmt.Fprintf(os.Stderr, "\tdocker run --rm --volume=/tmp/camli-build/camlistore.org:/OUT --volume=~/camlistore.org:/IN camlistore/go %s --rev=WIP:/IN\n", program)
|
||||
}
|
||||
|
||||
func isWIP() bool {
|
||||
return strings.HasPrefix(*flagRev, "WIP")
|
||||
}
|
||||
|
||||
// localCamliSource returns the path to the local Camlistore source tree
|
||||
// that should be specified in *flagRev if *flagRev starts with "WIP:",
|
||||
// empty string otherwise.
|
||||
func localCamliSource() string {
|
||||
if !isWIP() {
|
||||
return ""
|
||||
}
|
||||
return strings.TrimPrefix(*flagRev, "WIP:")
|
||||
}
|
||||
|
||||
func rev() string {
|
||||
if isWIP() {
|
||||
return "WORKINPROGRESS"
|
||||
}
|
||||
return *flagRev
|
||||
}
|
||||
|
||||
func getCamliSrc() {
|
||||
if *localSrc != "" {
|
||||
mirrorCamliSrc(*localSrc)
|
||||
if localCamliSource() != "" {
|
||||
mirrorCamliSrc(localCamliSource())
|
||||
return
|
||||
}
|
||||
fetchCamliSrc()
|
||||
|
@ -78,7 +97,7 @@ func fetchCamliSrc() {
|
|||
check(os.MkdirAll("/gopath/src/camlistore.org", 0777))
|
||||
check(os.Chdir("/gopath/src/camlistore.org"))
|
||||
|
||||
res, err := http.Get("https://camlistore.googlesource.com/camlistore/+archive/" + *rev + ".tar.gz")
|
||||
res, err := http.Get("https://camlistore.googlesource.com/camlistore/+archive/" + *flagRev + ".tar.gz")
|
||||
check(err)
|
||||
defer res.Body.Close()
|
||||
gz, err := gzip.NewReader(res.Body)
|
||||
|
@ -116,10 +135,9 @@ func buildCamlistored() {
|
|||
os.Setenv("PATH", "/usr/local/go/bin:"+oldPath)
|
||||
os.Setenv("CGO_ENABLED", "0")
|
||||
os.Setenv("GO15VENDOREXPERIMENT", "1")
|
||||
// TODO(mpl, bradfitz): stamp the 0.9 version here with ldflags if a version was passed as a flag to the program.
|
||||
cmd := exec.Command("go", "build",
|
||||
"-o", path.Join(*outDir, "/bin/camlistored"),
|
||||
`--ldflags`, "-w -d -linkmode internal -X camlistore.org/pkg/buildinfo.GitInfo="+*rev,
|
||||
`--ldflags`, "-w -d -linkmode internal -X camlistore.org/pkg/buildinfo.GitInfo="+rev(),
|
||||
"--tags=netgo", "camlistore.org/server/camlistored")
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
|
@ -157,17 +175,8 @@ func checkArgs() {
|
|||
if flag.NArg() != 0 {
|
||||
usage()
|
||||
}
|
||||
if *rev == "" {
|
||||
usage()
|
||||
}
|
||||
if *rev == "WORKINPROGRESS" {
|
||||
if *localSrc == "" {
|
||||
usage()
|
||||
}
|
||||
return
|
||||
}
|
||||
if *localSrc != "" {
|
||||
fmt.Fprintf(os.Stderr, "Usage error: --camlisource can only be used with --rev WORKINPROGRESS.\n")
|
||||
if *flagRev == "" {
|
||||
fmt.Fprintf(os.Stderr, "Usage error: --rev is required.\n")
|
||||
usage()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue