platforms: provide simpler function for common use

Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
Stephen J Day 2017-09-20 11:56:59 -07:00
parent f41871be9d
commit 9163377123
No known key found for this signature in database
GPG Key ID: 67B3DED84EDC823F
8 changed files with 23 additions and 13 deletions

View File

@ -206,7 +206,7 @@ func getImageLayers(ctx gocontext.Context, image images.Image, cs content.Store)
return nil, errors.Wrap(err, "failed to unmarshal manifest")
}
diffIDs, err := image.RootFS(ctx, cs, platforms.Format(platforms.Default()))
diffIDs, err := image.RootFS(ctx, cs, platforms.Default())
if err != nil {
return nil, errors.Wrap(err, "failed to resolve rootfs")
}

View File

@ -80,7 +80,7 @@ func WithSnapshot(id string) NewContainerOpts {
// root filesystem in read-write mode
func WithNewSnapshot(id string, i Image) NewContainerOpts {
return func(ctx context.Context, client *Client, c *containers.Container) error {
diffIDs, err := i.(*image).i.RootFS(ctx, client.ContentStore(), platforms.Format(platforms.Default()))
diffIDs, err := i.(*image).i.RootFS(ctx, client.ContentStore(), platforms.Default())
if err != nil {
return err
}
@ -109,7 +109,7 @@ func WithSnapshotCleanup(ctx context.Context, client *Client, c containers.Conta
// root filesystem in read-only mode
func WithNewSnapshotView(id string, i Image) NewContainerOpts {
return func(ctx context.Context, client *Client, c *containers.Container) error {
diffIDs, err := i.(*image).i.RootFS(ctx, client.ContentStore(), platforms.Format(platforms.Default()))
diffIDs, err := i.(*image).i.RootFS(ctx, client.ContentStore(), platforms.Default())
if err != nil {
return err
}

View File

@ -39,7 +39,7 @@ func WithCheckpoint(desc v1.Descriptor, snapshotKey string) NewContainerOpts {
fk := m
rw = &fk
case images.MediaTypeDockerSchema2Manifest:
config, err := images.Config(ctx, store, m, platforms.Format(platforms.Default()))
config, err := images.Config(ctx, store, m, platforms.Default())
if err != nil {
return err
}

View File

@ -45,7 +45,7 @@ func (i *image) Target() ocispec.Descriptor {
func (i *image) RootFS(ctx context.Context) ([]digest.Digest, error) {
provider := i.client.ContentStore()
return i.i.RootFS(ctx, provider, platforms.Format(platforms.Default()))
return i.i.RootFS(ctx, provider, platforms.Default())
}
func (i *image) Size(ctx context.Context) (int64, error) {
@ -55,11 +55,11 @@ func (i *image) Size(ctx context.Context) (int64, error) {
func (i *image) Config(ctx context.Context) (ocispec.Descriptor, error) {
provider := i.client.ContentStore()
return i.i.Config(ctx, provider, platforms.Format(platforms.Default()))
return i.i.Config(ctx, provider, platforms.Default())
}
func (i *image) Unpack(ctx context.Context, snapshotterName string) error {
layers, err := i.getLayers(ctx, platforms.Format(platforms.Default()))
layers, err := i.getLayers(ctx, platforms.Default())
if err != nil {
return err
}

View File

@ -6,8 +6,13 @@ import (
specs "github.com/opencontainers/image-spec/specs-go/v1"
)
// Default returns the current platform's default platform specification.
func Default() specs.Platform {
// Default returns the default specifier for the platform.
func Default() string {
return Format(DefaultSpec())
}
// DefaultSpec returns the current platform's default platform specification.
func DefaultSpec() specs.Platform {
return specs.Platform{
OS: runtime.GOOS,
Architecture: runtime.GOARCH,

View File

@ -13,8 +13,13 @@ func TestDefault(t *testing.T) {
OS: runtime.GOOS,
Architecture: runtime.GOARCH,
}
p := Default()
p := DefaultSpec()
if !reflect.DeepEqual(p, expected) {
t.Fatalf("default platform not as expected: %#v != %#v", p, expected)
}
s := Default()
if s != Format(p) {
t.Fatalf("default specifier should match formatted default spec: %v != %v", s, p)
}
}

View File

@ -73,7 +73,7 @@ func WithImageConfig(i Image) SpecOpts {
image = i.(*image)
store = client.ContentStore()
)
ic, err := image.i.Config(ctx, store, platforms.Format(platforms.Default()))
ic, err := image.i.Config(ctx, store, platforms.Default())
if err != nil {
return err
}
@ -236,7 +236,7 @@ func WithRemappedSnapshotView(id string, i Image, uid, gid uint32) NewContainerO
func withRemappedSnapshotBase(id string, i Image, uid, gid uint32, readonly bool) NewContainerOpts {
return func(ctx context.Context, client *Client, c *containers.Container) error {
diffIDs, err := i.(*image).i.RootFS(ctx, client.ContentStore(), platforms.Format(platforms.Default()))
diffIDs, err := i.(*image).i.RootFS(ctx, client.ContentStore(), platforms.Default())
if err != nil {
return err
}

View File

@ -21,7 +21,7 @@ func WithImageConfig(i Image) SpecOpts {
image = i.(*image)
store = client.ContentStore()
)
ic, err := image.i.Config(ctx, store, platforms.Format(platforms.Default()))
ic, err := image.i.Config(ctx, store, platforms.Default())
if err != nil {
return err
}