Skip to content

Commit

Permalink
pkg/bindings: Support writing image push progress to specified io.Writer
Browse files Browse the repository at this point in the history
Currently bindings writes image push progress to os.Stderr.

Since os.Stderr is inconvenience for bindings caller to
process the progress messages, Added this support.

Signed-off-by: Naoto Kobayashi <[email protected]>
  • Loading branch information
YoitoFes committed Aug 7, 2022
1 parent 635293e commit b1d1248
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
2 changes: 2 additions & 0 deletions pkg/bindings/images/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ func Push(ctx context.Context, source string, destination string, options *PushO
writer := io.Writer(os.Stderr)
if options.GetQuiet() {
writer = ioutil.Discard
} else if progressWriter := options.GetProgressWriter(); progressWriter != nil {
writer = progressWriter
}

dec := json.NewDecoder(response.Body)
Expand Down
6 changes: 6 additions & 0 deletions pkg/bindings/images/types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package images

import (
"io"

buildahDefine "github.com/containers/buildah/define"
)

Expand Down Expand Up @@ -131,6 +133,10 @@ type PushOptions struct {
Format *string
// Password for authenticating against the registry.
Password *string
// ProgressWriter is a writer where push progress are sent.
// Since API handler for image push is quiet by default, WithQuiet(false) is necessary for
// the writer to receive progress messages.
ProgressWriter *io.Writer
// SkipTLSVerify to skip HTTPS and certificate verification.
SkipTLSVerify *bool
// RemoveSignatures Discard any pre-existing signatures in the image.
Expand Down
16 changes: 16 additions & 0 deletions pkg/bindings/images/types_push_options.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions pkg/bindings/test/images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,10 @@ var _ = Describe("Podman images", func() {
Expect(err).To(HaveOccurred())
})

It("Image Push", func() {
Skip("TODO: implement test for image push to registry")
})

It("Build no options", func() {
results, err := images.Build(bt.conn, []string{"fixture/Containerfile"}, entities.BuildOptions{})
Expect(err).ToNot(HaveOccurred())
Expand Down
2 changes: 1 addition & 1 deletion pkg/domain/infra/tunnel/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func (ir *ImageEngine) Import(ctx context.Context, opts entities.ImageImportOpti

func (ir *ImageEngine) Push(ctx context.Context, source string, destination string, opts entities.ImagePushOptions) error {
options := new(images.PushOptions)
options.WithAll(opts.All).WithCompress(opts.Compress).WithUsername(opts.Username).WithPassword(opts.Password).WithAuthfile(opts.Authfile).WithFormat(opts.Format).WithRemoveSignatures(opts.RemoveSignatures).WithQuiet(opts.Quiet).WithCompressionFormat(opts.CompressionFormat)
options.WithAll(opts.All).WithCompress(opts.Compress).WithUsername(opts.Username).WithPassword(opts.Password).WithAuthfile(opts.Authfile).WithFormat(opts.Format).WithRemoveSignatures(opts.RemoveSignatures).WithQuiet(opts.Quiet).WithCompressionFormat(opts.CompressionFormat).WithProgressWriter(opts.Writer)

if s := opts.SkipTLSVerify; s != types.OptionalBoolUndefined {
if s == types.OptionalBoolTrue {
Expand Down

0 comments on commit b1d1248

Please sign in to comment.