feat(v0.1.60): sha256-based s3Key for content-addressed cache hit
This commit is contained in:
@@ -7,10 +7,11 @@
|
|||||||
package handler
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/sha256"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/api/errors"
|
"k8s.io/apimachinery/pkg/api/errors"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
@@ -221,8 +222,10 @@ func (h *Handler) UploadJobCode(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Версия на основе timestamp — каждый upload → новый уникальный ключ в S3
|
// Версия = sha256(загруженный zip). Одинаковый код → одинаковый s3Key → cache hit.
|
||||||
version := time.Now().Format("20060102150405")
|
// Изменился код → новый хеш → новый 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()))
|
s3Key, err := h.S3.UploadContext(r.Context(), ns, name, version, buf, int64(buf.Len()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeJSON(w, http.StatusInternalServerError, errResp("upload to S3: "+err.Error()))
|
writeJSON(w, http.StatusInternalServerError, errResp("upload to S3: "+err.Error()))
|
||||||
|
|||||||
@@ -8,7 +8,9 @@
|
|||||||
package handler
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/sha256"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
@@ -383,7 +385,10 @@ func (h *Handler) UploadServiceCode(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
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()))
|
s3Key, err := h.S3.UploadContext(r.Context(), ns, name, version, buf, int64(buf.Len()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeJSON(w, http.StatusInternalServerError, errResp("upload to S3: "+err.Error()))
|
writeJSON(w, http.StatusInternalServerError, errResp("upload to S3: "+err.Error()))
|
||||||
|
|||||||
@@ -10,9 +10,10 @@
|
|||||||
package handler
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/sha256"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/api/errors"
|
"k8s.io/apimachinery/pkg/api/errors"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
@@ -65,8 +66,10 @@ func (h *Handler) UploadCode(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Версия на основе timestamp — каждый upload → новый уникальный ключ в S3
|
// Версия = sha256(загруженный zip). Одинаковый код → одинаковый s3Key → cache hit.
|
||||||
version := time.Now().Format("20060102150405")
|
// Изменился код → новый хеш → новый 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()))
|
s3Key, err := h.S3.UploadContext(r.Context(), ns, name, version, buf, int64(buf.Len()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeJSON(w, http.StatusInternalServerError, errResp("upload to S3: "+err.Error()))
|
writeJSON(w, http.StatusInternalServerError, errResp("upload to S3: "+err.Error()))
|
||||||
|
|||||||
Reference in New Issue
Block a user