feat(v0.1.60): sha256-based s3Key for content-addressed cache hit

This commit is contained in:
Naeel
2026-03-23 06:57:18 +03:00
parent c033adec11
commit 2e7cd7f4f7
3 changed files with 18 additions and 7 deletions
+6 -3
View File
@@ -7,10 +7,11 @@
package handler
import (
"crypto/sha256"
"encoding/json"
"fmt"
"io"
"net/http"
"time"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -221,8 +222,10 @@ func (h *Handler) UploadJobCode(w http.ResponseWriter, r *http.Request) {
return
}
// Версия на основе timestamp — каждый upload → новый уникальный ключ в S3
version := time.Now().Format("20060102150405")
// Версия = sha256(загруженный zip). Одинаковый код → одинаковый s3Key → cache hit.
// Изменился код → новый хеш → новый build.
zipHash := sha256.Sum256(zipData)
version := fmt.Sprintf("%x", zipHash[:])[:16]
s3Key, err := h.S3.UploadContext(r.Context(), ns, name, version, buf, int64(buf.Len()))
if err != nil {
writeJSON(w, http.StatusInternalServerError, errResp("upload to S3: "+err.Error()))
+6 -1
View File
@@ -8,7 +8,9 @@
package handler
import (
"crypto/sha256"
"encoding/json"
"fmt"
"io"
"net/http"
"time"
@@ -383,7 +385,10 @@ func (h *Handler) UploadServiceCode(w http.ResponseWriter, r *http.Request) {
return
}
version := time.Now().Format("20060102150405")
// Версия = sha256(загруженный zip). Одинаковый код → одинаковый s3Key → cache hit.
// Изменился код → новый хеш → новый build.
zipHash := sha256.Sum256(zipData)
version := fmt.Sprintf("%x", zipHash[:])[:16]
s3Key, err := h.S3.UploadContext(r.Context(), ns, name, version, buf, int64(buf.Len()))
if err != nil {
writeJSON(w, http.StatusInternalServerError, errResp("upload to S3: "+err.Error()))
+6 -3
View File
@@ -10,9 +10,10 @@
package handler
import (
"crypto/sha256"
"fmt"
"io"
"net/http"
"time"
"k8s.io/apimachinery/pkg/api/errors"
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -65,8 +66,10 @@ func (h *Handler) UploadCode(w http.ResponseWriter, r *http.Request) {
return
}
// Версия на основе timestamp — каждый upload → новый уникальный ключ в S3
version := time.Now().Format("20060102150405")
// Версия = sha256(загруженный zip). Одинаковый код → одинаковый s3Key → cache hit.
// Изменился код → новый хеш → новый build.
zipHash := sha256.Sum256(zipData)
version := fmt.Sprintf("%x", zipHash[:])[:16]
s3Key, err := h.S3.UploadContext(r.Context(), ns, name, version, buf, int64(buf.Len()))
if err != nil {
writeJSON(w, http.StatusInternalServerError, errResp("upload to S3: "+err.Error()))