Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all: remove duplicate imports #2277

Merged
merged 6 commits into from
Aug 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,30 @@ run:

linters:
enable:
- gofmt
- govet
- deadcode
- gofmt
- goimports
- golint
- govet
- importas
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add importas and sorted alphabetically.

- ineffassign
- misspell
- unused
- varcheck
- golint
- staticcheck
- typecheck
- structcheck
- typecheck
- unused
- varcheck
disable-all: true

linters-settings:
importas:
alias:
- pkg: "github.com/opencontainers/image-spec/specs-go/v1"
alias: "ocispecs"
- pkg: "github.com/opencontainers/go-digest"
alias: "digest"
no-unaliased: true

issues:
exclude-rules:
- linters:
Expand Down
16 changes: 8 additions & 8 deletions cache/blobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/moby/buildkit/util/winlayers"
digest "github.com/opencontainers/go-digest"
imagespecidentity "github.com/opencontainers/image-spec/identity"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
"golang.org/x/sync/errgroup"
)
Expand Down Expand Up @@ -46,7 +46,7 @@ func (sr *immutableRef) computeBlobChain(ctx context.Context, createIfNeeded boo
func computeBlobChain(ctx context.Context, sr *immutableRef, createIfNeeded bool, compressionType compression.Type, forceCompression bool, s session.Group) error {
baseCtx := ctx
eg, ctx := errgroup.WithContext(ctx)
var currentDescr ocispec.Descriptor
var currentDescr ocispecs.Descriptor
if sr.parent != nil {
eg.Go(func() error {
return computeBlobChain(ctx, sr.parent, createIfNeeded, compressionType, forceCompression, s)
Expand All @@ -73,14 +73,14 @@ func computeBlobChain(ctx context.Context, sr *immutableRef, createIfNeeded bool
var mediaType string
switch compressionType {
case compression.Uncompressed:
mediaType = ocispec.MediaTypeImageLayer
mediaType = ocispecs.MediaTypeImageLayer
case compression.Gzip:
mediaType = ocispec.MediaTypeImageLayerGzip
mediaType = ocispecs.MediaTypeImageLayerGzip
default:
return nil, errors.Errorf("unknown layer compression type: %q", compressionType)
}

var descr ocispec.Descriptor
var descr ocispecs.Descriptor
var err error

if descr.Digest == "" {
Expand Down Expand Up @@ -151,7 +151,7 @@ func computeBlobChain(ctx context.Context, sr *immutableRef, createIfNeeded bool
}

if dp != nil {
currentDescr = dp.(ocispec.Descriptor)
currentDescr = dp.(ocispecs.Descriptor)
}
return nil
})
Expand All @@ -170,7 +170,7 @@ func computeBlobChain(ctx context.Context, sr *immutableRef, createIfNeeded bool
// setBlob associates a blob with the cache record.
// A lease must be held for the blob when calling this function
// Caller should call Info() for knowing what current values are actually set
func (sr *immutableRef) setBlob(ctx context.Context, desc ocispec.Descriptor) error {
func (sr *immutableRef) setBlob(ctx context.Context, desc ocispecs.Descriptor) error {
if _, ok := leases.FromContext(ctx); !ok {
return errors.Errorf("missing lease requirement for setBlob")
}
Expand Down Expand Up @@ -242,7 +242,7 @@ func isTypeWindows(sr *immutableRef) bool {
}

// ensureCompression ensures the specified ref has the blob of the specified compression Type.
func ensureCompression(ctx context.Context, ref *immutableRef, desc ocispec.Descriptor, compressionType compression.Type, s session.Group) error {
func ensureCompression(ctx context.Context, ref *immutableRef, desc ocispecs.Descriptor, compressionType compression.Type, s session.Group) error {
// Resolve converters
layerConvertFunc, _, err := getConverters(desc, compressionType)
if err != nil {
Expand Down
20 changes: 10 additions & 10 deletions cache/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import (
"github.com/containerd/containerd/images/converter/uncompress"
"github.com/containerd/containerd/labels"
"github.com/moby/buildkit/util/compression"
"github.com/opencontainers/go-digest"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
digest "github.com/opencontainers/go-digest"
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
)

// getConverters returns converter functions according to the specified compression type.
// If no conversion is needed, this returns nil without error.
func getConverters(desc ocispec.Descriptor, compressionType compression.Type) (converter.ConvertFunc, func(string) string, error) {
func getConverters(desc ocispecs.Descriptor, compressionType compression.Type) (converter.ConvertFunc, func(string) string, error) {
switch compressionType {
case compression.Uncompressed:
if !images.IsLayerType(desc.MediaType) || uncompress.IsUncompressedType(desc.MediaType) {
Expand All @@ -38,7 +38,7 @@ func getConverters(desc ocispec.Descriptor, compressionType compression.Type) (c
}
}

func gzipLayerConvertFunc(ctx context.Context, cs content.Store, desc ocispec.Descriptor) (*ocispec.Descriptor, error) {
func gzipLayerConvertFunc(ctx context.Context, cs content.Store, desc ocispecs.Descriptor) (*ocispecs.Descriptor, error) {
if !images.IsLayerType(desc.MediaType) || isGzipCompressedType(desc.MediaType) {
// No conversion. No need to return an error here.
return nil, nil
Expand Down Expand Up @@ -102,8 +102,8 @@ func isGzipCompressedType(mt string) bool {
case
images.MediaTypeDockerSchema2LayerGzip,
images.MediaTypeDockerSchema2LayerForeignGzip,
ocispec.MediaTypeImageLayerGzip,
ocispec.MediaTypeImageLayerNonDistributableGzip:
ocispecs.MediaTypeImageLayerGzip,
ocispecs.MediaTypeImageLayerNonDistributableGzip:
return true
default:
return false
Expand All @@ -116,10 +116,10 @@ func convertMediaTypeToUncompress(mt string) string {
return images.MediaTypeDockerSchema2Layer
case images.MediaTypeDockerSchema2LayerForeignGzip:
return images.MediaTypeDockerSchema2LayerForeign
case ocispec.MediaTypeImageLayerGzip:
return ocispec.MediaTypeImageLayer
case ocispec.MediaTypeImageLayerNonDistributableGzip:
return ocispec.MediaTypeImageLayerNonDistributable
case ocispecs.MediaTypeImageLayerGzip:
return ocispecs.MediaTypeImageLayer
case ocispecs.MediaTypeImageLayerNonDistributableGzip:
return ocispecs.MediaTypeImageLayerNonDistributable
default:
return mt
}
Expand Down
8 changes: 4 additions & 4 deletions cache/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/moby/buildkit/util/flightcontrol"
digest "github.com/opencontainers/go-digest"
imagespecidentity "github.com/opencontainers/image-spec/identity"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"golang.org/x/sync/errgroup"
Expand All @@ -45,7 +45,7 @@ type ManagerOpt struct {
}

type Accessor interface {
GetByBlob(ctx context.Context, desc ocispec.Descriptor, parent ImmutableRef, opts ...RefOption) (ImmutableRef, error)
GetByBlob(ctx context.Context, desc ocispecs.Descriptor, parent ImmutableRef, opts ...RefOption) (ImmutableRef, error)
Get(ctx context.Context, id string, opts ...RefOption) (ImmutableRef, error)

New(ctx context.Context, parent ImmutableRef, s session.Group, opts ...RefOption) (MutableRef, error)
Expand Down Expand Up @@ -97,7 +97,7 @@ func NewManager(opt ManagerOpt) (Manager, error) {
return cm, nil
}

func (cm *cacheManager) GetByBlob(ctx context.Context, desc ocispec.Descriptor, parent ImmutableRef, opts ...RefOption) (ir ImmutableRef, rerr error) {
func (cm *cacheManager) GetByBlob(ctx context.Context, desc ocispecs.Descriptor, parent ImmutableRef, opts ...RefOption) (ir ImmutableRef, rerr error) {
diffID, err := diffIDFromDescriptor(desc)
if err != nil {
return nil, err
Expand Down Expand Up @@ -1197,7 +1197,7 @@ func sortDeleteRecords(toDelete []*deleteRecord) {
})
}

func diffIDFromDescriptor(desc ocispec.Descriptor) (digest.Digest, error) {
func diffIDFromDescriptor(desc ocispecs.Descriptor) (digest.Digest, error) {
diffIDStr, ok := desc.Annotations["containerd.io/uncompressed"]
if !ok {
return "", errors.Errorf("missing uncompressed annotation for %s", desc.Digest)
Expand Down
22 changes: 11 additions & 11 deletions cache/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
containerdsnapshot "github.com/moby/buildkit/snapshot/containerd"
"github.com/moby/buildkit/util/leaseutil"
digest "github.com/opencontainers/go-digest"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
"github.com/stretchr/testify/require"
bolt "go.etcd.io/bbolt"
Expand Down Expand Up @@ -613,7 +613,7 @@ func TestSetBlob(t *testing.T) {
err = content.WriteBlob(ctx, co.cs, "ref1", bytes.NewBuffer(b), desc)
require.NoError(t, err)

err = snap.(*immutableRef).setBlob(ctx, ocispec.Descriptor{
err = snap.(*immutableRef).setBlob(ctx, ocispecs.Descriptor{
Digest: digest.FromBytes([]byte("foobar")),
Annotations: map[string]string{
"containerd.io/uncompressed": digest.FromBytes([]byte("foobar2")).String(),
Expand Down Expand Up @@ -720,7 +720,7 @@ func TestSetBlob(t *testing.T) {
require.Equal(t, string(info6.ChainID), info6.SnapshotID)
require.Equal(t, info6.Extracted, false)

_, err = cm.GetByBlob(ctx, ocispec.Descriptor{
_, err = cm.GetByBlob(ctx, ocispecs.Descriptor{
Digest: digest.FromBytes([]byte("notexist")),
Annotations: map[string]string{
"containerd.io/uncompressed": digest.FromBytes([]byte("notexist")).String(),
Expand Down Expand Up @@ -1052,7 +1052,7 @@ func (b bufferCloser) Close() error {
return nil
}

func mapToBlob(m map[string]string, compress bool) ([]byte, ocispec.Descriptor, error) {
func mapToBlob(m map[string]string, compress bool) ([]byte, ocispecs.Descriptor, error) {
buf := bytes.NewBuffer(nil)
sha := digest.SHA256.Digester()

Expand All @@ -1067,24 +1067,24 @@ func mapToBlob(m map[string]string, compress bool) ([]byte, ocispec.Descriptor,
Name: k,
Size: int64(len(v)),
}); err != nil {
return nil, ocispec.Descriptor{}, err
return nil, ocispecs.Descriptor{}, err
}
if _, err := tw.Write([]byte(v)); err != nil {
return nil, ocispec.Descriptor{}, err
return nil, ocispecs.Descriptor{}, err
}
}
if err := tw.Close(); err != nil {
return nil, ocispec.Descriptor{}, err
return nil, ocispecs.Descriptor{}, err
}
if err := dest.Close(); err != nil {
return nil, ocispec.Descriptor{}, err
return nil, ocispecs.Descriptor{}, err
}

mediaType := ocispec.MediaTypeImageLayer
mediaType := ocispecs.MediaTypeImageLayer
if compress {
mediaType = ocispec.MediaTypeImageLayerGzip
mediaType = ocispecs.MediaTypeImageLayerGzip
}
return buf.Bytes(), ocispec.Descriptor{
return buf.Bytes(), ocispecs.Descriptor{
Digest: digest.FromBytes(buf.Bytes()),
MediaType: mediaType,
Size: int64(buf.Len()),
Expand Down
8 changes: 4 additions & 4 deletions cache/refs.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/moby/buildkit/util/leaseutil"
"github.com/moby/buildkit/util/winlayers"
digest "github.com/opencontainers/go-digest"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"golang.org/x/sync/errgroup"
Expand Down Expand Up @@ -360,8 +360,8 @@ func (sr *immutableRef) Info() RefInfo {
}
}

func (sr *immutableRef) ociDesc() (ocispec.Descriptor, error) {
desc := ocispec.Descriptor{
func (sr *immutableRef) ociDesc() (ocispecs.Descriptor, error) {
desc := ocispecs.Descriptor{
Digest: digest.Digest(getBlob(sr.md)),
Size: getBlobSize(sr.md),
MediaType: getMediaType(sr.md),
Expand All @@ -377,7 +377,7 @@ func (sr *immutableRef) ociDesc() (ocispec.Descriptor, error) {
if !createdAt.IsZero() {
createdAt, err := createdAt.MarshalText()
if err != nil {
return ocispec.Descriptor{}, err
return ocispecs.Descriptor{}, err
}
desc.Annotations["buildkit/createdat"] = string(createdAt)
}
Expand Down
8 changes: 4 additions & 4 deletions cache/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/moby/buildkit/util/leaseutil"
"github.com/moby/buildkit/util/progress/logs"
"github.com/moby/buildkit/util/pull/pullprogress"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
"golang.org/x/sync/errgroup"
)
Expand Down Expand Up @@ -150,7 +150,7 @@ func (mp *lazyMultiProvider) Add(p lazyRefProvider) {
mp.plist = append(mp.plist, p)
}

func (mp *lazyMultiProvider) ReaderAt(ctx context.Context, desc ocispec.Descriptor) (content.ReaderAt, error) {
func (mp *lazyMultiProvider) ReaderAt(ctx context.Context, desc ocispecs.Descriptor) (content.ReaderAt, error) {
return mp.mprovider.ReaderAt(ctx, desc)
}

Expand All @@ -167,12 +167,12 @@ func (mp *lazyMultiProvider) Unlazy(ctx context.Context) error {

type lazyRefProvider struct {
ref *immutableRef
desc ocispec.Descriptor
desc ocispecs.Descriptor
dh *DescHandler
session session.Group
}

func (p lazyRefProvider) ReaderAt(ctx context.Context, desc ocispec.Descriptor) (content.ReaderAt, error) {
func (p lazyRefProvider) ReaderAt(ctx context.Context, desc ocispecs.Descriptor) (content.ReaderAt, error) {
if desc.Digest != p.desc.Digest {
return nil, errdefs.ErrNotFound
}
Expand Down
10 changes: 5 additions & 5 deletions cache/remotecache/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/moby/buildkit/util/progress/logs"
digest "github.com/opencontainers/go-digest"
specs "github.com/opencontainers/image-spec/specs-go"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -80,14 +80,14 @@ func (ce *contentCacheExporter) Finalize(ctx context.Context) (map[string]string
MediaType string `json:"mediaType,omitempty"`

// Manifests references platform specific manifests.
Manifests []ocispec.Descriptor `json:"manifests"`
Manifests []ocispecs.Descriptor `json:"manifests"`
}

var mfst manifestList
mfst.SchemaVersion = 2
mfst.MediaType = images.MediaTypeDockerSchema2ManifestList
if ce.oci {
mfst.MediaType = ocispec.MediaTypeImageIndex
mfst.MediaType = ocispecs.MediaTypeImageIndex
}

for _, l := range config.Layers {
Expand All @@ -110,7 +110,7 @@ func (ce *contentCacheExporter) Finalize(ctx context.Context) (map[string]string
return nil, err
}
dgst := digest.FromBytes(dt)
desc := ocispec.Descriptor{
desc := ocispecs.Descriptor{
Digest: dgst,
Size: int64(len(dt)),
MediaType: v1.CacheConfigMediaTypeV0,
Expand All @@ -129,7 +129,7 @@ func (ce *contentCacheExporter) Finalize(ctx context.Context) (map[string]string
}
dgst = digest.FromBytes(dt)

desc = ocispec.Descriptor{
desc = ocispecs.Descriptor{
Digest: dgst,
Size: int64(len(dt)),
MediaType: mfst.MediaType,
Expand Down
Loading