Save git version in lightning binary collection name and properties.
authorTom Clegg <tom@tomclegg.ca>
Tue, 8 Dec 2020 15:34:07 +0000 (10:34 -0500)
committerTom Clegg <tom@tomclegg.ca>
Tue, 8 Dec 2020 15:34:07 +0000 (10:34 -0500)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@tomclegg.ca>

Makefile [new file with mode: 0644]
arvados.go
version.sh [new file with mode: 0755]

diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..62f4e54
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,4 @@
+GOPATH?=$(HOME)/go
+.PHONY: $(GOPATH)/bin/lightning
+$(GOPATH)/bin/lightning:
+       go install -ldflags "-X git.arvados.org/arvados.git/lib/cmd.version=$(shell ./version.sh)"
index a79160d78546cd364aded15290ef63817ce039f9..f2819d01ef2c8ced3b4e30f0076bfa42aa3fa49c 100644 (file)
@@ -14,6 +14,7 @@ import (
        "sync"
        "time"
 
+       "git.arvados.org/arvados.git/lib/cmd"
        "git.arvados.org/arvados.git/sdk/go/arvados"
        "git.arvados.org/arvados.git/sdk/go/arvadosclient"
        "git.arvados.org/arvados.git/sdk/go/keepclient"
@@ -399,7 +400,7 @@ func (runner *arvadosContainerRunner) makeCommandCollection() (string, error) {
                return "", err
        }
        b2 := blake2b.Sum256(exe)
-       cname := fmt.Sprintf("lightning-%x", b2)
+       cname := "lightning " + cmd.Version.String() // must build with "make", not just "go install"
        var existing arvados.CollectionList
        err = runner.Client.RequestAndDecode(&existing, "GET", "arvados/v1/collections", nil, arvados.ListOptions{
                Limit: 1,
@@ -407,15 +408,16 @@ func (runner *arvadosContainerRunner) makeCommandCollection() (string, error) {
                Filters: []arvados.Filter{
                        {Attr: "name", Operator: "=", Operand: cname},
                        {Attr: "owner_uuid", Operator: "=", Operand: runner.ProjectUUID},
+                       {Attr: "properties.blake2b", Operator: "=", Operand: fmt.Sprintf("%x", b2)},
                },
        })
        if err != nil {
                return "", err
        }
        if len(existing.Items) > 0 {
-               uuid := existing.Items[0].UUID
-               log.Printf("using lightning binary in existing collection %s (name is %q; did not verify whether content matches)", uuid, cname)
-               return uuid, nil
+               coll := existing.Items[0]
+               log.Printf("using lightning binary in existing collection %s (name is %q, hash is %q; did not verify whether content matches)", coll.UUID, cname, coll.Properties["blake2b"])
+               return coll.UUID, nil
        }
        log.Printf("writing lightning binary to new collection %q", cname)
        ac, err := arvadosclient.New(runner.Client)
@@ -449,6 +451,9 @@ func (runner *arvadosContainerRunner) makeCommandCollection() (string, error) {
                        "owner_uuid":    runner.ProjectUUID,
                        "manifest_text": mtxt,
                        "name":          cname,
+                       "properties": map[string]interface{}{
+                               "blake2b": fmt.Sprintf("%x", b2),
+                       },
                },
        })
        if err != nil {
diff --git a/version.sh b/version.sh
new file mode 100755 (executable)
index 0000000..d17f361
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/bash
+set -e -o pipefail
+echo -n "0.0.0"
+echo -n "+$(git log -n1 --format=%h)"
+if [[ -n "$(git status -s)" || -n "$(git diff)" || -n "$(git diff --cached)" ]]; then
+    echo -n "-$(TZ=UTC date +%Y%m%d%H%M%S)"
+fi