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.
This commit is contained in:
Vincent Ambo 2019-08-17 10:18:15 +01:00 committed by Vincent Ambo
parent 0ee239874b
commit 9a95c4124f

View file

@ -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,
}
}