diff --git a/internal/api/handler/jobs.go b/internal/api/handler/jobs.go index 42bc286..1883edf 100644 --- a/internal/api/handler/jobs.go +++ b/internal/api/handler/jobs.go @@ -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())) diff --git a/internal/api/handler/services.go b/internal/api/handler/services.go index a9df160..fd7ee87 100644 --- a/internal/api/handler/services.go +++ b/internal/api/handler/services.go @@ -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())) diff --git a/internal/api/handler/upload.go b/internal/api/handler/upload.go index ad146a5..2353a9d 100644 --- a/internal/api/handler/upload.go +++ b/internal/api/handler/upload.go @@ -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()))