mirror of
https://github.com/ko-build/ko.git
synced 2025-07-03 23:30:35 +02:00
Support --tag and --tag-only with nop publisher (#797)
* Support --tag and --tag-only with nop publisher * log the output, for debugging * unset KO_DOCKER_REPO for push=false test * run e2e test first before other stuff * review feedback
This commit is contained in:
5
.github/workflows/e2e.yaml
vendored
5
.github/workflows/e2e.yaml
vendored
@ -33,6 +33,11 @@ jobs:
|
||||
# cribbed from https://gist.github.com/Syeberman/39d81b1e17d091be5657ecd6fbff0753
|
||||
eval $(go env | sed -r 's/^(set )?(\w+)=("?)(.*)\3$/\2="\4"/gm')
|
||||
|
||||
# Check that building without push prints the tag (and sha)
|
||||
KO_DOCKER_REPO="" go run ./ build --push=false ./test | grep ":latest@sha256:"
|
||||
KO_DOCKER_REPO="" go run ./ build --push=false -t test ./test | grep ":test@sha256:"
|
||||
KO_DOCKER_REPO="" go run ./ build --push=false -t test --tag-only ./test | grep ":test$"
|
||||
|
||||
export PLATFORM=${GOOS}/${GOARCH}
|
||||
|
||||
if [[ "${{ matrix.platform }}" == "windows-latest" ]]; then
|
||||
|
@ -224,9 +224,16 @@ func makePublisher(po *options.PublishOptions) (publish.Interface, error) {
|
||||
// If not publishing, at least generate a digest to simulate
|
||||
// publishing.
|
||||
if len(publishers) == 0 {
|
||||
// If one or more tags are specified, use the first tag in the list
|
||||
var tag string
|
||||
if len(po.Tags) >= 1 {
|
||||
tag = po.Tags[0]
|
||||
}
|
||||
publishers = append(publishers, nopPublisher{
|
||||
repoName: repoName,
|
||||
namer: namer,
|
||||
tag: tag,
|
||||
tagOnly: po.TagOnly,
|
||||
})
|
||||
}
|
||||
|
||||
@ -256,15 +263,27 @@ func makePublisher(po *options.PublishOptions) (publish.Interface, error) {
|
||||
type nopPublisher struct {
|
||||
repoName string
|
||||
namer publish.Namer
|
||||
tag string
|
||||
tagOnly bool
|
||||
}
|
||||
|
||||
func (n nopPublisher) Publish(_ context.Context, br build.Result, s string) (name.Reference, error) {
|
||||
s = strings.TrimPrefix(s, build.StrictScheme)
|
||||
nm := n.namer(n.repoName, s)
|
||||
if n.tagOnly {
|
||||
if n.tag == "" {
|
||||
return nil, errors.New("must specify tag if requesting tag only")
|
||||
}
|
||||
return name.NewTag(fmt.Sprintf("%s:%s", nm, n.tag))
|
||||
}
|
||||
h, err := br.Digest()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return name.NewDigest(fmt.Sprintf("%s@%s", n.namer(n.repoName, s), h))
|
||||
if n.tag == "" {
|
||||
return name.NewDigest(fmt.Sprintf("%s@%s", nm, h))
|
||||
}
|
||||
return name.NewDigest(fmt.Sprintf("%s:%s@%s", nm, n.tag, h))
|
||||
}
|
||||
|
||||
func (n nopPublisher) Close() error { return nil }
|
||||
|
Reference in New Issue
Block a user