Skip to content

Commit

Permalink
Merge pull request #1533 from stevvooe/specifier-default
Browse files Browse the repository at this point in the history
platforms: provide simpler function for common use
  • Loading branch information
estesp committed Sep 20, 2017
2 parents 78c4e55 + 9163377 commit ef5f202
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cmd/ctr/utils.go
Expand Up @@ -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")
}
Expand Down
4 changes: 2 additions & 2 deletions container_opts.go
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion container_opts_unix.go
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions image.go
Expand Up @@ -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) {
Expand All @@ -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
}
Expand Down
9 changes: 7 additions & 2 deletions platforms/defaults.go
Expand Up @@ -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,
Expand Down
7 changes: 6 additions & 1 deletion platforms/defaults_test.go
Expand Up @@ -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)
}
}
4 changes: 2 additions & 2 deletions spec_opts_unix.go
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion spec_opts_windows.go
Expand Up @@ -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
}
Expand Down

0 comments on commit ef5f202

Please sign in to comment.