-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replace resolveimageconfig with generic sourcemetaresolver
This is more versatile function that works for any source, not just images. It can be used together with a policy that switches between input and output source as well as for adding additional metadata for other sources in the future. Signed-off-by: Tonis Tiigi <[email protected]>
- Loading branch information
1 parent
effe19a
commit 9e14155
Showing
36 changed files
with
1,747 additions
and
536 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package sourceresolver | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
|
||
"github.com/distribution/reference" | ||
"github.com/moby/buildkit/solver/pb" | ||
"github.com/moby/buildkit/util/imageutil" | ||
digest "github.com/opencontainers/go-digest" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
type ImageMetaResolver interface { | ||
ResolveImageConfig(ctx context.Context, ref string, opt Opt) (string, digest.Digest, []byte, error) | ||
} | ||
|
||
type imageMetaResolver struct { | ||
mr MetaResolver | ||
} | ||
|
||
var _ ImageMetaResolver = &imageMetaResolver{} | ||
|
||
func NewImageMetaResolver(mr MetaResolver) ImageMetaResolver { | ||
return &imageMetaResolver{ | ||
mr: mr, | ||
} | ||
} | ||
|
||
func (imr *imageMetaResolver) ResolveImageConfig(ctx context.Context, ref string, opt Opt) (string, digest.Digest, []byte, error) { | ||
parsed, err := reference.ParseNormalizedNamed(ref) | ||
if err != nil { | ||
return "", "", nil, errors.Wrapf(err, "could not parse reference %q", ref) | ||
} | ||
ref = parsed.String() | ||
op := &pb.SourceOp{ | ||
Identifier: "docker-image://" + ref, | ||
} | ||
if opt := opt.OCILayoutOpt; opt != nil { | ||
op.Identifier = "oci-layout://" + ref | ||
op.Attrs = map[string]string{} | ||
if opt.Store.SessionID != "" { | ||
op.Attrs[pb.AttrOCILayoutSessionID] = opt.Store.SessionID | ||
} | ||
if opt.Store.StoreID != "" { | ||
op.Attrs[pb.AttrOCILayoutStoreID] = opt.Store.StoreID | ||
} | ||
} | ||
res, err := imr.mr.ResolveSourceMetadata(ctx, op, opt) | ||
if err != nil { | ||
return "", "", nil, errors.Wrapf(err, "failed to resolve source metadata for %s", ref) | ||
} | ||
if res.Image == nil { | ||
return "", "", nil, &imageutil.ResolveToNonImageError{Ref: ref, Updated: res.Op.Identifier} | ||
} | ||
ref = strings.TrimPrefix(res.Op.Identifier, "docker-image://") | ||
ref = strings.TrimPrefix(ref, "oci-layout://") | ||
return ref, res.Image.Digest, res.Image.Config, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package sourceresolver | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/moby/buildkit/solver/pb" | ||
spb "github.com/moby/buildkit/sourcepolicy/pb" | ||
digest "github.com/opencontainers/go-digest" | ||
ocispecs "github.com/opencontainers/image-spec/specs-go/v1" | ||
) | ||
|
||
type ResolverType int | ||
|
||
const ( | ||
ResolverTypeRegistry ResolverType = iota | ||
ResolverTypeOCILayout | ||
) | ||
|
||
type MetaResolver interface { | ||
ResolveSourceMetadata(ctx context.Context, op *pb.SourceOp, opt Opt) (*MetaResponse, error) | ||
} | ||
|
||
type Opt struct { | ||
LogName string | ||
SourcePolicies []*spb.Policy | ||
Platform *ocispecs.Platform | ||
|
||
ImageOpt *ResolveImageOpt | ||
OCILayoutOpt *ResolveOCILayoutOpt | ||
} | ||
|
||
type MetaResponse struct { | ||
Op *pb.SourceOp | ||
|
||
Image *ResolveImageResponse | ||
} | ||
|
||
type ResolveImageOpt struct { | ||
ResolveMode string | ||
} | ||
|
||
type ResolveImageResponse struct { | ||
Digest digest.Digest | ||
Config []byte | ||
} | ||
|
||
type ResolveOCILayoutOpt struct { | ||
Store ResolveImageConfigOptStore | ||
} | ||
|
||
type ResolveImageConfigOptStore struct { | ||
SessionID string | ||
StoreID string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.