Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable preparer interface to pre operations #964

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/commands/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ func publishImages(ctx context.Context, importpaths []string, pub publish.Interf
return nil, fmt.Errorf("importpath %q is not supported: %w", importpath, err)
}

if ppub, ok := pub.(publish.Preparer); ok {
if err := ppub.Prepare(ctx, importpath); err != nil {
return nil, fmt.Errorf("error preparing publisher: %w", err)
}
}

img, err := b.Build(ctx, importpath)
if err != nil {
return nil, fmt.Errorf("error building %q: %w", importpath, err)
Expand Down
22 changes: 22 additions & 0 deletions pkg/publish/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,25 @@ func (d *defalt) Publish(ctx context.Context, br build.Result, s string) (name.R
func (d *defalt) Close() error {
return nil
}

// Prepare implements publish.Preparer
func (d *defalt) Prepare(ctx context.Context, s string) error {
var no []name.Option
if d.insecure {
no = append(no, name.Insecure)
}

for _, tagName := range d.tags {
tag, err := name.NewTag(fmt.Sprintf("%s:%s", d.namer(d.base, s), tagName), no...)
if err != nil {
return err
}

if err := remote.CheckPushPermission(tag, d.keychain, d.t); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't going to handle d.insecure, unfortunately... 🤔

return err
}
}
developer-guy marked this conversation as resolved.
Show resolved Hide resolved

return nil

}
12 changes: 12 additions & 0 deletions pkg/publish/multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,15 @@ func (p *multiPublisher) Close() (err error) {
}
return
}

// Prepare implements publish.Preparer.
func (p *multiPublisher) Prepare(ctx context.Context, s string) (err error) {
for _, pub := range p.publishers {
if ppub, ok := pub.(Preparer); ok {
if perr := ppub.Prepare(ctx, s); perr != nil {
err = perr
developer-guy marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
return
}
4 changes: 4 additions & 0 deletions pkg/publish/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ import (
"github.com/google/ko/pkg/build"
)

type Preparer interface {
developer-guy marked this conversation as resolved.
Show resolved Hide resolved
Prepare(context.Context, string) error
}

// Interface abstracts different methods for publishing images.
type Interface interface {
// Publish uploads the given build.Result to a registry incorporating the
Expand Down