about summary refs log tree commit diff
path: root/tools/nixery/server/main.go
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2019-08-14T19·02+0100
committerVincent Ambo <github@tazj.in>2019-08-14T19·18+0100
commitcf227c153f0eb55b2d931c780d3f7b020e8844bb (patch)
treea49b21e8d6ecc5310acee0d51d01cca0ce6051a1 /tools/nixery/server/main.go
parent58380e331340d5fb19726531e1a5b50999b260dc (diff)
feat(builder): Implement build cache for manifests & layers
Implements a cache that keeps track of:

a) Manifests that have already been built (for up to 6 hours)
b) Layers that have already been seen (and uploaded to GCS)

This significantly speeds up response times for images that are full
or partial matches with previous images served by an instance.
Diffstat (limited to 'tools/nixery/server/main.go')
-rw-r--r--tools/nixery/server/main.go5
1 files changed, 4 insertions, 1 deletions
diff --git a/tools/nixery/server/main.go b/tools/nixery/server/main.go
index 5d7dcd2adfc2..fd307f79d4b4 100644
--- a/tools/nixery/server/main.go
+++ b/tools/nixery/server/main.go
@@ -125,6 +125,7 @@ type registryHandler struct {
 	cfg    *config.Config
 	ctx    *context.Context
 	bucket *storage.BucketHandle
+	cache  *builder.BuildCache
 }
 
 func (h *registryHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@@ -140,7 +141,7 @@ func (h *registryHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 		imageTag := manifestMatches[2]
 		log.Printf("Requesting manifest for image %q at tag %q", imageName, imageTag)
 		image := builder.ImageFromName(imageName, imageTag)
-		buildResult, err := builder.BuildImage(h.ctx, h.cfg, &image, h.bucket)
+		buildResult, err := builder.BuildImage(h.ctx, h.cfg, h.cache, &image, h.bucket)
 
 		if err != nil {
 			writeError(w, 500, "UNKNOWN", "image build failure")
@@ -192,6 +193,7 @@ func main() {
 	cfg := config.FromEnv()
 	ctx := context.Background()
 	bucket := prepareBucket(&ctx, cfg)
+	cache := builder.NewCache()
 
 	log.Printf("Starting Kubernetes Nix controller on port %s\n", cfg.Port)
 
@@ -200,6 +202,7 @@ func main() {
 		cfg:    cfg,
 		ctx:    &ctx,
 		bucket: bucket,
+		cache:  &cache,
 	})
 
 	// All other roots are served by the static file server.