about summary refs log tree commit diff
path: root/tools/nixery/server/builder
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2019-10-28T17·32+0100
committerVincent Ambo <github@tazj.in>2019-10-28T21·31+0100
commitd8fba233655e127d54926394eacd4b9391ec8b8b (patch)
treec005b0c965864de6b30ef683c9057d01494d2192 /tools/nixery/server/builder
parent30e618b65bdd330ea5904b2be00cbac46d5b03e3 (diff)
fix(server): Thread request context to all relevant places
Previously background contexts where created where necessary (e.g. in
GCS interactions). Should I begin to use request timeouts or other
context-dependent things in the future, it's useful to have the actual
HTTP request context around.

This threads the request context through the application to all places
that need it.
Diffstat (limited to 'tools/nixery/server/builder')
-rw-r--r--tools/nixery/server/builder/builder.go4
-rw-r--r--tools/nixery/server/builder/cache.go8
2 files changed, 6 insertions, 6 deletions
diff --git a/tools/nixery/server/builder/builder.go b/tools/nixery/server/builder/builder.go
index 021cc662c56d..59158037e443 100644
--- a/tools/nixery/server/builder/builder.go
+++ b/tools/nixery/server/builder/builder.go
@@ -375,7 +375,7 @@ func (b *byteCounter) Write(p []byte) (n int, err error) {
 // image manifest.
 func uploadHashLayer(ctx context.Context, s *State, key string, lw layerWriter) (*manifest.Entry, error) {
 	path := "staging/" + key
-	sha256sum, size, err := s.Storage.Persist(path, func(sw io.Writer) (string, int64, error) {
+	sha256sum, size, err := s.Storage.Persist(ctx, path, func(sw io.Writer) (string, int64, error) {
 		// Sets up a "multiwriter" that simultaneously runs both hash
 		// algorithms and uploads to the storage backend.
 		shasum := sha256.New()
@@ -399,7 +399,7 @@ func uploadHashLayer(ctx context.Context, s *State, key string, lw layerWriter)
 
 	// Hashes are now known and the object is in the bucket, what
 	// remains is to move it to the correct location and cache it.
-	err = s.Storage.Move("staging/"+key, "layers/"+sha256sum)
+	err = s.Storage.Move(ctx, "staging/"+key, "layers/"+sha256sum)
 	if err != nil {
 		log.WithError(err).WithField("layer", key).
 			Error("failed to move layer from staging")
diff --git a/tools/nixery/server/builder/cache.go b/tools/nixery/server/builder/cache.go
index 07ac9746d5f0..82bd90927cd0 100644
--- a/tools/nixery/server/builder/cache.go
+++ b/tools/nixery/server/builder/cache.go
@@ -120,7 +120,7 @@ func manifestFromCache(ctx context.Context, s *State, key string) (json.RawMessa
 		return m, true
 	}
 
-	r, err := s.Storage.Fetch("manifests/" + key)
+	r, err := s.Storage.Fetch(ctx, "manifests/"+key)
 	if err != nil {
 		log.WithError(err).WithFields(log.Fields{
 			"manifest": key,
@@ -152,7 +152,7 @@ func cacheManifest(ctx context.Context, s *State, key string, m json.RawMessage)
 	go s.Cache.localCacheManifest(key, m)
 
 	path := "manifests/" + key
-	_, size, err := s.Storage.Persist(path, func(w io.Writer) (string, int64, error) {
+	_, size, err := s.Storage.Persist(ctx, path, func(w io.Writer) (string, int64, error) {
 		size, err := io.Copy(w, bytes.NewReader([]byte(m)))
 		return "", size, err
 	})
@@ -180,7 +180,7 @@ func layerFromCache(ctx context.Context, s *State, key string) (*manifest.Entry,
 		return entry, true
 	}
 
-	r, err := s.Storage.Fetch("builds/" + key)
+	r, err := s.Storage.Fetch(ctx, "builds/"+key)
 	if err != nil {
 		log.WithError(err).WithFields(log.Fields{
 			"layer":   key,
@@ -220,7 +220,7 @@ func cacheLayer(ctx context.Context, s *State, key string, entry manifest.Entry)
 
 	j, _ := json.Marshal(&entry)
 	path := "builds/" + key
-	_, _, err := s.Storage.Persist(path, func(w io.Writer) (string, int64, error) {
+	_, _, err := s.Storage.Persist(ctx, path, func(w io.Writer) (string, int64, error) {
 		size, err := io.Copy(w, bytes.NewReader(j))
 		return "", size, err
 	})