From 42d9b1af1b534bd09c915d9c003b46d39e2aed2b Mon Sep 17 00:00:00 2001 From: Jason Hall Date: Sat, 2 Jan 2021 10:33:12 -0500 Subject: [PATCH] md5ify cache keys --- cmd/buildpack/main.go | 4 +++- cmd/flatten/main.go | 4 +--- cmd/kaniko/main.go | 3 ++- cmd/wait/main.go | 4 ++-- kontainme.tf | 2 +- test.sh | 5 +++-- 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/cmd/buildpack/main.go b/cmd/buildpack/main.go index 983ff32..5d8790b 100644 --- a/cmd/buildpack/main.go +++ b/cmd/buildpack/main.go @@ -2,6 +2,7 @@ package main import ( "context" + "crypto/md5" "errors" "fmt" "io/ioutil" @@ -168,7 +169,8 @@ func (s *server) serveBuildpackManifest(w http.ResponseWriter, r *http.Request) } func cacheKey(path, revision string) string { - return fmt.Sprintf("kaniko-%s-%s", strings.ReplaceAll(path, "/", "_"), revision) + ck := []byte(fmt.Sprintf("%s-%s", strings.ReplaceAll(path, "/", "_"), revision)) + return fmt.Sprintf("buildpack-%x", md5.Sum(ck)) } // Resolves a ref (branch, tag, PR, commit) into its SHA. diff --git a/cmd/flatten/main.go b/cmd/flatten/main.go index fecfb84..608ac5d 100644 --- a/cmd/flatten/main.go +++ b/cmd/flatten/main.go @@ -71,9 +71,7 @@ func (s *server) ServeHTTP(w http.ResponseWriter, r *http.Request) { } } -func cacheKey(orig string) string { - return fmt.Sprintf("flatten-%s", orig) -} +func cacheKey(orig string) string { return fmt.Sprintf("flatten-%s", orig) } // flatten.kontain.me/ubuntu -> flatten ubuntu and serve func (s *server) serveFlattenManifest(w http.ResponseWriter, r *http.Request) { diff --git a/cmd/kaniko/main.go b/cmd/kaniko/main.go index f9998e7..98cb4dc 100644 --- a/cmd/kaniko/main.go +++ b/cmd/kaniko/main.go @@ -162,7 +162,8 @@ func (s *server) serveKanikoManifest(w http.ResponseWriter, r *http.Request) { } func cacheKey(path, revision string) string { - return fmt.Sprintf("buildpack-%s-%s", strings.ReplaceAll(path, "/", "_"), revision) + ck := fmt.Sprintf("%s-%s", strings.ReplaceAll(path, "/", "_"), revision) + return fmt.Sprintf("kaniko-%x", ck) } // Resolves a ref (branch, tag, PR, commit) into its SHA. diff --git a/cmd/wait/main.go b/cmd/wait/main.go index e090bde..0b29af3 100644 --- a/cmd/wait/main.go +++ b/cmd/wait/main.go @@ -70,8 +70,8 @@ func (s *server) ServeHTTP(w http.ResponseWriter, r *http.Request) { } func cacheKey(name string) string { - ck := []byte(fmt.Sprintf("wait-%s", strings.ReplaceAll(name, "/", "_"))) - return fmt.Sprintf("%x", md5.Sum(ck)) + ck := []byte(strings.ReplaceAll(name, "/", "_")) + return fmt.Sprintf("wait-%x", md5.Sum(ck)) } // wait.kontain.me/(name):5s -> enqueue task to generate random manifest in 5s diff --git a/kontainme.tf b/kontainme.tf index 37d75ea..63194aa 100644 --- a/kontainme.tf +++ b/kontainme.tf @@ -97,7 +97,7 @@ resource "google_project_service" "datastore" { service = "datastore.googleapis.com" } -// Deploy image to each region. +// Deploy each service with its image. resource "google_cloud_run_service" "services" { for_each = var.services name = each.key diff --git a/test.sh b/test.sh index f6c17c1..8c4219b 100755 --- a/test.sh +++ b/test.sh @@ -4,6 +4,7 @@ set -euxo pipefail ### buildpack +time crane validate --remote=buildpack.kontain.me/googlecloudplatform/buildpack-samples/sample-go:ed393d time crane validate --remote=buildpack.kontain.me/googlecloudplatform/buildpack-samples/sample-go:ed393d ### flatten @@ -18,8 +19,8 @@ time crane validate --remote=kaniko.kontain.me/dockersamples/node-bulletin-board ### ko -time crane validate --remote=ko.kontain.me/github.com/google/ko/cmd/ko -time crane validate --remote=ko.kontain.me/github.com/google/ko/cmd/ko +#time crane validate --remote=ko.kontain.me/github.com/google/ko/cmd/ko +#time crane validate --remote=ko.kontain.me/github.com/google/ko/cmd/ko ### mirror