mirror of
https://github.com/ko-build/ko.git
synced 2025-11-06 09:19:12 +02:00
Use annotation strings from image-spec/specs-go (#407)
This commit is contained in:
@@ -42,6 +42,7 @@ import (
|
||||
"github.com/google/go-containerregistry/pkg/v1/mutate"
|
||||
"github.com/google/go-containerregistry/pkg/v1/tarball"
|
||||
"github.com/google/go-containerregistry/pkg/v1/types"
|
||||
specsv1 "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"golang.org/x/tools/go/packages"
|
||||
)
|
||||
|
||||
@@ -65,11 +66,6 @@ For more information see:
|
||||
`
|
||||
)
|
||||
|
||||
const (
|
||||
baseDigestAnnotation = "org.opencontainers.image.base.digest"
|
||||
baseRefAnnotation = "org.opencontainers.image.base.name"
|
||||
)
|
||||
|
||||
// GetBase takes an importpath and returns a base image reference and base image (or index).
|
||||
type GetBase func(context.Context, string) (name.Reference, Result, error)
|
||||
|
||||
@@ -784,8 +780,8 @@ func (g *gobuild) buildOne(ctx context.Context, refStr string, baseRef name.Refe
|
||||
}
|
||||
|
||||
withApp = mutate.Annotations(withApp, map[string]string{
|
||||
baseRefAnnotation: baseRef.Name(),
|
||||
baseDigestAnnotation: baseDigest.String(),
|
||||
specsv1.AnnotationBaseImageDigest: baseDigest.String(),
|
||||
specsv1.AnnotationBaseImageName: baseRef.Name(),
|
||||
}).(v1.Image)
|
||||
|
||||
// Start from a copy of the base image's config file, and set
|
||||
@@ -933,8 +929,8 @@ func (g *gobuild) buildAll(ctx context.Context, ref string, baseRef name.Referen
|
||||
// (Docker manifest lists don't support annotations)
|
||||
if baseType == types.OCIImageIndex {
|
||||
idx = mutate.Annotations(idx, map[string]string{
|
||||
baseRefAnnotation: baseRef.Name(),
|
||||
baseDigestAnnotation: baseDigest.String(),
|
||||
specsv1.AnnotationBaseImageName: baseRef.Name(),
|
||||
specsv1.AnnotationBaseImageDigest: baseDigest.String(),
|
||||
}).(v1.ImageIndex)
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ import (
|
||||
"github.com/google/go-containerregistry/pkg/v1/empty"
|
||||
"github.com/google/go-containerregistry/pkg/v1/mutate"
|
||||
"github.com/google/go-containerregistry/pkg/v1/random"
|
||||
specsv1 "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
)
|
||||
|
||||
func repoRootDir() (string, error) {
|
||||
@@ -487,11 +488,11 @@ func validateImage(t *testing.T, img v1.Image, baseLayers int64, creationTime v1
|
||||
t.Fatalf("Manifest() = %v", err)
|
||||
}
|
||||
t.Logf("Got annotations: %v", mf.Annotations)
|
||||
if _, found := mf.Annotations[baseDigestAnnotation]; !found {
|
||||
if _, found := mf.Annotations[specsv1.AnnotationBaseImageDigest]; !found {
|
||||
t.Errorf("image annotations did not contain base image digest")
|
||||
}
|
||||
want := baseRef.Name()
|
||||
if got := mf.Annotations[baseRefAnnotation]; got != want {
|
||||
if got := mf.Annotations[specsv1.AnnotationBaseImageName]; got != want {
|
||||
t.Errorf("base image ref; got %q, want %q", got, want)
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user