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

Add flag and PublishOption for destination repo #351

Merged
merged 4 commits into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ e.g.:
- `KO_DOCKER_REPO=gcr.io/my-project`, or
- `KO_DOCKER_REPO=my-dockerhub-user`

If both the flag and the environment variable are set, the flag value takes
Copy link
Member

Choose a reason for hiding this comment

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

This change can be removed now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

precedence.

# Build an Image

`ko publish ./cmd/app` builds and pushes a container image, and prints the
Expand Down
12 changes: 11 additions & 1 deletion pkg/commands/options/publish.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018 Google LLC All Rights Reserved.
// Copyright 2021 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.
Expand All @@ -17,6 +17,7 @@ package options
import (
"crypto/md5" //nolint: gosec // No strong cryptography needed.
"encoding/hex"
"os"
"path"

"github.com/google/ko/pkg/publish"
Expand All @@ -25,6 +26,9 @@ import (

// PublishOptions encapsulates options when publishing.
type PublishOptions struct {
// DockerRepo configures the destination image repository
DockerRepo string

Tags []string

// Push publishes images to a registry.
Expand All @@ -46,6 +50,12 @@ type PublishOptions struct {
}

func AddPublishArg(cmd *cobra.Command, po *PublishOptions) {
// Set DockerRepo from the KO_DOCKER_REPO envionment variable.
// See https://github.com/google/ko/pull/351 for flag discussion.
if dockerRepo, exists := os.LookupEnv("KO_DOCKER_REPO"); exists {
po.DockerRepo = dockerRepo
}

cmd.Flags().StringSliceVarP(&po.Tags, "tags", "t", []string{"latest"},
"Which tags to use for the produced image instead of the default 'latest' tag "+
"(may not work properly with --base-import-paths or --bare).")
Expand Down
4 changes: 2 additions & 2 deletions pkg/commands/resolver.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018 Google LLC All Rights Reserved.
// Copyright 2021 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.
Expand Down Expand Up @@ -131,7 +131,7 @@ func makePublisher(po *options.PublishOptions) (publish.Interface, error) {
// Create the publish.Interface that we will use to publish image references
// to either a docker daemon or a container image registry.
innerPublisher, err := func() (publish.Interface, error) {
repoName := os.Getenv("KO_DOCKER_REPO")
repoName := po.DockerRepo
namer := options.MakeNamer(po)
if repoName == publish.LocalDomain || po.Local {
// TODO(jonjohnsonjr): I'm assuming that nobody will
Expand Down