Skip to content

Commit

Permalink
libimage, push: tag repo@remote-digest on localstorage on successful …
Browse files Browse the repository at this point in the history
…push

Upon successful push now libimage will commit the remote digest on
localstorage as tag example: `repo:remote-digest`

This is needed as when a push operation is performed libimage does not
acks successfully created digest on remote-repo so after this commit
users would be able to perform image operations on the just commited
digest, as `repo:remote-digest` will point to the same image which was
just pushed to remote repo.

Closes: containers/buildah#3866

[NO NEW TESTS NEEDED] : Not sure if we have any tests for remote
registry push on c/common

Signed-off-by: Aditya R <arajan@redhat.com>
  • Loading branch information
flouthoc committed May 31, 2022
1 parent 6d22aa8 commit 6129a3e
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion libimage/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package libimage

import (
"context"
"strings"
"time"

dockerArchiveTransport "github.com/containers/image/v5/docker/archive"
"github.com/containers/image/v5/docker/reference"
"github.com/containers/image/v5/manifest"
"github.com/containers/image/v5/transports/alltransports"
"github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -85,5 +87,21 @@ func (r *Runtime) Push(ctx context.Context, source, destination string, options

defer c.close()

return c.copy(ctx, srcRef, destRef)
manifestBytes, err := c.copy(ctx, srcRef, destRef)
if err != nil {
return nil, err
}
manifestDigest, err := manifest.Digest(manifestBytes)
if err != nil {
return nil, err
}
// Tag for pushed remote digest i.e repo@remote-digest
remoteDigest := strings.TrimPrefix(manifestDigest.String(), "sha256:")
pushedTag := destRef.DockerReference().Name() + ":" + remoteDigest
logrus.Debugf("Successfully pushed image and now creating local tag %q", pushedTag)
err = image.Tag(pushedTag)
if err != nil {
logrus.Debugf("Failed creating local tag for %q just pushed image: %s", pushedTag, err)
}
return manifestBytes, nil
}

0 comments on commit 6129a3e

Please sign in to comment.