-
Notifications
You must be signed in to change notification settings - Fork 405
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This change adds a new `--image-refs=FILE` flag that can be used to direct `ko` to write a file containing a `\n` delimited list of published references. In the common case, this will contain the list of digest references, but if flags directing the use of tags are present this will reflect the style of reference requested.
- Loading branch information
Showing
9 changed files
with
161 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright 2018 Google LLC All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package publish | ||
|
||
import ( | ||
"context" | ||
"io" | ||
|
||
"github.com/google/go-containerregistry/pkg/name" | ||
"github.com/google/ko/pkg/build" | ||
) | ||
|
||
// recorder wraps a publisher implementation in a layer that recordes the published | ||
// references to an io.Writer. | ||
type recorder struct { | ||
inner Interface | ||
wc io.Writer | ||
} | ||
|
||
// recorder implements Interface | ||
var _ Interface = (*recorder)(nil) | ||
|
||
// NewRecorder wraps the provided publish.Interface in an implementation that | ||
// records publish results to an io.Writer. | ||
func NewRecorder(inner Interface, wc io.Writer) (Interface, error) { | ||
return &recorder{ | ||
inner: inner, | ||
wc: wc, | ||
}, nil | ||
} | ||
|
||
// Publish implements Interface | ||
func (r *recorder) Publish(ctx context.Context, br build.Result, ref string) (name.Reference, error) { | ||
result, err := r.inner.Publish(ctx, br, ref) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if _, err := r.wc.Write([]byte(result.String() + "\n")); err != nil { | ||
return nil, err | ||
} | ||
return result, nil | ||
} | ||
|
||
// Close implements Interface | ||
func (r *recorder) Close() error { | ||
if err := r.inner.Close(); err != nil { | ||
return err | ||
} | ||
if c, ok := r.wc.(io.Closer); ok { | ||
return c.Close() | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright 2018 Google LLC All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package publish | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/google/go-containerregistry/pkg/name" | ||
"github.com/google/ko/pkg/build" | ||
) | ||
|
||
type cbPublish struct { | ||
cb func(context.Context, build.Result, string) (name.Reference, error) | ||
} | ||
|
||
var _ Interface = (*slowpublish)(nil) | ||
|
||
func (sp *cbPublish) Publish(ctx context.Context, br build.Result, ref string) (name.Reference, error) { | ||
return sp.cb(ctx, br, ref) | ||
} | ||
|
||
func (sp *cbPublish) Close() error { | ||
return nil | ||
} | ||
|
||
func TestRecorder(t *testing.T) { | ||
|
||
num := 0 | ||
inner := &cbPublish{cb: func(c context.Context, b build.Result, s string) (name.Reference, error) { | ||
num++ | ||
return name.ParseReference(fmt.Sprintf("ubuntu:%d", num)) | ||
}} | ||
|
||
buf := bytes.NewBuffer(nil) | ||
|
||
recorder, err := NewRecorder(inner, buf) | ||
if err != nil { | ||
t.Fatalf("NewRecorder() = %v", err) | ||
} | ||
|
||
if _, err := recorder.Publish(context.Background(), nil, ""); err != nil { | ||
t.Errorf("recorder.Publish() = %v", err) | ||
} | ||
if _, err := recorder.Publish(context.Background(), nil, ""); err != nil { | ||
t.Errorf("recorder.Publish() = %v", err) | ||
} | ||
if _, err := recorder.Publish(context.Background(), nil, ""); err != nil { | ||
t.Errorf("recorder.Publish() = %v", err) | ||
} | ||
if err := recorder.Close(); err != nil { | ||
t.Errorf("recorder.Close() = %v", err) | ||
} | ||
|
||
want, got := "ubuntu:1\nubuntu:2\nubuntu:3\n", buf.String() | ||
if got != want { | ||
t.Errorf("buf.String() = %s, wanted %s", got, want) | ||
} | ||
} |