From 9e9bcec9ece8e1986c3067e4da50734589450cb1 Mon Sep 17 00:00:00 2001 From: Valentin Rothberg Date: Tue, 2 May 2023 13:57:43 +0200 Subject: [PATCH] history: correctly set tags Requires vendoring fixes from c/common and to update the transformation code. Also add a test to avoid future regressions. Fixes: #17763 Signed-off-by: Valentin Rothberg --- go.mod | 2 +- go.sum | 4 ++-- pkg/domain/infra/abi/images.go | 13 +++++++------ test/apiv2/10-images.at | 4 ++-- test/system/110-history.bats | 3 +++ .../containers/common/libimage/history.go | 8 ++++++-- .../containers/common/pkg/sysinfo/numcpu_linux.go | 5 +---- .../github.com/containers/common/version/version.go | 2 +- vendor/modules.txt | 2 +- 9 files changed, 24 insertions(+), 19 deletions(-) diff --git a/go.mod b/go.mod index 126dd3f4c7..8131bd7ef4 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/containernetworking/cni v1.1.2 github.com/containernetworking/plugins v1.2.0 github.com/containers/buildah v1.30.0 - github.com/containers/common v0.53.0 + github.com/containers/common v0.53.1-0.20230502134647-9cd0cc23c80f github.com/containers/conmon v2.0.20+incompatible github.com/containers/image/v5 v5.25.0 github.com/containers/libhvee v0.0.5 diff --git a/go.sum b/go.sum index 503c8d7c32..c5ee42aedc 100644 --- a/go.sum +++ b/go.sum @@ -239,8 +239,8 @@ github.com/containernetworking/plugins v1.2.0 h1:SWgg3dQG1yzUo4d9iD8cwSVh1VqI+bP github.com/containernetworking/plugins v1.2.0/go.mod h1:/VjX4uHecW5vVimFa1wkG4s+r/s9qIfPdqlLF4TW8c4= github.com/containers/buildah v1.30.0 h1:mdp2COGKFFEZNEGP8VZ5ITuUFVNPFoH+iK2sSesNfTA= github.com/containers/buildah v1.30.0/go.mod h1:lyMLZIevpAa6zSzjRl7z4lFJMCMQLFjfo56YIefaB/U= -github.com/containers/common v0.53.0 h1:Ax814cLeX5VXSnkKUdxz762g+27fJj1st4UvKoXmkKs= -github.com/containers/common v0.53.0/go.mod h1:pABPxJwlTE8oYk9/2BW0e0mumkuhJHIPsABHTGRXN3w= +github.com/containers/common v0.53.1-0.20230502134647-9cd0cc23c80f h1:NGr0tr+qnavYQ3m+ajnrCLCp7y/YlGj14OXsYD5RhqY= +github.com/containers/common v0.53.1-0.20230502134647-9cd0cc23c80f/go.mod h1:uG5iTo9KbPxcyj3nsq0OPbBRTrSsrXKIMNRw4D6rt/w= github.com/containers/conmon v2.0.20+incompatible h1:YbCVSFSCqFjjVwHTPINGdMX1F6JXHGTUje2ZYobNrkg= github.com/containers/conmon v2.0.20+incompatible/go.mod h1:hgwZ2mtuDrppv78a/cOBNiCm6O0UMWGx1mu7P00nu5I= github.com/containers/image/v5 v5.25.0 h1:TJ0unmalbU+scd0i3Txap2wjGsAnv06MSCwgn6bsizk= diff --git a/pkg/domain/infra/abi/images.go b/pkg/domain/infra/abi/images.go index 4e4ec294dd..0ba9471c2e 100644 --- a/pkg/domain/infra/abi/images.go +++ b/pkg/domain/infra/abi/images.go @@ -92,15 +92,16 @@ func (ir *ImageEngine) Prune(ctx context.Context, opts entities.ImagePruneOption } func toDomainHistoryLayer(layer *libimage.ImageHistory) entities.ImageHistoryLayer { - l := entities.ImageHistoryLayer{} - l.ID = layer.ID + l := entities.ImageHistoryLayer{ + Comment: layer.Comment, + CreatedBy: layer.CreatedBy, + ID: layer.ID, + Size: layer.Size, + Tags: layer.Tags, + } if layer.Created != nil { l.Created = *layer.Created } - l.CreatedBy = layer.CreatedBy - copy(l.Tags, layer.Tags) - l.Size = layer.Size - l.Comment = layer.Comment return l } diff --git a/test/apiv2/10-images.at b/test/apiv2/10-images.at index 8f52a321f4..8eb0235ba7 100644 --- a/test/apiv2/10-images.at +++ b/test/apiv2/10-images.at @@ -73,7 +73,7 @@ for i in $iid ${iid:0:12} $PODMAN_TEST_IMAGE_NAME; do t GET libpod/images/$i/history 200 \ .[0].Id=$iid \ .[0].Created~[0-9]\\{10\\} \ - .[0].Tags=null \ + .[0].Tags[0]="$IMAGE" \ .[0].Size=0 \ .[0].Comment= done @@ -82,7 +82,7 @@ for i in $iid ${iid:0:12} $PODMAN_TEST_IMAGE_NAME; do t GET images/$i/history 200 \ .[0].Id="sha256:"$iid \ .[0].Created~[0-9]\\{10\\} \ - .[0].Tags=null \ + .[0].Tags[0]="$IMAGE" \ .[0].Size=0 \ .[0].Comment= done diff --git a/test/system/110-history.bats b/test/system/110-history.bats index 47ad83ef8e..dbb97aacb0 100644 --- a/test/system/110-history.bats +++ b/test/system/110-history.bats @@ -27,6 +27,9 @@ load helpers while IFS= read -r row; do is "$row" ".* .*$" done <<<$output + + run_podman history --format "{{.Tags}}" $IMAGE + is "$output" "\[$IMAGE\].*" "podman history sets tags" } @test "podman history - json" { diff --git a/vendor/github.com/containers/common/libimage/history.go b/vendor/github.com/containers/common/libimage/history.go index 46252df106..ad989b528a 100644 --- a/vendor/github.com/containers/common/libimage/history.go +++ b/vendor/github.com/containers/common/libimage/history.go @@ -51,7 +51,6 @@ func (i *Image) History(ctx context.Context) ([]ImageHistory, error) { } if layer != nil { - history.Tags = layer.Names if !ociImage.History[x].EmptyLayer { history.Size = layer.UncompressedSize } @@ -64,8 +63,13 @@ func (i *Image) History(ctx context.Context) ([]ImageHistory, error) { history.ID = id usedIDs[id] = true } + for i := range node.images { + history.Tags = append(history.Tags, node.images[i].Names()...) + } } - if layer.Parent != "" && !ociImage.History[x].EmptyLayer { + if layer.Parent == "" { + layer = nil + } else if !ociImage.History[x].EmptyLayer { layer, err = i.runtime.store.Layer(layer.Parent) if err != nil { return nil, err diff --git a/vendor/github.com/containers/common/pkg/sysinfo/numcpu_linux.go b/vendor/github.com/containers/common/pkg/sysinfo/numcpu_linux.go index c10d69c79c..d77e52f603 100644 --- a/vendor/github.com/containers/common/pkg/sysinfo/numcpu_linux.go +++ b/vendor/github.com/containers/common/pkg/sysinfo/numcpu_linux.go @@ -8,14 +8,11 @@ import "golang.org/x/sys/unix" // numCPU queries the system for the count of threads available // for use to this process. // -// Issues two syscalls. // Returns 0 on errors. Use |runtime.NumCPU| in that case. func numCPU() int { // Gets the affinity mask for a process: The very one invoking this function. - pid := unix.Getpid() - var mask unix.CPUSet - err := unix.SchedGetaffinity(pid, &mask) + err := unix.SchedGetaffinity(0, &mask) if err != nil { return 0 } diff --git a/vendor/github.com/containers/common/version/version.go b/vendor/github.com/containers/common/version/version.go index 8bd54871c0..9f33b9c73a 100644 --- a/vendor/github.com/containers/common/version/version.go +++ b/vendor/github.com/containers/common/version/version.go @@ -1,4 +1,4 @@ package version // Version is the version of the build. -const Version = "0.53.0" +const Version = "0.54.0-dev" diff --git a/vendor/modules.txt b/vendor/modules.txt index e1acd44587..6e886de1ad 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -125,7 +125,7 @@ github.com/containers/buildah/pkg/rusage github.com/containers/buildah/pkg/sshagent github.com/containers/buildah/pkg/util github.com/containers/buildah/util -# github.com/containers/common v0.53.0 +# github.com/containers/common v0.53.1-0.20230502134647-9cd0cc23c80f ## explicit; go 1.18 github.com/containers/common/libimage github.com/containers/common/libimage/define