From 8e3bcf19748838b30e34d612832d1dc9d90363b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Thu, 22 Feb 2024 18:01:40 +0100 Subject: [PATCH 1/4] pkg/streamformatter: Make `progressOutput` concurrency safe MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sync access to the underlying `io.Writer` with a mutex. Signed-off-by: Paweł Gronowski (cherry picked from commit 5689dabfb357b673abdb4391eef426f297d7d1bb) Signed-off-by: Albin Kerouanton --- pkg/streamformatter/streamformatter.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/streamformatter/streamformatter.go b/pkg/streamformatter/streamformatter.go index b0456e580dc9d..098df6b5236b9 100644 --- a/pkg/streamformatter/streamformatter.go +++ b/pkg/streamformatter/streamformatter.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" "io" + "sync" "github.com/docker/docker/pkg/jsonmessage" "github.com/docker/docker/pkg/progress" @@ -109,6 +110,7 @@ type progressOutput struct { sf formatProgress out io.Writer newLines bool + mu sync.Mutex } // WriteProgress formats progress information from a ProgressReader. @@ -120,6 +122,9 @@ func (out *progressOutput) WriteProgress(prog progress.Progress) error { jsonProgress := jsonmessage.JSONProgress{Current: prog.Current, Total: prog.Total, HideCounts: prog.HideCounts, Units: prog.Units} formatted = out.sf.formatProgress(prog.ID, prog.Action, &jsonProgress, prog.Aux) } + + out.mu.Lock() + defer out.mu.Unlock() _, err := out.out.Write(formatted) if err != nil { return err From 200181357121635030123eea0650fbcdbaf29089 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Thu, 22 Feb 2024 17:40:44 +0100 Subject: [PATCH 2/4] c8d/pull: Emit `Pulling fs layer` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Paweł Gronowski (cherry picked from commit ff5f780f2b57be7cbe7ea27c179fb2edfb869ddd) Signed-off-by: Albin Kerouanton --- daemon/containerd/image_pull.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/daemon/containerd/image_pull.go b/daemon/containerd/image_pull.go index 12fa824259277..1614f1081bc6a 100644 --- a/daemon/containerd/image_pull.go +++ b/daemon/containerd/image_pull.go @@ -117,6 +117,9 @@ func (i *ImageService) pullTag(ctx context.Context, ref reference.Named, platfor progress.Message(out, "", distribution.DeprecatedSchema1ImageMessage(ref)) sentSchema1Deprecation = true } + if images.IsLayerType(desc.MediaType) { + progress.Update(out, desc.Digest.String(), "Pulling fs layer") + } if images.IsManifestType(desc.MediaType) { if !sentPullingFrom { var tagOrDigest string From 97951c39fb2e048204c9d6d2b2e9b8c7917025d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Thu, 22 Feb 2024 18:02:22 +0100 Subject: [PATCH 3/4] c8d/pull: Don't emit `Downloading` with 0 progress MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To align with the graphdrivers behavior and don't send unnecessary progress messages. Signed-off-by: Paweł Gronowski (cherry picked from commit 14df52b709d7ad00f1d9064b996aeba23ff024d5) Signed-off-by: Albin Kerouanton --- daemon/containerd/progress.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/daemon/containerd/progress.go b/daemon/containerd/progress.go index 8d7ff12bdb6b0..5d21eb3ec1ab6 100644 --- a/daemon/containerd/progress.go +++ b/daemon/containerd/progress.go @@ -135,6 +135,9 @@ func (p pullProgress) UpdateProgress(ctx context.Context, ongoing *jobs, out pro } key := remotes.MakeRefKey(ctx, j) if info, ok := pulling[key]; ok { + if info.Offset == 0 { + continue + } out.WriteProgress(progress.Progress{ ID: stringid.TruncateID(j.Digest.Encoded()), Action: "Downloading", From be59afce2da7abc5339bf7aa2e3dbaa1bc3afc13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Tue, 27 Feb 2024 11:04:25 +0100 Subject: [PATCH 4/4] c8d/pull: Output truncated id for `Pulling fs layer` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit All other progress updates are emitted with truncated id. ```diff $ docker pull --platform linux/amd64 alpine Using default tag: latest latest: Pulling from library/alpine -sha256:4abcf20661432fb2d719aaf90656f55c287f8ca915dc1c92ec14ff61e67fbaf8: Pulling fs layer +4abcf2066143: Download complete Digest: sha256:c5b1261d6d3e43071626931fc004f70149baeba2c8ec672bd4f27761f8e1ad6b Status: Image is up to date for alpine:latest docker.io/library/alpine:latest ``` Signed-off-by: Paweł Gronowski (cherry picked from commit 16aa7dd67fc20f15690b145f30e921d783746cb6) Signed-off-by: Albin Kerouanton --- daemon/containerd/image_pull.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/daemon/containerd/image_pull.go b/daemon/containerd/image_pull.go index 1614f1081bc6a..88ef659f2d274 100644 --- a/daemon/containerd/image_pull.go +++ b/daemon/containerd/image_pull.go @@ -21,6 +21,7 @@ import ( "github.com/docker/docker/internal/compatcontext" "github.com/docker/docker/pkg/progress" "github.com/docker/docker/pkg/streamformatter" + "github.com/docker/docker/pkg/stringid" ocispec "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" ) @@ -118,7 +119,8 @@ func (i *ImageService) pullTag(ctx context.Context, ref reference.Named, platfor sentSchema1Deprecation = true } if images.IsLayerType(desc.MediaType) { - progress.Update(out, desc.Digest.String(), "Pulling fs layer") + id := stringid.TruncateID(desc.Digest.String()) + progress.Update(out, id, "Pulling fs layer") } if images.IsManifestType(desc.MediaType) { if !sentPullingFrom {