about summary refs log tree commit diff
path: root/tools
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2019-08-17T09·18+0100
committerVincent Ambo <github@tazj.in>2019-08-17T09·31+0100
commit9a95c4124f911dbc07d4eabc0c4b8fc2d44c74d6 (patch)
tree376a3e92f21625a1c46a63942716fc4b85d00a20 /tools
parent0ee239874b76bea75a3d3a90201118b3c4294576 (diff)
fix(server): Sort requested packages in image name & spec
Before this change, Nixery would pass on the image name unmodified to
Nix which would lead it to cache-bust the manifest and configuration
layers for images that are content-identical but have different
package ordering.

This fixes #38.
Diffstat (limited to 'tools')
-rw-r--r--tools/nixery/server/builder/builder.go16
1 files changed, 13 insertions, 3 deletions
diff --git a/tools/nixery/server/builder/builder.go b/tools/nixery/server/builder/builder.go
index 46301d6c6a0c..a249384d9fef 100644
--- a/tools/nixery/server/builder/builder.go
+++ b/tools/nixery/server/builder/builder.go
@@ -27,6 +27,7 @@ import (
 	"log"
 	"os"
 	"os/exec"
+	"sort"
 	"strings"
 
 	"cloud.google.com/go/storage"
@@ -50,12 +51,21 @@ type Image struct {
 //
 // It will expand convenience names under the hood (see the `convenienceNames`
 // function below).
+//
+// Once assembled the image structure uses a sorted representation of
+// the name. This is to avoid unnecessarily cache-busting images if
+// only the order of requested packages has changed.
 func ImageFromName(name string, tag string) Image {
-	packages := strings.Split(name, "/")
+	pkgs := strings.Split(name, "/")
+	expanded := convenienceNames(pkgs)
+
+	sort.Strings(pkgs)
+	sort.Strings(expanded)
+
 	return Image{
-		Name:     name,
+		Name:     strings.Join(pkgs, "/"),
 		Tag:      tag,
-		Packages: convenienceNames(packages),
+		Packages: expanded,
 	}
 }