-
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.
Sources are a pretty neat extension point, except there are a few code paths that hard-code against each type. This moves code around and adjusts interfaces so that Source implementations are self-contained and merely need to be registered with the source.Manager. Signed-off-by: Alex Suraci <suraci.alex@gmail.com>
- Loading branch information
Showing
21 changed files
with
741 additions
and
613 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package containerimage | ||
|
||
import ( | ||
"github.com/containerd/containerd/reference" | ||
"github.com/moby/buildkit/client" | ||
"github.com/moby/buildkit/solver/llbsolver/provenance" | ||
"github.com/moby/buildkit/source" | ||
srctypes "github.com/moby/buildkit/source/types" | ||
"github.com/moby/buildkit/util/resolver" | ||
digest "github.com/opencontainers/go-digest" | ||
ocispecs "github.com/opencontainers/image-spec/specs-go/v1" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
type ImageIdentifier struct { | ||
Reference reference.Spec | ||
Platform *ocispecs.Platform | ||
ResolveMode resolver.ResolveMode | ||
RecordType client.UsageRecordType | ||
LayerLimit *int | ||
} | ||
|
||
func NewImageIdentifier(str string) (*ImageIdentifier, error) { | ||
ref, err := reference.Parse(str) | ||
if err != nil { | ||
return nil, errors.WithStack(err) | ||
} | ||
|
||
if ref.Object == "" { | ||
return nil, errors.WithStack(reference.ErrObjectRequired) | ||
} | ||
return &ImageIdentifier{Reference: ref}, nil | ||
} | ||
|
||
var _ source.Identifier = (*ImageIdentifier)(nil) | ||
|
||
func (*ImageIdentifier) Scheme() string { | ||
return srctypes.DockerImageScheme | ||
} | ||
|
||
func (id *ImageIdentifier) Capture(c *provenance.Capture, pin string) error { | ||
dgst, err := digest.Parse(pin) | ||
if err != nil { | ||
return errors.Wrapf(err, "failed to parse image digest %s", pin) | ||
} | ||
c.AddImage(provenance.ImageSource{ | ||
Ref: id.Reference.String(), | ||
Platform: id.Platform, | ||
Digest: dgst, | ||
}) | ||
return nil | ||
} | ||
|
||
type OCIIdentifier struct { | ||
Reference reference.Spec | ||
Platform *ocispecs.Platform | ||
SessionID string | ||
StoreID string | ||
LayerLimit *int | ||
} | ||
|
||
func NewOCIIdentifier(str string) (*OCIIdentifier, error) { | ||
ref, err := reference.Parse(str) | ||
if err != nil { | ||
return nil, errors.WithStack(err) | ||
} | ||
|
||
if ref.Object == "" { | ||
return nil, errors.WithStack(reference.ErrObjectRequired) | ||
} | ||
return &OCIIdentifier{Reference: ref}, nil | ||
} | ||
|
||
var _ source.Identifier = (*OCIIdentifier)(nil) | ||
|
||
func (*OCIIdentifier) Scheme() string { | ||
return srctypes.OCIScheme | ||
} | ||
|
||
func (id *OCIIdentifier) Capture(c *provenance.Capture, pin string) error { | ||
dgst, err := digest.Parse(pin) | ||
if err != nil { | ||
return errors.Wrapf(err, "failed to parse OCI digest %s", pin) | ||
} | ||
c.AddImage(provenance.ImageSource{ | ||
Ref: id.Reference.String(), | ||
Platform: id.Platform, | ||
Digest: dgst, | ||
Local: true, | ||
}) | ||
return 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
Oops, something went wrong.