From a8aa7b200c5a15f76f3bb2d39e0f3f3aa51787c1 Mon Sep 17 00:00:00 2001 From: coryb Date: Sun, 12 Mar 2023 11:21:27 -0700 Subject: [PATCH] use bklog.G(ctx) instead of logrus directly Signed-off-by: coryb --- .golangci.yml | 1 + cache/blobs.go | 6 +++--- cache/manager.go | 7 +++---- cache/metadata.go | 2 +- cache/metadata/metadata.go | 7 ++++--- cache/metadata/metadata_test.go | 8 +++++--- cache/refs.go | 7 +++---- cache/remotecache/azblob/exporter.go | 4 ++-- cache/remotecache/azblob/importer.go | 8 ++++---- cache/remotecache/export.go | 2 +- cache/remotecache/gha/gha.go | 4 ++-- cache/remotecache/import.go | 4 ++-- cache/remotecache/inline/inline.go | 4 ++-- cache/remotecache/v1/chains.go | 6 +++--- cache/remotecache/v1/utils.go | 12 ++++++------ cmd/buildctl/build.go | 6 +++--- cmd/buildctl/build/exportcache.go | 4 ++-- cmd/buildctl/build/importcache.go | 4 ++-- cmd/buildctl/debug/workers.go | 4 ++-- cmd/buildctl/dialstdio.go | 6 +++--- cmd/buildctl/diskusage.go | 4 ++-- cmd/buildctl/prune.go | 4 ++-- cmd/buildkitd/debug.go | 6 +++--- cmd/buildkitd/main.go | 18 +++++++++--------- cmd/buildkitd/main_containerd_worker.go | 10 +++++----- cmd/buildkitd/main_oci_worker.go | 15 ++++++++------- cmd/buildkitd/util_linux.go | 4 ++-- executor/containerdexecutor/executor.go | 2 +- executor/runcexecutor/executor.go | 2 +- executor/stubs.go | 13 +++++++------ exporter/containerimage/export.go | 2 +- exporter/containerimage/opts.go | 17 +++++++++-------- exporter/containerimage/writer.go | 6 +++--- exporter/oci/export.go | 2 +- .../dockerfile/cmd/dockerfile-frontend/main.go | 4 ++-- frontend/gateway/gateway.go | 2 +- frontend/gateway/grpcclient/client.go | 2 +- solver/llbsolver/solver.go | 9 +++++---- util/appcontext/appcontext.go | 4 ++-- util/archutil/detect.go | 8 ++++---- util/compression/compression.go | 10 +++++----- util/entitlements/security/security_linux.go | 12 ++++++------ util/grpcerrors/grpcerrors.go | 11 ++++++----- util/grpcerrors/intercept.go | 6 +++--- util/network/netproviders/network_unix.go | 4 ++-- util/network/netproviders/network_windows.go | 4 ++-- util/progress/progressui/colors.go | 18 +++++++++--------- util/pull/pullprogress/progress.go | 13 ++++++++----- util/push/push.go | 6 +++--- util/resolver/limited/group.go | 4 ++-- util/testutil/integration/containerd.go | 4 ++-- util/testutil/integration/oci.go | 4 ++-- util/testutil/integration/sandbox.go | 4 ++-- util/winlayers/differ.go | 10 +++++----- 54 files changed, 180 insertions(+), 170 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index b76fc488b9a7..9e199428b5b2 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -44,6 +44,7 @@ linters-settings: forbidigo: forbid: - '^fmt\.Errorf(# use errors\.Errorf instead)?$' + - 'logrus\.(Trace|Debug|Info|Warn|Warning|Error|Fatal)(f|ln)?\((# use bklog\.G\(ctx\) instead of logrus directly)?' importas: alias: - pkg: "github.com/opencontainers/image-spec/specs-go/v1" diff --git a/cache/blobs.go b/cache/blobs.go index 716be9093471..88ea08b8a00b 100644 --- a/cache/blobs.go +++ b/cache/blobs.go @@ -11,6 +11,7 @@ import ( "github.com/containerd/containerd/leases" "github.com/containerd/containerd/mount" "github.com/moby/buildkit/session" + "github.com/moby/buildkit/util/bklog" "github.com/moby/buildkit/util/compression" "github.com/moby/buildkit/util/flightcontrol" "github.com/moby/buildkit/util/winlayers" @@ -18,7 +19,6 @@ import ( imagespecidentity "github.com/opencontainers/image-spec/identity" ocispecs "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" - "github.com/sirupsen/logrus" "golang.org/x/sync/errgroup" ) @@ -180,7 +180,7 @@ func computeBlobChain(ctx context.Context, sr *immutableRef, createIfNeeded bool } } if logWarnOnErr { - logrus.Warnf("failed to compute blob by overlay differ (ok=%v): %v", ok, err) + bklog.G(ctx).Warnf("failed to compute blob by overlay differ (ok=%v): %v", ok, err) } } if ok { @@ -198,7 +198,7 @@ func computeBlobChain(ctx context.Context, sr *immutableRef, createIfNeeded bool diff.WithCompressor(compressorFunc), ) if err != nil { - logrus.WithError(err).Warnf("failed to compute blob by buildkit differ") + bklog.G(ctx).WithError(err).Warnf("failed to compute blob by buildkit differ") } } diff --git a/cache/manager.go b/cache/manager.go index d579a6007ba0..0f305ae5f8da 100644 --- a/cache/manager.go +++ b/cache/manager.go @@ -27,7 +27,6 @@ import ( imagespecidentity "github.com/opencontainers/image-spec/identity" ocispecs "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" - "github.com/sirupsen/logrus" "golang.org/x/sync/errgroup" ) @@ -243,7 +242,7 @@ func (cm *cacheManager) GetByBlob(ctx context.Context, desc ocispecs.Descriptor, if err := cm.LeaseManager.Delete(context.TODO(), leases.Lease{ ID: l.ID, }); err != nil { - logrus.Errorf("failed to remove lease: %+v", err) + bklog.G(ctx).Errorf("failed to remove lease: %+v", err) } } }() @@ -319,7 +318,7 @@ func (cm *cacheManager) init(ctx context.Context) error { for _, si := range items { if _, err := cm.getRecord(ctx, si.ID()); err != nil { - logrus.Debugf("could not load snapshot %s: %+v", si.ID(), err) + bklog.G(ctx).Debugf("could not load snapshot %s: %+v", si.ID(), err) cm.MetadataStore.Clear(si.ID()) cm.LeaseManager.Delete(ctx, leases.Lease{ID: si.ID()}) } @@ -597,7 +596,7 @@ func (cm *cacheManager) New(ctx context.Context, s ImmutableRef, sess session.Gr if err := cm.LeaseManager.Delete(context.TODO(), leases.Lease{ ID: l.ID, }); err != nil { - logrus.Errorf("failed to remove lease: %+v", err) + bklog.G(ctx).Errorf("failed to remove lease: %+v", err) } } }() diff --git a/cache/metadata.go b/cache/metadata.go index 82209a93c0f9..b223024dcae3 100644 --- a/cache/metadata.go +++ b/cache/metadata.go @@ -87,7 +87,7 @@ func (cm *cacheManager) Search(ctx context.Context, idx string) ([]RefMetadata, // callers must hold cm.mu lock func (cm *cacheManager) search(ctx context.Context, idx string) ([]RefMetadata, error) { - sis, err := cm.MetadataStore.Search(idx) + sis, err := cm.MetadataStore.Search(ctx, idx) if err != nil { return nil, err } diff --git a/cache/metadata/metadata.go b/cache/metadata/metadata.go index 170c0a8872f4..1240034a4472 100644 --- a/cache/metadata/metadata.go +++ b/cache/metadata/metadata.go @@ -2,12 +2,13 @@ package metadata import ( "bytes" + "context" "encoding/json" "strings" "sync" + "github.com/moby/buildkit/util/bklog" "github.com/pkg/errors" - "github.com/sirupsen/logrus" bolt "go.etcd.io/bbolt" ) @@ -80,7 +81,7 @@ func (s *Store) Probe(index string) (bool, error) { return exists, errors.WithStack(err) } -func (s *Store) Search(index string) ([]*StorageItem, error) { +func (s *Store) Search(ctx context.Context, index string) ([]*StorageItem, error) { var out []*StorageItem err := s.db.View(func(tx *bolt.Tx) error { b := tx.Bucket([]byte(indexBucket)) @@ -100,7 +101,7 @@ func (s *Store) Search(index string) ([]*StorageItem, error) { k, _ = c.Next() b := main.Bucket([]byte(itemID)) if b == nil { - logrus.Errorf("index pointing to missing record %s", itemID) + bklog.G(ctx).Errorf("index pointing to missing record %s", itemID) continue } si, err := newStorageItem(itemID, b, s) diff --git a/cache/metadata/metadata_test.go b/cache/metadata/metadata_test.go index 0dc362773dda..4656aefa2d69 100644 --- a/cache/metadata/metadata_test.go +++ b/cache/metadata/metadata_test.go @@ -1,6 +1,7 @@ package metadata import ( + "context" "path/filepath" "testing" @@ -140,14 +141,15 @@ func TestIndexes(t *testing.T) { require.NoError(t, err) } - sis, err := s.Search("tag:baz") + ctx := context.Background() + sis, err := s.Search(ctx, "tag:baz") require.NoError(t, err) require.Equal(t, 2, len(sis)) require.Equal(t, sis[0].ID(), "foo1") require.Equal(t, sis[1].ID(), "foo3") - sis, err = s.Search("tag:bax") + sis, err = s.Search(ctx, "tag:bax") require.NoError(t, err) require.Equal(t, 1, len(sis)) @@ -156,7 +158,7 @@ func TestIndexes(t *testing.T) { err = s.Clear("foo1") require.NoError(t, err) - sis, err = s.Search("tag:baz") + sis, err = s.Search(ctx, "tag:baz") require.NoError(t, err) require.Equal(t, 1, len(sis)) diff --git a/cache/refs.go b/cache/refs.go index 0af736ab70ca..f742d4a16889 100644 --- a/cache/refs.go +++ b/cache/refs.go @@ -34,7 +34,6 @@ import ( digest "github.com/opencontainers/go-digest" ocispecs "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" - "github.com/sirupsen/logrus" "golang.org/x/sync/errgroup" ) @@ -993,7 +992,7 @@ func (sr *immutableRef) withRemoteSnapshotLabelsStargzMode(ctx context.Context, info.Labels[k] = "" // Remove labels appended in this call } if _, err := r.cm.Snapshotter.Update(ctx, info, flds...); err != nil { - logrus.Warn(errors.Wrapf(err, "failed to remove tmp remote labels")) + bklog.G(ctx).Warn(errors.Wrapf(err, "failed to remove tmp remote labels")) } }() @@ -1055,7 +1054,7 @@ func (sr *immutableRef) prepareRemoteSnapshotsStargzMode(ctx context.Context, s info.Labels[k] = "" } if _, err := r.cm.Snapshotter.Update(ctx, info, tmpFields...); err != nil { - logrus.Warn(errors.Wrapf(err, + bklog.G(ctx).Warn(errors.Wrapf(err, "failed to remove tmp remote labels after prepare")) } }() @@ -1363,7 +1362,7 @@ func (cr *cacheRecord) finalize(ctx context.Context) error { cr.cm.mu.Lock() defer cr.cm.mu.Unlock() if err := mutable.remove(context.TODO(), true); err != nil { - logrus.Error(err) + bklog.G(ctx).Error(err) } }() diff --git a/cache/remotecache/azblob/exporter.go b/cache/remotecache/azblob/exporter.go index 406b12f8fbd2..2b2b8f9769d7 100644 --- a/cache/remotecache/azblob/exporter.go +++ b/cache/remotecache/azblob/exporter.go @@ -14,11 +14,11 @@ import ( v1 "github.com/moby/buildkit/cache/remotecache/v1" "github.com/moby/buildkit/session" "github.com/moby/buildkit/solver" + "github.com/moby/buildkit/util/bklog" "github.com/moby/buildkit/util/compression" "github.com/moby/buildkit/util/progress" digest "github.com/opencontainers/go-digest" "github.com/pkg/errors" - "github.com/sirupsen/logrus" ) // ResolveCacheExporterFunc for "azblob" cache exporter. @@ -89,7 +89,7 @@ func (ce *exporter) Finalize(ctx context.Context) (map[string]string, error) { return nil, err } - logrus.Debugf("layers %s exists = %t", key, exists) + bklog.G(ctx).Debugf("layers %s exists = %t", key, exists) if !exists { layerDone := progress.OneOff(ctx, fmt.Sprintf("writing layer %s", l.Blob)) diff --git a/cache/remotecache/azblob/importer.go b/cache/remotecache/azblob/importer.go index ea10c59f049a..8601843d6737 100644 --- a/cache/remotecache/azblob/importer.go +++ b/cache/remotecache/azblob/importer.go @@ -13,12 +13,12 @@ import ( v1 "github.com/moby/buildkit/cache/remotecache/v1" "github.com/moby/buildkit/session" "github.com/moby/buildkit/solver" + "github.com/moby/buildkit/util/bklog" "github.com/moby/buildkit/util/contentutil" "github.com/moby/buildkit/util/progress" "github.com/moby/buildkit/worker" ocispecs "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" - "github.com/sirupsen/logrus" "golang.org/x/sync/errgroup" ) @@ -92,7 +92,7 @@ func (ci *importer) loadManifest(ctx context.Context, name string) (*v1.CacheCha return nil, err } - logrus.Debugf("name %s cache with key %s exists = %v", name, key, exists) + bklog.G(ctx).Debugf("name %s cache with key %s exists = %v", name, key, exists) if !exists { return v1.NewCacheChains(), nil @@ -113,7 +113,7 @@ func (ci *importer) loadManifest(ctx context.Context, name string) (*v1.CacheCha return nil, errors.WithStack(err) } - logrus.Debugf("imported config: %s", string(bytes)) + bklog.G(ctx).Debugf("imported config: %s", string(bytes)) var config v1.CacheConfig if err := json.Unmarshal(bytes, &config); err != nil { @@ -188,7 +188,7 @@ func (f *fetcher) Fetch(ctx context.Context, desc ocispecs.Descriptor) (io.ReadC return nil, errors.Errorf("blob %s not found", desc.Digest) } - logrus.Debugf("reading layer from cache: %s", key) + bklog.G(ctx).Debugf("reading layer from cache: %s", key) blobClient, err := f.containerClient.NewBlockBlobClient(key) if err != nil { diff --git a/cache/remotecache/export.go b/cache/remotecache/export.go index a0fd7ba7e202..b63153d78070 100644 --- a/cache/remotecache/export.go +++ b/cache/remotecache/export.go @@ -104,7 +104,7 @@ func (ce *contentCacheExporter) Finalize(ctx context.Context) (map[string]string mfst.Manifests = append(mfst.Manifests, dgstPair.Descriptor) } - mfst.Manifests = compression.ConvertAllLayerMediaTypes(ce.oci, mfst.Manifests...) + mfst.Manifests = compression.ConvertAllLayerMediaTypes(ctx, ce.oci, mfst.Manifests...) dt, err := json.Marshal(config) if err != nil { diff --git a/cache/remotecache/gha/gha.go b/cache/remotecache/gha/gha.go index 9b16e7fc9de8..c24755e93d07 100644 --- a/cache/remotecache/gha/gha.go +++ b/cache/remotecache/gha/gha.go @@ -15,6 +15,7 @@ import ( v1 "github.com/moby/buildkit/cache/remotecache/v1" "github.com/moby/buildkit/session" "github.com/moby/buildkit/solver" + "github.com/moby/buildkit/util/bklog" "github.com/moby/buildkit/util/compression" "github.com/moby/buildkit/util/progress" "github.com/moby/buildkit/util/tracing" @@ -22,13 +23,12 @@ import ( digest "github.com/opencontainers/go-digest" ocispecs "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" - "github.com/sirupsen/logrus" actionscache "github.com/tonistiigi/go-actions-cache" "golang.org/x/sync/errgroup" ) func init() { - actionscache.Log = logrus.Debugf + actionscache.Log = bklog.L.Debugf } const ( diff --git a/cache/remotecache/import.go b/cache/remotecache/import.go index 6278090187ec..6e3c6331d9fc 100644 --- a/cache/remotecache/import.go +++ b/cache/remotecache/import.go @@ -12,12 +12,12 @@ import ( v1 "github.com/moby/buildkit/cache/remotecache/v1" "github.com/moby/buildkit/session" "github.com/moby/buildkit/solver" + "github.com/moby/buildkit/util/bklog" "github.com/moby/buildkit/util/imageutil" "github.com/moby/buildkit/worker" digest "github.com/opencontainers/go-digest" ocispecs "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" - "github.com/sirupsen/logrus" "golang.org/x/sync/errgroup" ) @@ -162,7 +162,7 @@ func (ci *contentCacheImporter) importInlineCache(ctx context.Context, dt []byte } if len(img.Rootfs.DiffIDs) != len(m.Layers) { - logrus.Warnf("invalid image with mismatching manifest and config") + bklog.G(ctx).Warnf("invalid image with mismatching manifest and config") return nil } diff --git a/cache/remotecache/inline/inline.go b/cache/remotecache/inline/inline.go index 036ec059f76e..3b7b0c68d2e7 100644 --- a/cache/remotecache/inline/inline.go +++ b/cache/remotecache/inline/inline.go @@ -8,10 +8,10 @@ import ( v1 "github.com/moby/buildkit/cache/remotecache/v1" "github.com/moby/buildkit/session" "github.com/moby/buildkit/solver" + "github.com/moby/buildkit/util/bklog" "github.com/moby/buildkit/util/compression" digest "github.com/opencontainers/go-digest" "github.com/pkg/errors" - "github.com/sirupsen/logrus" ) func ResolveCacheExporterFunc() remotecache.ResolveCacheExporterFunc { @@ -85,7 +85,7 @@ func (ce *exporter) ExportForLayers(ctx context.Context, layers []digest.Digest) } if len(cfg.Layers) == 0 { - logrus.Warn("failed to match any cache with layers") + bklog.G(ctx).Warn("failed to match any cache with layers") return nil, nil } diff --git a/cache/remotecache/v1/chains.go b/cache/remotecache/v1/chains.go index 8c8bbde5dc76..11ea24b865f8 100644 --- a/cache/remotecache/v1/chains.go +++ b/cache/remotecache/v1/chains.go @@ -39,7 +39,7 @@ func (c *CacheChains) Visited(v interface{}) bool { return ok } -func (c *CacheChains) normalize() error { +func (c *CacheChains) normalize(ctx context.Context) error { st := &normalizeState{ added: map[*item]*item{}, links: map[*item]map[nlink]map[digest.Digest]struct{}{}, @@ -66,7 +66,7 @@ func (c *CacheChains) normalize() error { } } - st.removeLoops() + st.removeLoops(ctx) items := make([]*item, 0, len(st.byKey)) for _, it := range st.byKey { @@ -77,7 +77,7 @@ func (c *CacheChains) normalize() error { } func (c *CacheChains) Marshal(ctx context.Context) (*CacheConfig, DescriptorProvider, error) { - if err := c.normalize(); err != nil { + if err := c.normalize(ctx); err != nil { return nil, nil, err } diff --git a/cache/remotecache/v1/utils.go b/cache/remotecache/v1/utils.go index f7139035fabb..213e670a61d2 100644 --- a/cache/remotecache/v1/utils.go +++ b/cache/remotecache/v1/utils.go @@ -6,10 +6,10 @@ import ( "sort" "github.com/moby/buildkit/solver" + "github.com/moby/buildkit/util/bklog" digest "github.com/opencontainers/go-digest" ocispecs "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" - "github.com/sirupsen/logrus" ) // sortConfig sorts the config structure to make sure it is deterministic @@ -128,7 +128,7 @@ type normalizeState struct { next int } -func (s *normalizeState) removeLoops() { +func (s *normalizeState) removeLoops(ctx context.Context) { roots := []digest.Digest{} for dgst, it := range s.byKey { if len(it.links) == 0 { @@ -139,11 +139,11 @@ func (s *normalizeState) removeLoops() { visited := map[digest.Digest]struct{}{} for _, d := range roots { - s.checkLoops(d, visited) + s.checkLoops(ctx, d, visited) } } -func (s *normalizeState) checkLoops(d digest.Digest, visited map[digest.Digest]struct{}) { +func (s *normalizeState) checkLoops(ctx context.Context, d digest.Digest, visited map[digest.Digest]struct{}) { it, ok := s.byKey[d] if !ok { return @@ -165,11 +165,11 @@ func (s *normalizeState) checkLoops(d digest.Digest, visited map[digest.Digest]s continue } if !it2.removeLink(it) { - logrus.Warnf("failed to remove looping cache key %s %s", d, id) + bklog.G(ctx).Warnf("failed to remove looping cache key %s %s", d, id) } delete(links[l], id) } else { - s.checkLoops(id, visited) + s.checkLoops(ctx, id, visited) } } } diff --git a/cmd/buildctl/build.go b/cmd/buildctl/build.go index e7cb1f770d3c..e776a71e4ae8 100644 --- a/cmd/buildctl/build.go +++ b/cmd/buildctl/build.go @@ -22,10 +22,10 @@ import ( "github.com/moby/buildkit/session/sshforward/sshprovider" "github.com/moby/buildkit/solver/pb" spb "github.com/moby/buildkit/sourcepolicy/pb" + "github.com/moby/buildkit/util/bklog" "github.com/moby/buildkit/util/progress/progresswriter" digest "github.com/opencontainers/go-digest" "github.com/pkg/errors" - "github.com/sirupsen/logrus" "github.com/urfave/cli" "golang.org/x/sync/errgroup" ) @@ -154,7 +154,7 @@ func buildAction(clicontext *cli.Context) error { defer traceFile.Close() traceEnc = json.NewEncoder(traceFile) - logrus.Infof("tracing logs to %s", traceFile.Name()) + bklog.L.Infof("tracing logs to %s", traceFile.Name()) } dockerConfig := config.LoadDefaultConfigFile(os.Stderr) @@ -339,7 +339,7 @@ func buildAction(clicontext *cli.Context) error { return err } for k, v := range resp.ExporterResponse { - logrus.Debugf("exporter response: %s=%s", k, v) + bklog.G(ctx).Debugf("exporter response: %s=%s", k, v) } metadataFile := clicontext.String("metadata-file") diff --git a/cmd/buildctl/build/exportcache.go b/cmd/buildctl/build/exportcache.go index ec8b6a24bc4e..19dfe513a8e6 100644 --- a/cmd/buildctl/build/exportcache.go +++ b/cmd/buildctl/build/exportcache.go @@ -5,8 +5,8 @@ import ( "strings" "github.com/moby/buildkit/client" + "github.com/moby/buildkit/util/bklog" "github.com/pkg/errors" - "github.com/sirupsen/logrus" ) func parseExportCacheCSV(s string) (client.CacheOptionsEntry, error) { @@ -51,7 +51,7 @@ func ParseExportCache(exportCaches []string) ([]client.CacheOptionsEntry, error) legacy := !strings.Contains(exportCache, "type=") if legacy { // Deprecated since BuildKit v0.4.0, but no plan to remove: https://github.com/moby/buildkit/pull/2783#issuecomment-1093449772 - logrus.Warnf("--export-cache is deprecated. Please use --export-cache type=registry,ref=,=[,=] instead") + bklog.L.Warnf("--export-cache is deprecated. Please use --export-cache type=registry,ref=,=[,=] instead") exports = append(exports, client.CacheOptionsEntry{ Type: "registry", Attrs: map[string]string{ diff --git a/cmd/buildctl/build/importcache.go b/cmd/buildctl/build/importcache.go index b91eb36490c9..dcccf6941bda 100644 --- a/cmd/buildctl/build/importcache.go +++ b/cmd/buildctl/build/importcache.go @@ -5,8 +5,8 @@ import ( "strings" "github.com/moby/buildkit/client" + "github.com/moby/buildkit/util/bklog" "github.com/pkg/errors" - "github.com/sirupsen/logrus" ) func parseImportCacheCSV(s string) (client.CacheOptionsEntry, error) { @@ -48,7 +48,7 @@ func ParseImportCache(importCaches []string) ([]client.CacheOptionsEntry, error) legacy := !strings.Contains(importCache, "type=") if legacy { // Deprecated since BuildKit v0.4.0, but no plan to remove: https://github.com/moby/buildkit/pull/2783#issuecomment-1093449772 - logrus.Warn("--import-cache is deprecated. Please use --import-cache type=registry,ref=,=[,=] instead.") + bklog.L.Warn("--import-cache is deprecated. Please use --import-cache type=registry,ref=,=[,=] instead.") imports = append(imports, client.CacheOptionsEntry{ Type: "registry", Attrs: map[string]string{"ref": importCache}, diff --git a/cmd/buildctl/debug/workers.go b/cmd/buildctl/debug/workers.go index 9a68d34d532b..0a692eb0c6d0 100644 --- a/cmd/buildctl/debug/workers.go +++ b/cmd/buildctl/debug/workers.go @@ -11,8 +11,8 @@ import ( "github.com/containerd/containerd/platforms" "github.com/moby/buildkit/client" bccommon "github.com/moby/buildkit/cmd/buildctl/common" + "github.com/moby/buildkit/util/bklog" ocispecs "github.com/opencontainers/image-spec/specs-go/v1" - "github.com/sirupsen/logrus" "github.com/tonistiigi/units" "github.com/urfave/cli" ) @@ -49,7 +49,7 @@ func listWorkers(clicontext *cli.Context) error { } if format := clicontext.String("format"); format != "" { if clicontext.Bool("verbose") { - logrus.Debug("Ignoring --verbose") + bklog.L.Debug("Ignoring --verbose") } tmpl, err := bccommon.ParseTemplate(format) if err != nil { diff --git a/cmd/buildctl/dialstdio.go b/cmd/buildctl/dialstdio.go index 9539f6f4559d..08fcb6141a2f 100644 --- a/cmd/buildctl/dialstdio.go +++ b/cmd/buildctl/dialstdio.go @@ -7,8 +7,8 @@ import ( "strings" "time" + "github.com/moby/buildkit/util/bklog" "github.com/pkg/errors" - "github.com/sirupsen/logrus" "github.com/urfave/cli" ) @@ -74,10 +74,10 @@ func dialer(address string, timeout time.Duration) (net.Conn, error) { func copier(to halfWriteCloser, from halfReadCloser, debugDescription string) error { defer func() { if err := from.CloseRead(); err != nil { - logrus.Errorf("error while CloseRead (%s): %v", debugDescription, err) + bklog.L.Errorf("error while CloseRead (%s): %v", debugDescription, err) } if err := to.CloseWrite(); err != nil { - logrus.Errorf("error while CloseWrite (%s): %v", debugDescription, err) + bklog.L.Errorf("error while CloseWrite (%s): %v", debugDescription, err) } }() if _, err := io.Copy(to, from); err != nil { diff --git a/cmd/buildctl/diskusage.go b/cmd/buildctl/diskusage.go index 8c00fcfe4e77..b474bd99fffb 100644 --- a/cmd/buildctl/diskusage.go +++ b/cmd/buildctl/diskusage.go @@ -9,7 +9,7 @@ import ( "github.com/moby/buildkit/client" bccommon "github.com/moby/buildkit/cmd/buildctl/common" - "github.com/sirupsen/logrus" + "github.com/moby/buildkit/util/bklog" "github.com/tonistiigi/units" "github.com/urfave/cli" ) @@ -47,7 +47,7 @@ func diskUsage(clicontext *cli.Context) error { if format := clicontext.String("format"); format != "" { if clicontext.Bool("verbose") { - logrus.Debug("Ignoring --verbose") + bklog.L.Debug("Ignoring --verbose") } tmpl, err := bccommon.ParseTemplate(format) if err != nil { diff --git a/cmd/buildctl/prune.go b/cmd/buildctl/prune.go index 31c917262514..25aa27c55c7f 100644 --- a/cmd/buildctl/prune.go +++ b/cmd/buildctl/prune.go @@ -7,7 +7,7 @@ import ( "github.com/moby/buildkit/client" bccommon "github.com/moby/buildkit/cmd/buildctl/common" - "github.com/sirupsen/logrus" + "github.com/moby/buildkit/util/bklog" "github.com/tonistiigi/units" "github.com/urfave/cli" ) @@ -65,7 +65,7 @@ func prune(clicontext *cli.Context) error { if format := clicontext.String("format"); format != "" { if clicontext.Bool("verbose") { - logrus.Debug("Ignoring --verbose") + bklog.L.Debug("Ignoring --verbose") } tmpl, err := bccommon.ParseTemplate(format) if err != nil { diff --git a/cmd/buildkitd/debug.go b/cmd/buildkitd/debug.go index 9cbd8df76211..80e87a6f81ab 100644 --- a/cmd/buildkitd/debug.go +++ b/cmd/buildkitd/debug.go @@ -8,7 +8,7 @@ import ( "runtime" "time" - "github.com/sirupsen/logrus" + "github.com/moby/buildkit/util/bklog" "golang.org/x/net/trace" ) @@ -25,7 +25,7 @@ func setupDebugHandlers(addr string) error { m.Handle("/debug/gc", http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { runtime.GC() - logrus.Debugf("triggered GC from debug endpoint") + bklog.G(req.Context()).Debugf("triggered GC from debug endpoint") })) // setting debugaddr is opt-in. permission is defined by listener address @@ -42,7 +42,7 @@ func setupDebugHandlers(addr string) error { Handler: m, ReadHeaderTimeout: time.Minute, } - logrus.Debugf("debug handlers listening at %s", addr) + bklog.L.Debugf("debug handlers listening at %s", addr) go server.ListenAndServe() return nil } diff --git a/cmd/buildkitd/main.go b/cmd/buildkitd/main.go index 1d48831dd20e..166070d18df7 100644 --- a/cmd/buildkitd/main.go +++ b/cmd/buildkitd/main.go @@ -347,13 +347,13 @@ func serveGRPC(cfg config.GRPCConfig, server *grpc.Server, errCh chan error) err if os.Getenv("NOTIFY_SOCKET") != "" { notified, notifyErr := sddaemon.SdNotify(false, sddaemon.SdNotifyReady) - logrus.Debugf("SdNotifyReady notified=%v, err=%v", notified, notifyErr) + bklog.L.Debugf("SdNotifyReady notified=%v, err=%v", notified, notifyErr) } for _, l := range listeners { func(l net.Listener) { eg.Go(func() error { defer l.Close() - logrus.Infof("running server on %s", l.Addr()) + bklog.L.Infof("running server on %s", l.Addr()) return server.Serve(l) }) }(l) @@ -378,7 +378,7 @@ func defaultConf() (config.Config, error) { if !errors.As(err, &pe) { return config.Config{}, err } - logrus.Warnf("failed to load default config: %v", err) + bklog.L.Warnf("failed to load default config: %v", err) } setDefaultConfig(&cfg) @@ -530,7 +530,7 @@ func getListener(addr string, uid, gid int, tlsConfig *tls.Config) (net.Listener switch proto { case "unix", "npipe": if tlsConfig != nil { - logrus.Warnf("TLS is disabled for %s", addr) + bklog.L.Warnf("TLS is disabled for %s", addr) } return sys.GetLocalListener(listenAddr, uid, gid) case "fd": @@ -542,7 +542,7 @@ func getListener(addr string, uid, gid int, tlsConfig *tls.Config) (net.Listener } if tlsConfig == nil { - logrus.Warnf("TLS is not enabled for %s. enabling mutual TLS authentication is highly recommended", addr) + bklog.L.Warnf("TLS is not enabled for %s. enabling mutual TLS authentication is highly recommended", addr) return l, nil } return tls.NewListener(l, tlsConfig), nil @@ -572,7 +572,7 @@ func unaryInterceptor(globalCtx context.Context, tp trace.TracerProvider) grpc.U resp, err = withTrace(ctx, req, info, handler) if err != nil { - logrus.Errorf("%s returned error: %v", info.FullMethod, err) + bklog.G(ctx).Errorf("%s returned error: %v", info.FullMethod, err) if logrus.GetLevel() >= logrus.DebugLevel { fmt.Fprintf(os.Stderr, "%+v", stack.Formatter(grpcerrors.FromGRPC(err))) } @@ -711,7 +711,7 @@ func newWorkerController(c *cli.Context, wiOpt workerInitializerOpt) (*worker.Co } for _, w := range ws { p := w.Platforms(false) - logrus.Infof("found worker %q, labels=%v, platforms=%v", w.ID(), w.Labels(), formatPlatforms(p)) + bklog.L.Infof("found worker %q, labels=%v, platforms=%v", w.ID(), w.Labels(), formatPlatforms(p)) archutil.WarnIfUnsupported(p) if err = wc.Add(w); err != nil { return nil, err @@ -726,8 +726,8 @@ func newWorkerController(c *cli.Context, wiOpt workerInitializerOpt) (*worker.Co if err != nil { return nil, err } - logrus.Infof("found %d workers, default=%q", nWorkers, defaultWorker.ID()) - logrus.Warn("currently, only the default worker can be used.") + bklog.L.Infof("found %d workers, default=%q", nWorkers, defaultWorker.ID()) + bklog.L.Warn("currently, only the default worker can be used.") return wc, nil } diff --git a/cmd/buildkitd/main_containerd_worker.go b/cmd/buildkitd/main_containerd_worker.go index 7992b1bf87ac..985a9846d511 100644 --- a/cmd/buildkitd/main_containerd_worker.go +++ b/cmd/buildkitd/main_containerd_worker.go @@ -13,13 +13,13 @@ import ( ctd "github.com/containerd/containerd" "github.com/containerd/containerd/pkg/userns" "github.com/moby/buildkit/cmd/buildkitd/config" + "github.com/moby/buildkit/util/bklog" "github.com/moby/buildkit/util/network/cniprovider" "github.com/moby/buildkit/util/network/netproviders" "github.com/moby/buildkit/worker" "github.com/moby/buildkit/worker/base" "github.com/moby/buildkit/worker/containerd" "github.com/pkg/errors" - "github.com/sirupsen/logrus" "github.com/urfave/cli" "golang.org/x/sync/semaphore" ) @@ -247,7 +247,7 @@ func containerdWorkerInitializer(c *cli.Context, common workerInitializerOpt) ([ } if cfg.Rootless { - logrus.Debugf("running in rootless mode") + bklog.L.Debugf("running in rootless mode") if common.config.Workers.Containerd.NetworkConfig.Mode == "auto" { common.config.Workers.Containerd.NetworkConfig.Mode = "host" } @@ -305,16 +305,16 @@ func validContainerdSocket(cfg config.ContainerdConfig) bool { socketPath := strings.TrimPrefix(socket, "unix://") if _, err := os.Stat(socketPath); errors.Is(err, os.ErrNotExist) { // FIXME(AkihiroSuda): add more conditions - logrus.Warnf("skipping containerd worker, as %q does not exist", socketPath) + bklog.L.Warnf("skipping containerd worker, as %q does not exist", socketPath) return false } c, err := ctd.New(socketPath, ctd.WithDefaultNamespace(cfg.Namespace)) if err != nil { - logrus.Warnf("skipping containerd worker, as failed to connect client to %q: %v", socketPath, err) + bklog.L.Warnf("skipping containerd worker, as failed to connect client to %q: %v", socketPath, err) return false } if _, err := c.Server(context.Background()); err != nil { - logrus.Warnf("skipping containerd worker, as failed to call introspection API on %q: %v", socketPath, err) + bklog.L.Warnf("skipping containerd worker, as failed to call introspection API on %q: %v", socketPath, err) return false } return true diff --git a/cmd/buildkitd/main_oci_worker.go b/cmd/buildkitd/main_oci_worker.go index 64cedacea156..81b836193a22 100644 --- a/cmd/buildkitd/main_oci_worker.go +++ b/cmd/buildkitd/main_oci_worker.go @@ -33,6 +33,7 @@ import ( "github.com/moby/buildkit/cmd/buildkitd/config" "github.com/moby/buildkit/executor/oci" "github.com/moby/buildkit/session" + "github.com/moby/buildkit/util/bklog" "github.com/moby/buildkit/util/network/cniprovider" "github.com/moby/buildkit/util/network/netproviders" "github.com/moby/buildkit/util/resolver" @@ -275,7 +276,7 @@ func ociWorkerInitializer(c *cli.Context, common workerInitializerOpt) ([]worker } if cfg.Rootless { - logrus.Debugf("running in rootless mode") + bklog.L.Debugf("running in rootless mode") if common.config.Workers.OCI.NetworkConfig.Mode == "auto" { common.config.Workers.OCI.NetworkConfig.Mode = "host" } @@ -283,7 +284,7 @@ func ociWorkerInitializer(c *cli.Context, common workerInitializerOpt) ([]worker processMode := oci.ProcessSandbox if cfg.NoProcessSandbox { - logrus.Warn("NoProcessSandbox is enabled. Note that NoProcessSandbox allows build containers to kill (and potentially ptrace) an arbitrary process in the BuildKit host namespace. NoProcessSandbox should be enabled only when the BuildKit is running in a container as an unprivileged user.") + bklog.L.Warn("NoProcessSandbox is enabled. Note that NoProcessSandbox allows build containers to kill (and potentially ptrace) an arbitrary process in the BuildKit host namespace. NoProcessSandbox should be enabled only when the BuildKit is running in a container as an unprivileged user.") if !cfg.Rootless { return nil, errors.New("can't enable NoProcessSandbox without Rootless") } @@ -367,15 +368,15 @@ func snapshotterFactory(commonRoot string, cfg config.OCIConfig, sm *session.Man if err := overlayutils.Supported(commonRoot); err == nil { name = "overlayfs" } else { - logrus.Debugf("auto snapshotter: overlayfs is not available for %s, trying fuse-overlayfs: %v", commonRoot, err) + bklog.L.Debugf("auto snapshotter: overlayfs is not available for %s, trying fuse-overlayfs: %v", commonRoot, err) if err2 := fuseoverlayfs.Supported(commonRoot); err2 == nil { name = "fuse-overlayfs" } else { - logrus.Debugf("auto snapshotter: fuse-overlayfs is not available for %s, falling back to native: %v", commonRoot, err2) + bklog.L.Debugf("auto snapshotter: fuse-overlayfs is not available for %s, falling back to native: %v", commonRoot, err2) name = "native" } } - logrus.Infof("auto snapshotter: using %s", name) + bklog.L.Infof("auto snapshotter: using %s", name) } snFactory := runc.SnapshotterFactory{ @@ -412,7 +413,7 @@ func snapshotterFactory(commonRoot string, cfg config.OCIConfig, sm *session.Man snFactory.New = func(root string) (ctdsnapshot.Snapshotter, error) { userxattr, err := overlayutils.NeedsUserXAttr(root) if err != nil { - logrus.WithError(err).Warnf("cannot detect whether \"userxattr\" option needs to be used, assuming to be %v", userxattr) + bklog.L.WithError(err).Warnf("cannot detect whether \"userxattr\" option needs to be used, assuming to be %v", userxattr) } opq := sgzlayer.OverlayOpaqueTrusted if userxattr { @@ -442,7 +443,7 @@ func validOCIBinary() bool { _, err := exec.LookPath("runc") _, err1 := exec.LookPath("buildkit-runc") if err != nil && err1 != nil { - logrus.Warnf("skipping oci worker, as runc does not exist") + bklog.L.Warnf("skipping oci worker, as runc does not exist") return false } return true diff --git a/cmd/buildkitd/util_linux.go b/cmd/buildkitd/util_linux.go index cfbc0a5c99c3..2fda61c91d40 100644 --- a/cmd/buildkitd/util_linux.go +++ b/cmd/buildkitd/util_linux.go @@ -4,8 +4,8 @@ import ( "strings" "github.com/docker/docker/pkg/idtools" + "github.com/moby/buildkit/util/bklog" "github.com/pkg/errors" - "github.com/sirupsen/logrus" ) func parseIdentityMapping(str string) (*idtools.IdentityMapping, error) { @@ -20,7 +20,7 @@ func parseIdentityMapping(str string) (*idtools.IdentityMapping, error) { username := idparts[0] - logrus.Debugf("user namespaces: ID ranges will be mapped to subuid ranges of: %s", username) + bklog.L.Debugf("user namespaces: ID ranges will be mapped to subuid ranges of: %s", username) mappings, err := idtools.LoadIdentityMapping(username) if err != nil { diff --git a/executor/containerdexecutor/executor.go b/executor/containerdexecutor/executor.go index ac195c431588..6a6033df5de0 100644 --- a/executor/containerdexecutor/executor.go +++ b/executor/containerdexecutor/executor.go @@ -135,7 +135,7 @@ func (w *containerdExecutor) Run(ctx context.Context, id string, root executor.M return err } defer lm.Unmount() - defer executor.MountStubsCleaner(rootfsPath, mounts, meta.RemoveMountStubsRecursive)() + defer executor.MountStubsCleaner(ctx, rootfsPath, mounts, meta.RemoveMountStubsRecursive)() uid, gid, sgids, err := oci.GetUser(rootfsPath, meta.User) if err != nil { diff --git a/executor/runcexecutor/executor.go b/executor/runcexecutor/executor.go index 213ebb73665a..2fe954b12153 100644 --- a/executor/runcexecutor/executor.go +++ b/executor/runcexecutor/executor.go @@ -224,7 +224,7 @@ func (w *runcExecutor) Run(ctx context.Context, id string, root executor.Mount, } defer mount.Unmount(rootFSPath, 0) - defer executor.MountStubsCleaner(rootFSPath, mounts, meta.RemoveMountStubsRecursive)() + defer executor.MountStubsCleaner(ctx, rootFSPath, mounts, meta.RemoveMountStubsRecursive)() uid, gid, sgids, err := oci.GetUser(rootFSPath, meta.User) if err != nil { diff --git a/executor/stubs.go b/executor/stubs.go index 22a8ac1310c4..e2ac460e2015 100644 --- a/executor/stubs.go +++ b/executor/stubs.go @@ -1,17 +1,18 @@ package executor import ( + "context" "errors" "os" "path/filepath" "syscall" "github.com/containerd/continuity/fs" + "github.com/moby/buildkit/util/bklog" "github.com/moby/buildkit/util/system" - "github.com/sirupsen/logrus" ) -func MountStubsCleaner(dir string, mounts []Mount, recursive bool) func() { +func MountStubsCleaner(ctx context.Context, dir string, mounts []Mount, recursive bool) func() { names := []string{"/etc/resolv.conf", "/etc/hosts"} for _, m := range mounts { @@ -72,23 +73,23 @@ func MountStubsCleaner(dir string, mounts []Mount, recursive bool) func() { dir := filepath.Dir(p) dirSt, err := os.Stat(dir) if err != nil { - logrus.WithError(err).Warnf("Failed to stat %q (parent of mount stub %q)", dir, p) + bklog.G(ctx).WithError(err).Warnf("Failed to stat %q (parent of mount stub %q)", dir, p) continue } mtime := dirSt.ModTime() atime, err := system.Atime(dirSt) if err != nil { - logrus.WithError(err).Warnf("Failed to stat atime of %q (parent of mount stub %q)", dir, p) + bklog.G(ctx).WithError(err).Warnf("Failed to stat atime of %q (parent of mount stub %q)", dir, p) atime = mtime } if err := os.Remove(p); err != nil { - logrus.WithError(err).Warnf("Failed to remove mount stub %q", p) + bklog.G(ctx).WithError(err).Warnf("Failed to remove mount stub %q", p) } // Restore the timestamps of the dir if err := os.Chtimes(dir, atime, mtime); err != nil { - logrus.WithError(err).Warnf("Failed to restore time time mount stub timestamp (os.Chtimes(%q, %v, %v))", dir, atime, mtime) + bklog.G(ctx).WithError(err).Warnf("Failed to restore time time mount stub timestamp (os.Chtimes(%q, %v, %v))", dir, atime, mtime) } } } diff --git a/exporter/containerimage/export.go b/exporter/containerimage/export.go index c69f9d22a705..96692d567fa1 100644 --- a/exporter/containerimage/export.go +++ b/exporter/containerimage/export.go @@ -83,7 +83,7 @@ func (e *imageExporter) Resolve(ctx context.Context, opt map[string]string) (exp store: true, } - opt, err := i.opts.Load(opt) + opt, err := i.opts.Load(ctx, opt) if err != nil { return nil, err } diff --git a/exporter/containerimage/opts.go b/exporter/containerimage/opts.go index dececd6acedc..edc1959e0f0b 100644 --- a/exporter/containerimage/opts.go +++ b/exporter/containerimage/opts.go @@ -1,14 +1,15 @@ package containerimage import ( + "context" "strconv" "time" cacheconfig "github.com/moby/buildkit/cache/config" "github.com/moby/buildkit/exporter/util/epoch" + "github.com/moby/buildkit/util/bklog" "github.com/moby/buildkit/util/compression" "github.com/pkg/errors" - "github.com/sirupsen/logrus" ) const ( @@ -32,7 +33,7 @@ type ImageCommitOpts struct { ForceInlineAttestations bool // force inline attestations to be attached } -func (c *ImageCommitOpts) Load(opt map[string]string) (map[string]string, error) { +func (c *ImageCommitOpts) Load(ctx context.Context, opt map[string]string) (map[string]string, error) { rest := make(map[string]string) as, optb, err := ParseAnnotations(toBytesMap(opt)) @@ -71,11 +72,11 @@ func (c *ImageCommitOpts) Load(opt map[string]string) (map[string]string, error) } if c.RefCfg.Compression.Type.OnlySupportOCITypes() { - c.EnableOCITypes(c.RefCfg.Compression.Type.String()) + c.EnableOCITypes(ctx, c.RefCfg.Compression.Type.String()) } if c.RefCfg.Compression.Type.NeedsForceCompression() { - c.EnableForceCompression(c.RefCfg.Compression.Type.String()) + c.EnableForceCompression(ctx, c.RefCfg.Compression.Type.String()) } c.Annotations = c.Annotations.Merge(as) @@ -83,25 +84,25 @@ func (c *ImageCommitOpts) Load(opt map[string]string) (map[string]string, error) return rest, nil } -func (c *ImageCommitOpts) EnableOCITypes(reason string) { +func (c *ImageCommitOpts) EnableOCITypes(ctx context.Context, reason string) { if !c.OCITypes { message := "forcibly turning on oci-mediatype mode" if reason != "" { message += " for " + reason } - logrus.Warn(message) + bklog.G(ctx).Warn(message) c.OCITypes = true } } -func (c *ImageCommitOpts) EnableForceCompression(reason string) { +func (c *ImageCommitOpts) EnableForceCompression(ctx context.Context, reason string) { if !c.RefCfg.Compression.Force { message := "forcibly turning on force-compression mode" if reason != "" { message += " for " + reason } - logrus.Warn(message) + bklog.G(ctx).Warn(message) c.RefCfg.Compression.Force = true } diff --git a/exporter/containerimage/writer.go b/exporter/containerimage/writer.go index 930fdc61c079..02988ecc0c13 100644 --- a/exporter/containerimage/writer.go +++ b/exporter/containerimage/writer.go @@ -100,7 +100,7 @@ func (ic *ImageWriter) Commit(ctx context.Context, inp *exporter.Source, session } } if len(a.Index)+len(a.IndexDescriptor)+len(a.ManifestDescriptor) > 0 { - opts.EnableOCITypes("annotations") + opts.EnableOCITypes(ctx, "annotations") } } @@ -148,7 +148,7 @@ func (ic *ImageWriter) Commit(ctx context.Context, inp *exporter.Source, session } if len(inp.Attestations) > 0 { - opts.EnableOCITypes("attestations") + opts.EnableOCITypes(ctx, "attestations") } refs := make([]cache.ImmutableRef, 0, len(inp.Refs)) @@ -722,7 +722,7 @@ func normalizeLayersAndHistory(ctx context.Context, remote *solver.Remote, histo } // convert between oci and docker media types (or vice versa) if needed - remote.Descriptors = compression.ConvertAllLayerMediaTypes(oci, remote.Descriptors...) + remote.Descriptors = compression.ConvertAllLayerMediaTypes(ctx, oci, remote.Descriptors...) return remote, history } diff --git a/exporter/oci/export.go b/exporter/oci/export.go index da7aace2ba2d..202e260c47bb 100644 --- a/exporter/oci/export.go +++ b/exporter/oci/export.go @@ -71,7 +71,7 @@ func (e *imageExporter) Resolve(ctx context.Context, opt map[string]string) (exp }, } - opt, err := i.opts.Load(opt) + opt, err := i.opts.Load(ctx, opt) if err != nil { return nil, err } diff --git a/frontend/dockerfile/cmd/dockerfile-frontend/main.go b/frontend/dockerfile/cmd/dockerfile-frontend/main.go index 4e2dc6dddecd..a44b9d1abd69 100644 --- a/frontend/dockerfile/cmd/dockerfile-frontend/main.go +++ b/frontend/dockerfile/cmd/dockerfile-frontend/main.go @@ -8,8 +8,8 @@ import ( dockerfile "github.com/moby/buildkit/frontend/dockerfile/builder" "github.com/moby/buildkit/frontend/gateway/grpcclient" "github.com/moby/buildkit/util/appcontext" + "github.com/moby/buildkit/util/bklog" "github.com/moby/buildkit/util/stack" - "github.com/sirupsen/logrus" ) func init() { @@ -27,7 +27,7 @@ func main() { } if err := grpcclient.RunFromEnvironment(appcontext.Context(), dockerfile.Build); err != nil { - logrus.Errorf("fatal error: %+v", err) + bklog.L.Errorf("fatal error: %+v", err) panic(err) } } diff --git a/frontend/gateway/gateway.go b/frontend/gateway/gateway.go index 36d46b6faa28..5f42edee55e1 100644 --- a/frontend/gateway/gateway.go +++ b/frontend/gateway/gateway.go @@ -1324,7 +1324,7 @@ func (lbf *llbBridgeForwarder) ExecProcess(srv pb.LLBBridge_ExecProcessServer) e var statusError *rpc.Status if err != nil { statusCode = pb.UnknownExitStatus - st, _ := status.FromError(grpcerrors.ToGRPC(err)) + st, _ := status.FromError(grpcerrors.ToGRPC(ctx, err)) stp := st.Proto() statusError = &rpc.Status{ Code: stp.Code, diff --git a/frontend/gateway/grpcclient/client.go b/frontend/gateway/grpcclient/client.go index acc3cd6885ee..b37db2d4b82f 100644 --- a/frontend/gateway/grpcclient/client.go +++ b/frontend/gateway/grpcclient/client.go @@ -190,7 +190,7 @@ func (c *grpcClient) Run(ctx context.Context, f client.BuildFunc) (retError erro } } if retError != nil { - st, _ := status.FromError(grpcerrors.ToGRPC(retError)) + st, _ := status.FromError(grpcerrors.ToGRPC(ctx, retError)) stp := st.Proto() req.Error = &rpc.Status{ Code: stp.Code, diff --git a/solver/llbsolver/solver.go b/solver/llbsolver/solver.go index efde7df3aed0..b80e19773885 100644 --- a/solver/llbsolver/solver.go +++ b/solver/llbsolver/solver.go @@ -27,6 +27,7 @@ import ( "github.com/moby/buildkit/solver/result" spb "github.com/moby/buildkit/sourcepolicy/pb" "github.com/moby/buildkit/util/attestation" + "github.com/moby/buildkit/util/bklog" "github.com/moby/buildkit/util/compression" "github.com/moby/buildkit/util/entitlements" "github.com/moby/buildkit/util/grpcerrors" @@ -35,7 +36,6 @@ import ( "github.com/moby/buildkit/worker" digest "github.com/opencontainers/go-digest" "github.com/pkg/errors" - "github.com/sirupsen/logrus" "go.opentelemetry.io/otel/sdk/trace/tracetest" "go.opentelemetry.io/otel/trace" "golang.org/x/sync/errgroup" @@ -331,7 +331,7 @@ func (s *Solver) recordBuildHistory(ctx context.Context, id string, req frontend }() if err != nil { - st, ok := grpcerrors.AsGRPCStatus(grpcerrors.ToGRPC(err)) + st, ok := grpcerrors.AsGRPCStatus(grpcerrors.ToGRPC(ctx, err)) if !ok { st = status.New(codes.Unknown, err.Error()) } @@ -347,7 +347,7 @@ func (s *Solver) recordBuildHistory(ctx context.Context, id string, req frontend } if stopTrace == nil { - logrus.Warn("no trace recorder found, skipping") + bklog.G(ctx).Warn("no trace recorder found, skipping") return err } go func() { @@ -389,7 +389,7 @@ func (s *Solver) recordBuildHistory(ctx context.Context, id string, req frontend } return nil }(); err != nil { - logrus.Errorf("failed to save trace for %s: %+v", id, err) + bklog.G(ctx).Errorf("failed to save trace for %s: %+v", id, err) } }() @@ -872,6 +872,7 @@ func defaultResolver(wc *worker.Controller) ResolveWorkerFunc { return wc.GetDefault() } } + func allWorkers(wc *worker.Controller) func(func(w worker.Worker) error) error { return func(f func(worker.Worker) error) error { all, err := wc.List() diff --git a/util/appcontext/appcontext.go b/util/appcontext/appcontext.go index 3c67f9236297..f9cf0ba8fb60 100644 --- a/util/appcontext/appcontext.go +++ b/util/appcontext/appcontext.go @@ -6,7 +6,7 @@ import ( "os/signal" "sync" - "github.com/sirupsen/logrus" + "github.com/moby/buildkit/util/bklog" ) var appContextCache context.Context @@ -36,7 +36,7 @@ func Context() context.Context { cancel() retries++ if retries >= exitLimit { - logrus.Errorf("got %d SIGTERM/SIGINTs, forcing shutdown", retries) + bklog.G(ctx).Errorf("got %d SIGTERM/SIGINTs, forcing shutdown", retries) os.Exit(1) } } diff --git a/util/archutil/detect.go b/util/archutil/detect.go index 3184f9e548fb..7826441271fd 100644 --- a/util/archutil/detect.go +++ b/util/archutil/detect.go @@ -6,8 +6,8 @@ import ( "sync" "github.com/containerd/containerd/platforms" + "github.com/moby/buildkit/util/bklog" ocispecs "github.com/opencontainers/image-spec/specs-go/v1" - "github.com/sirupsen/logrus" ) var mu sync.Mutex @@ -181,10 +181,10 @@ func amd64vector(v string) (out []string) { func printPlatformWarning(p ocispecs.Platform, err error) { if strings.Contains(err.Error(), "exec format error") { - logrus.Warnf("platform %s cannot pass the validation, kernel support for miscellaneous binary may have not enabled.", platforms.Format(p)) + bklog.L.Warnf("platform %s cannot pass the validation, kernel support for miscellaneous binary may have not enabled.", platforms.Format(p)) } else if strings.Contains(err.Error(), "no such file or directory") { - logrus.Warnf("platforms %s cannot pass the validation, '-F' flag might have not set for 'archutil'.", platforms.Format(p)) + bklog.L.Warnf("platforms %s cannot pass the validation, '-F' flag might have not set for 'archutil'.", platforms.Format(p)) } else { - logrus.Warnf("platforms %s cannot pass the validation: %s", platforms.Format(p), err.Error()) + bklog.L.Warnf("platforms %s cannot pass the validation: %s", platforms.Format(p), err.Error()) } } diff --git a/util/compression/compression.go b/util/compression/compression.go index 39603a2a5389..a262523877e9 100644 --- a/util/compression/compression.go +++ b/util/compression/compression.go @@ -9,11 +9,11 @@ import ( "github.com/containerd/containerd/content" "github.com/containerd/containerd/images" "github.com/containerd/stargz-snapshotter/estargz" + "github.com/moby/buildkit/util/bklog" "github.com/moby/buildkit/util/iohelper" digest "github.com/opencontainers/go-digest" ocispecs "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" - "github.com/sirupsen/logrus" ) type Compressor func(dest io.Writer, mediaType string) (io.WriteCloser, error) @@ -211,7 +211,7 @@ var toOCILayerType = map[string]string{ mediaTypeDockerSchema2LayerZstd: mediaTypeImageLayerZstd, } -func convertLayerMediaType(mediaType string, oci bool) string { +func convertLayerMediaType(ctx context.Context, mediaType string, oci bool) string { var converted string if oci { converted = toOCILayerType[mediaType] @@ -219,16 +219,16 @@ func convertLayerMediaType(mediaType string, oci bool) string { converted = toDockerLayerType[mediaType] } if converted == "" { - logrus.Warnf("unhandled conversion for mediatype %q", mediaType) + bklog.G(ctx).Warnf("unhandled conversion for mediatype %q", mediaType) return mediaType } return converted } -func ConvertAllLayerMediaTypes(oci bool, descs ...ocispecs.Descriptor) []ocispecs.Descriptor { +func ConvertAllLayerMediaTypes(ctx context.Context, oci bool, descs ...ocispecs.Descriptor) []ocispecs.Descriptor { var converted []ocispecs.Descriptor for _, desc := range descs { - desc.MediaType = convertLayerMediaType(desc.MediaType, oci) + desc.MediaType = convertLayerMediaType(ctx, desc.MediaType, oci) converted = append(converted, desc) } return converted diff --git a/util/entitlements/security/security_linux.go b/util/entitlements/security/security_linux.go index c53a24b865ab..9ab9398013ab 100644 --- a/util/entitlements/security/security_linux.go +++ b/util/entitlements/security/security_linux.go @@ -10,16 +10,16 @@ import ( "github.com/containerd/containerd/oci" "github.com/containerd/containerd/pkg/cap" "github.com/containerd/containerd/pkg/userns" + "github.com/moby/buildkit/util/bklog" specs "github.com/opencontainers/runtime-spec/specs-go" "github.com/pkg/errors" - "github.com/sirupsen/logrus" "golang.org/x/sys/unix" ) // WithInsecureSpec sets spec with All capability. func WithInsecureSpec() oci.SpecOpts { - return func(_ context.Context, _ oci.Client, _ *containers.Container, s *specs.Spec) error { - addCaps, err := getAllCaps() + return func(ctx context.Context, _ oci.Client, _ *containers.Container, s *specs.Spec) error { + addCaps, err := getAllCaps(ctx) if err != nil { return err } @@ -96,7 +96,7 @@ func WithInsecureSpec() oci.SpecOpts { loopID, err := getFreeLoopID() if err != nil { - logrus.Debugf("failed to get next free loop device: %v", err) + bklog.G(ctx).Debugf("failed to get next free loop device: %v", err) } for i := 0; i <= loopID+7; i++ { @@ -142,7 +142,7 @@ func getCurrentCaps() ([]string, error) { return currentCaps, currentCapsError } -func getAllCaps() ([]string, error) { +func getAllCaps(ctx context.Context) ([]string, error) { availableCaps, err := getCurrentCaps() if err != nil { return nil, errors.Errorf("error getting current capabilities: %s", err) @@ -152,7 +152,7 @@ func getAllCaps() ([]string, error) { // they are either not supported by the kernel or dropped at the process level for _, cap := range availableCaps { if _, exists := linux35Caps[cap]; !exists { - logrus.Warnf("capability %s could not be granted for insecure mode", cap) + bklog.G(ctx).Warnf("capability %s could not be granted for insecure mode", cap) } } diff --git a/util/grpcerrors/grpcerrors.go b/util/grpcerrors/grpcerrors.go index 23588f5eef2e..710bc1ec8b5a 100644 --- a/util/grpcerrors/grpcerrors.go +++ b/util/grpcerrors/grpcerrors.go @@ -1,6 +1,7 @@ package grpcerrors import ( + "context" "encoding/json" "errors" @@ -9,8 +10,8 @@ import ( gogotypes "github.com/gogo/protobuf/types" "github.com/golang/protobuf/proto" //nolint:staticcheck "github.com/golang/protobuf/ptypes/any" + "github.com/moby/buildkit/util/bklog" "github.com/moby/buildkit/util/stack" - "github.com/sirupsen/logrus" spb "google.golang.org/genproto/googleapis/rpc/status" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -25,7 +26,7 @@ type TypedErrorProto interface { WrapError(error) error } -func ToGRPC(err error) error { +func ToGRPC(ctx context.Context, err error) error { if err == nil { return nil } @@ -64,7 +65,7 @@ func ToGRPC(err error) error { }) if len(details) > 0 { - if st2, err := withDetails(st, details...); err == nil { + if st2, err := withDetails(ctx, st, details...); err == nil { st = st2 } } @@ -72,7 +73,7 @@ func ToGRPC(err error) error { return st.Err() } -func withDetails(s *status.Status, details ...proto.Message) (*status.Status, error) { +func withDetails(ctx context.Context, s *status.Status, details ...proto.Message) (*status.Status, error) { if s.Code() == codes.OK { return nil, errors.New("no error details for status with code OK") } @@ -80,7 +81,7 @@ func withDetails(s *status.Status, details ...proto.Message) (*status.Status, er for _, detail := range details { url, err := typeurl.TypeURL(detail) if err != nil { - logrus.Warnf("ignoring typed error %T: not registered", detail) + bklog.G(ctx).Warnf("ignoring typed error %T: not registered", detail) continue } dt, err := json.Marshal(detail) diff --git a/util/grpcerrors/intercept.go b/util/grpcerrors/intercept.go index 1c17e4c67d27..a59207891093 100644 --- a/util/grpcerrors/intercept.go +++ b/util/grpcerrors/intercept.go @@ -15,7 +15,7 @@ func UnaryServerInterceptor(ctx context.Context, req interface{}, info *grpc.Una oldErr := err if err != nil { stack.Helper() - err = ToGRPC(err) + err = ToGRPC(ctx, err) } if oldErr != nil && err == nil { logErr := errors.Wrap(err, "invalid grpc error conversion") @@ -30,7 +30,7 @@ func UnaryServerInterceptor(ctx context.Context, req interface{}, info *grpc.Una } func StreamServerInterceptor(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error { - err := ToGRPC(handler(srv, ss)) + err := ToGRPC(ss.Context(), handler(srv, ss)) if err != nil { stack.Helper() } @@ -50,5 +50,5 @@ func StreamClientInterceptor(ctx context.Context, desc *grpc.StreamDesc, cc *grp if err != nil { stack.Helper() } - return s, ToGRPC(err) + return s, ToGRPC(ctx, err) } diff --git a/util/network/netproviders/network_unix.go b/util/network/netproviders/network_unix.go index b8d733ec32f0..d52173932291 100644 --- a/util/network/netproviders/network_unix.go +++ b/util/network/netproviders/network_unix.go @@ -4,8 +4,8 @@ package netproviders import ( + "github.com/moby/buildkit/util/bklog" "github.com/moby/buildkit/util/network" - "github.com/sirupsen/logrus" ) func getHostProvider() (network.Provider, bool) { @@ -13,6 +13,6 @@ func getHostProvider() (network.Provider, bool) { } func getFallback() (network.Provider, string) { - logrus.Warn("using host network as the default") + bklog.L.Warn("using host network as the default") return network.NewHostProvider(), "host" } diff --git a/util/network/netproviders/network_windows.go b/util/network/netproviders/network_windows.go index c7e460e333a2..0a17a36db36a 100644 --- a/util/network/netproviders/network_windows.go +++ b/util/network/netproviders/network_windows.go @@ -4,8 +4,8 @@ package netproviders import ( + "github.com/moby/buildkit/util/bklog" "github.com/moby/buildkit/util/network" - "github.com/sirupsen/logrus" ) func getHostProvider() (network.Provider, bool) { @@ -13,6 +13,6 @@ func getHostProvider() (network.Provider, bool) { } func getFallback() (network.Provider, string) { - logrus.Warn("using null network as the default") + bklog.L.Warn("using null network as the default") return network.NewNoneProvider(), "" } diff --git a/util/progress/progressui/colors.go b/util/progress/progressui/colors.go index f6d3174769dc..9758f6b5d6bc 100644 --- a/util/progress/progressui/colors.go +++ b/util/progress/progressui/colors.go @@ -6,8 +6,8 @@ import ( "strconv" "strings" + "github.com/moby/buildkit/util/bklog" "github.com/morikuni/aec" - "github.com/sirupsen/logrus" ) var termColorMap = map[string]aec.ANSI{ @@ -41,7 +41,7 @@ func setUserDefinedTermColors(colorsEnv string) { k, v, ok := strings.Cut(field, "=") if !ok || strings.Contains(v, "=") { err := errors.New("A valid entry must have exactly two fields") - logrus.WithError(err).Warnf("Could not parse BUILDKIT_COLORS component: %s", field) + bklog.L.WithError(err).Warnf("Could not parse BUILDKIT_COLORS component: %s", field) continue } k = strings.ToLower(k) @@ -53,7 +53,7 @@ func setUserDefinedTermColors(colorsEnv string) { } } else { err := errors.New("Colors must be a name from the pre-defined list or a valid 3-part RGB value") - logrus.WithError(err).Warnf("Unknown color value found in BUILDKIT_COLORS: %s=%s", k, v) + bklog.L.WithError(err).Warnf("Unknown color value found in BUILDKIT_COLORS: %s=%s", k, v) } } } @@ -63,7 +63,7 @@ func readBuildkitColorsEnv(colorsEnv string) []string { csvReader.Comma = ':' fields, err := csvReader.Read() if err != nil { - logrus.WithError(err).Warnf("Could not parse BUILDKIT_COLORS. Falling back to defaults.") + bklog.L.WithError(err).Warnf("Could not parse BUILDKIT_COLORS. Falling back to defaults.") return nil } return fields @@ -73,12 +73,12 @@ func readRGB(v string) aec.ANSI { csvReader := csv.NewReader(strings.NewReader(v)) fields, err := csvReader.Read() if err != nil { - logrus.WithError(err).Warnf("Could not parse value %s as valid comma-separated RGB color. Ignoring.", v) + bklog.L.WithError(err).Warnf("Could not parse value %s as valid comma-separated RGB color. Ignoring.", v) return nil } if len(fields) != 3 { err = errors.New("A valid RGB color must have three fields") - logrus.WithError(err).Warnf("Could not parse value %s as valid RGB color. Ignoring.", v) + bklog.L.WithError(err).Warnf("Could not parse value %s as valid RGB color. Ignoring.", v) return nil } ok := isValidRGB(fields) @@ -103,7 +103,7 @@ func parseKeys(k string, c aec.ANSI) { case "warning": colorWarning = c default: - logrus.Warnf("Unknown key found in BUILDKIT_COLORS (expected: run, cancel, error, or warning): %s", k) + bklog.L.Warnf("Unknown key found in BUILDKIT_COLORS (expected: run, cancel, error, or warning): %s", k) } } @@ -111,14 +111,14 @@ func isValidRGB(s []string) bool { for _, n := range s { num, err := strconv.Atoi(n) if err != nil { - logrus.Warnf("A field in BUILDKIT_COLORS appears to contain an RGB value that is not an integer: %s", strings.Join(s, ",")) + bklog.L.Warnf("A field in BUILDKIT_COLORS appears to contain an RGB value that is not an integer: %s", strings.Join(s, ",")) return false } ok := isValidRGBValue(num) if ok { continue } else { - logrus.Warnf("A field in BUILDKIT_COLORS appears to contain an RGB value that is not within the valid range of 0-255: %s", strings.Join(s, ",")) + bklog.L.Warnf("A field in BUILDKIT_COLORS appears to contain an RGB value that is not within the valid range of 0-255: %s", strings.Join(s, ",")) return false } } diff --git a/util/pull/pullprogress/progress.go b/util/pull/pullprogress/progress.go index 93c50106f79d..61e1c90706c2 100644 --- a/util/pull/pullprogress/progress.go +++ b/util/pull/pullprogress/progress.go @@ -8,6 +8,7 @@ import ( "github.com/containerd/containerd/content" "github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/remotes" + "github.com/moby/buildkit/util/bklog" "github.com/moby/buildkit/util/progress" ocispecs "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" @@ -33,13 +34,14 @@ func (p *ProviderWithProgress) ReaderAt(ctx context.Context, desc ocispecs.Descr ctx, cancel := context.WithCancel(ctx) doneCh := make(chan struct{}) go trackProgress(ctx, desc, p.Manager, doneCh) - return readerAtWithCancel{ReaderAt: ra, cancel: cancel, doneCh: doneCh}, nil + return readerAtWithCancel{ReaderAt: ra, cancel: cancel, doneCh: doneCh, logger: bklog.G(ctx)}, nil } type readerAtWithCancel struct { content.ReaderAt cancel func() doneCh <-chan struct{} + logger *logrus.Entry } func (ra readerAtWithCancel) Close() error { @@ -47,7 +49,7 @@ func (ra readerAtWithCancel) Close() error { select { case <-ra.doneCh: case <-time.After(time.Second): - logrus.Warn("timeout waiting for pull progress to complete") + ra.logger.Warn("timeout waiting for pull progress to complete") } return ra.ReaderAt.Close() } @@ -66,13 +68,14 @@ func (f *FetcherWithProgress) Fetch(ctx context.Context, desc ocispecs.Descripto ctx, cancel := context.WithCancel(ctx) doneCh := make(chan struct{}) go trackProgress(ctx, desc, f.Manager, doneCh) - return readerWithCancel{ReadCloser: rc, cancel: cancel, doneCh: doneCh}, nil + return readerWithCancel{ReadCloser: rc, cancel: cancel, doneCh: doneCh, logger: bklog.G(ctx)}, nil } type readerWithCancel struct { io.ReadCloser cancel func() doneCh <-chan struct{} + logger *logrus.Entry } func (r readerWithCancel) Close() error { @@ -80,7 +83,7 @@ func (r readerWithCancel) Close() error { select { case <-r.doneCh: case <-time.After(time.Second): - logrus.Warn("timeout waiting for pull progress to complete") + r.logger.Warn("timeout waiting for pull progress to complete") } return r.ReadCloser.Close() } @@ -120,7 +123,7 @@ func trackProgress(ctx context.Context, desc ocispecs.Descriptor, manager PullMa }) continue } else if !errors.Is(err, errdefs.ErrNotFound) { - logrus.Errorf("unexpected error getting ingest status of %q: %v", ingestRef, err) + bklog.G(ctx).Errorf("unexpected error getting ingest status of %q: %v", ingestRef, err) return } diff --git a/util/push/push.go b/util/push/push.go index 881b2fd86f16..72415171b01f 100644 --- a/util/push/push.go +++ b/util/push/push.go @@ -16,6 +16,7 @@ import ( "github.com/docker/distribution/reference" "github.com/moby/buildkit/session" "github.com/moby/buildkit/util/attestation" + "github.com/moby/buildkit/util/bklog" "github.com/moby/buildkit/util/flightcontrol" "github.com/moby/buildkit/util/imageutil" "github.com/moby/buildkit/util/progress" @@ -27,7 +28,6 @@ import ( digest "github.com/opencontainers/go-digest" ocispecs "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" - "github.com/sirupsen/logrus" ) type pusher struct { @@ -254,7 +254,7 @@ func childrenHandler(provider content.Provider) images.HandlerFunc { // childless data types. return nil, nil default: - logrus.Warnf("encountered unknown type %v; children may not be fetched", desc.MediaType) + bklog.G(ctx).Warnf("encountered unknown type %v; children may not be fetched", desc.MediaType) } return descs, nil @@ -289,7 +289,7 @@ func updateDistributionSourceHandler(manager content.Manager, pushF images.Handl // update distribution source to layer if islayer { if _, err := updateF(ctx, desc); err != nil { - logrus.Warnf("failed to update distribution source for layer %v: %v", desc.Digest, err) + bklog.G(ctx).Warnf("failed to update distribution source for layer %v: %v", desc.Digest, err) } } return children, nil diff --git a/util/resolver/limited/group.go b/util/resolver/limited/group.go index 7fdd947a02a5..934bd4f4eb17 100644 --- a/util/resolver/limited/group.go +++ b/util/resolver/limited/group.go @@ -11,8 +11,8 @@ import ( "github.com/containerd/containerd/images" "github.com/containerd/containerd/remotes" "github.com/docker/distribution/reference" + "github.com/moby/buildkit/util/bklog" ocispecs "github.com/opencontainers/image-spec/specs-go/v1" - "github.com/sirupsen/logrus" "golang.org/x/sync/semaphore" ) @@ -119,7 +119,7 @@ func (f *fetcher) Fetch(ctx context.Context, desc ocispecs.Descriptor) (io.ReadC rcw := &readCloser{ReadCloser: rc} closer := func() { if !rcw.closed { - logrus.Warnf("fetcher not closed cleanly: %s", desc.Digest) + bklog.G(ctx).Warnf("fetcher not closed cleanly: %s", desc.Digest) } release() } diff --git a/util/testutil/integration/containerd.go b/util/testutil/integration/containerd.go index 193176f2b407..d0a42cd22bd0 100644 --- a/util/testutil/integration/containerd.go +++ b/util/testutil/integration/containerd.go @@ -13,8 +13,8 @@ import ( "strings" "time" + "github.com/moby/buildkit/util/bklog" "github.com/pkg/errors" - "github.com/sirupsen/logrus" ) func InitContainerdWorker() { @@ -45,7 +45,7 @@ func InitContainerdWorker() { if s := os.Getenv("BUILDKIT_INTEGRATION_ROOTLESS_IDPAIR"); s != "" { var uid, gid int if _, err := fmt.Sscanf(s, "%d:%d", &uid, &gid); err != nil { - logrus.Fatalf("unexpected BUILDKIT_INTEGRATION_ROOTLESS_IDPAIR: %q", s) + bklog.L.Fatalf("unexpected BUILDKIT_INTEGRATION_ROOTLESS_IDPAIR: %q", s) } if rootlessSupported(uid) { Register(&containerd{ diff --git a/util/testutil/integration/oci.go b/util/testutil/integration/oci.go index b4934a937870..05f66f93ed52 100644 --- a/util/testutil/integration/oci.go +++ b/util/testutil/integration/oci.go @@ -7,8 +7,8 @@ import ( "os" "runtime" + "github.com/moby/buildkit/util/bklog" "github.com/pkg/errors" - "github.com/sirupsen/logrus" ) func InitOCIWorker() { @@ -18,7 +18,7 @@ func InitOCIWorker() { if s := os.Getenv("BUILDKIT_INTEGRATION_ROOTLESS_IDPAIR"); s != "" { var uid, gid int if _, err := fmt.Sscanf(s, "%d:%d", &uid, &gid); err != nil { - logrus.Fatalf("unexpected BUILDKIT_INTEGRATION_ROOTLESS_IDPAIR: %q", s) + bklog.L.Fatalf("unexpected BUILDKIT_INTEGRATION_ROOTLESS_IDPAIR: %q", s) } if rootlessSupported(uid) { Register(&oci{uid: uid, gid: gid}) diff --git a/util/testutil/integration/sandbox.go b/util/testutil/integration/sandbox.go index 5a6f519f16c5..b208aee51e00 100644 --- a/util/testutil/integration/sandbox.go +++ b/util/testutil/integration/sandbox.go @@ -14,8 +14,8 @@ import ( "time" "github.com/google/shlex" + "github.com/moby/buildkit/util/bklog" "github.com/pkg/errors" - "github.com/sirupsen/logrus" ) const buildkitdConfigFile = "buildkitd.toml" @@ -267,7 +267,7 @@ func rootlessSupported(uid int) bool { cmd := exec.Command("sudo", "-u", fmt.Sprintf("#%d", uid), "-i", "--", "exec", "unshare", "-U", "true") //nolint:gosec // test utility b, err := cmd.CombinedOutput() if err != nil { - logrus.Warnf("rootless mode is not supported on this host: %v (%s)", err, string(b)) + bklog.L.Warnf("rootless mode is not supported on this host: %v (%s)", err, string(b)) return false } return true diff --git a/util/winlayers/differ.go b/util/winlayers/differ.go index fe2b1c216176..71c1c4723cba 100644 --- a/util/winlayers/differ.go +++ b/util/winlayers/differ.go @@ -18,8 +18,8 @@ import ( digest "github.com/opencontainers/go-digest" ocispecs "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" - "github.com/sirupsen/logrus" + "github.com/moby/buildkit/util/bklog" log "github.com/moby/buildkit/util/bklog" ) @@ -109,7 +109,7 @@ func (s *winDiffer) Compare(ctx context.Context, lower, upper []mount.Mount, opt if err != nil { return errors.Wrap(err, "failed to get compressed stream") } - w, discard, done := makeWindowsLayer(io.MultiWriter(compressed, dgstr.Hash())) + w, discard, done := makeWindowsLayer(ctx, io.MultiWriter(compressed, dgstr.Hash())) err = archive.WriteDiff(ctx, w, lowerRoot, upperRoot) if err != nil { discard(err) @@ -125,7 +125,7 @@ func (s *winDiffer) Compare(ctx context.Context, lower, upper []mount.Mount, opt } config.Labels["containerd.io/uncompressed"] = dgstr.Digest().String() } else { - w, discard, done := makeWindowsLayer(cw) + w, discard, done := makeWindowsLayer(ctx, cw) if err = archive.WriteDiff(ctx, w, lowerRoot, upperRoot); err != nil { discard(err) return errors.Wrap(err, "failed to write diff") @@ -203,7 +203,7 @@ func addSecurityDescriptor(h *tar.Header) { } } -func makeWindowsLayer(w io.Writer) (io.Writer, func(error), chan error) { +func makeWindowsLayer(ctx context.Context, w io.Writer) (io.Writer, func(error), chan error) { pr, pw := io.Pipe() done := make(chan error) @@ -259,7 +259,7 @@ func makeWindowsLayer(w io.Writer) (io.Writer, func(error), chan error) { return tarWriter.Close() }() if err != nil { - logrus.Errorf("makeWindowsLayer %+v", err) + bklog.G(ctx).Errorf("makeWindowsLayer %+v", err) } pw.CloseWithError(err) done <- err