Skip to content

Commit

Permalink
Support --tag and --tag-only with nop publisher (#797)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
imjasonh authored Aug 24, 2022
1 parent 568da16 commit f9775dc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 20 additions & 1 deletion pkg/commands/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}

Expand Down Expand Up @@ -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 }
Expand Down

0 comments on commit f9775dc

Please sign in to comment.