"path/filepath"
"regexp"
"runtime"
+ "runtime/debug"
"sort"
"strings"
// 0.
var Version versionCommand
-var version = "dev"
+var (
+ // These default version/commit strings should be set at build
+ // time: `go install -buildvcs=false -ldflags "-X
+ // git.arvados.org/arvados.git/lib/cmd.version=1.2.3"`
+ version = "dev"
+ commit = "0000000000000000000000000000000000000000"
+)
type versionCommand struct{}
return fmt.Sprintf("%s (%s)", version, runtime.Version())
}
+func (versionCommand) Commit() string {
+ if bi, ok := debug.ReadBuildInfo(); ok {
+ for _, bs := range bi.Settings {
+ if bs.Key == "vcs.revision" {
+ return bs.Value
+ }
+ }
+ }
+ return commit
+}
+
func (versionCommand) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
prog = regexp.MustCompile(` -*version$`).ReplaceAllLiteralString(prog, "")
fmt.Fprintf(stdout, "%s %s (%s)\n", prog, version, runtime.Version())
type installCommand struct {
ClusterType string
SourcePath string
+ Commit string
PackageVersion string
EatMyData bool
}
versionFlag := flags.Bool("version", false, "Write version information to stdout and exit 0")
flags.StringVar(&inst.ClusterType, "type", "production", "cluster `type`: development, test, production, or package")
flags.StringVar(&inst.SourcePath, "source", "/arvados", "source tree location (required for -type=package)")
+ flags.StringVar(&inst.Commit, "commit", "", "source commit `hash` to embed (blank means use 'git log' or all-zero placeholder)")
flags.StringVar(&inst.PackageVersion, "package-version", "0.0.0", "version string to embed in executable files")
flags.BoolVar(&inst.EatMyData, "eatmydata", false, "use eatmydata to speed up install")
return cmd.Version.RunCommand(prog, args, stdin, stdout, stderr)
}
+ if inst.Commit == "" {
+ if commit, err := exec.Command("env", "-C", inst.SourcePath, "git", "log", "-n1", "--format=%H").CombinedOutput(); err == nil {
+ inst.Commit = strings.TrimSpace(string(commit))
+ } else {
+ inst.Commit = "0000000000000000000000000000000000000000"
+ }
+ }
+
var dev, test, prod, pkg bool
switch inst.ClusterType {
case "development":
// container using a non-root-owned git tree
// mounted from the host -- as in
// "arvados-package build".
- cmd := exec.Command("go", "install", "-buildvcs=false", "-ldflags", "-X git.arvados.org/arvados.git/lib/cmd.version="+inst.PackageVersion+" -X main.version="+inst.PackageVersion+" -s -w")
+ cmd := exec.Command("go", "install", "-buildvcs=false",
+ "-ldflags", "-s -w"+
+ " -X git.arvados.org/arvados.git/lib/cmd.version="+inst.PackageVersion+
+ " -X git.arvados.org/arvados.git/lib/cmd.commit="+inst.Commit)
cmd.Env = append(cmd.Env, os.Environ()...)
cmd.Env = append(cmd.Env, "GOBIN=/var/lib/arvados/bin")
cmd.Dir = filepath.Join(inst.SourcePath, srcdir)
// Install workbench2 app to /var/lib/arvados/workbench2/
if err = inst.runBash(`
-cd `+inst.SourcePath+`/services/workbench2
-VERSION="`+inst.PackageVersion+`" BUILD_NUMBER=1 GIT_COMMIT=000000000 yarn build
+cd "`+inst.SourcePath+`/services/workbench2"
+VERSION="`+inst.PackageVersion+`" BUILD_NUMBER=1 GIT_COMMIT="`+inst.Commit[:9]+`" yarn build
rsync -a --delete-after build/ /var/lib/arvados/workbench2/
`, stdout, stderr); err != nil {
return 1