feat(repo): use OCI style digest identifiers

Use the same format as the Open Container Initiative for a digest
string. https://github.com/opencontainers/image-spec/blob/master/descriptor.md#digests-and-verification

Fixes #1166
pull/1202/head
Brandon Philips 8 years ago
parent 1d6202d895
commit 440e548901

@ -23,7 +23,7 @@ alpine-0.1.0:
name: alpine name: alpine
url: https://storage.googleapis.com/kubernetes-charts/alpine-0.1.0.tgz url: https://storage.googleapis.com/kubernetes-charts/alpine-0.1.0.tgz
created: 2016-05-26 11:23:44.086354411 +0000 UTC created: 2016-05-26 11:23:44.086354411 +0000 UTC
checksum: a61575c2d3160e5e39abf2a5ec984d6119404b18 digest: sha256:78e9a4282295184e8ce1496d23987993673f38e33e203c8bc18bc838a73e5864
chartfile: chartfile:
name: alpine name: alpine
description: Deploy a basic Alpine Linux pod description: Deploy a basic Alpine Linux pod
@ -33,7 +33,7 @@ redis-2.0.0:
name: redis name: redis
url: https://storage.googleapis.com/kubernetes-charts/redis-2.0.0.tgz url: https://storage.googleapis.com/kubernetes-charts/redis-2.0.0.tgz
created: 2016-05-26 11:23:44.087939192 +0000 UTC created: 2016-05-26 11:23:44.087939192 +0000 UTC
checksum: 2cea3048cf85d588204e1b1cc0674472b4517919 digest: sha256:bde9c2949e64d059c18d8f93566a64dafc6d2e8e259a70322fb804831dfd0b5b
chartfile: chartfile:
name: redis name: redis
description: Port of the replicatedservice template from kubernetes/charts description: Port of the replicatedservice template from kubernetes/charts

@ -39,7 +39,7 @@ type ChartRef struct {
URL string `yaml:"url"` URL string `yaml:"url"`
Created string `yaml:"created,omitempty"` Created string `yaml:"created,omitempty"`
Removed bool `yaml:"removed,omitempty"` Removed bool `yaml:"removed,omitempty"`
Checksum string `yaml:"checksum,omitempty"` Digest string `yaml:"digest,omitempty"`
Chartfile *chart.Metadata `yaml:"chartfile"` Chartfile *chart.Metadata `yaml:"chartfile"`
} }

@ -17,9 +17,10 @@ limitations under the License.
package repo // import "k8s.io/helm/pkg/repo" package repo // import "k8s.io/helm/pkg/repo"
import ( import (
"crypto/sha1" "crypto/sha256"
"encoding/hex"
"errors" "errors"
"fmt" "io"
"io/ioutil" "io/ioutil"
"net/url" "net/url"
"os" "os"
@ -131,7 +132,7 @@ func (r *ChartRepository) Index() error {
} }
chartfile := ch.Metadata chartfile := ch.Metadata
hash, err := generateChecksum(path) digest, err := generateDigest(path)
if err != nil { if err != nil {
return err return err
} }
@ -152,7 +153,7 @@ func (r *ChartRepository) Index() error {
url, _ := url.Parse(r.URL) url, _ := url.Parse(r.URL)
url.Path = filepath.Join(url.Path, key+".tgz") url.Path = filepath.Join(url.Path, key+".tgz")
entry := &ChartRef{Chartfile: chartfile, Name: chartfile.Name, URL: url.String(), Created: created, Checksum: hash, Removed: false} entry := &ChartRef{Chartfile: chartfile, Name: chartfile.Name, URL: url.String(), Created: created, Digest: digest, Removed: false}
r.IndexFile.Entries[key] = entry r.IndexFile.Entries[key] = entry
@ -170,18 +171,15 @@ func (r *ChartRepository) Index() error {
return r.saveIndexFile() return r.saveIndexFile()
} }
func generateChecksum(path string) (string, error) { func generateDigest(path string) (string, error) {
f, err := os.Open(path) f, err := os.Open(path)
if err != nil { if err != nil {
return "", err return "", err
} }
b, err := ioutil.ReadAll(f) h := sha256.New()
if err != nil { io.Copy(h, f)
return "", err
}
result := sha1.Sum(b)
return fmt.Sprintf("%x", result), nil digest := h.Sum([]byte{})
return "sha256:" + hex.EncodeToString(digest[:]), nil
} }

@ -85,8 +85,8 @@ func TestIndex(t *testing.T) {
} }
timestamps[chartName] = details.Created timestamps[chartName] = details.Created
if details.Checksum == "" { if details.Digest == "" {
t.Errorf("Checksum was not set for %s", chartName) t.Errorf("Digest was not set for %s", chartName)
} }
} }

Loading…
Cancel
Save