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

build: Imply current import path #717

Merged
merged 2 commits into from
Jun 16, 2022
Merged
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
19 changes: 9 additions & 10 deletions doc/ko_build.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,26 @@ ko build IMPORTPATH... [flags]

```

# Build and publish import path references to a Docker
# Registry as:
# Build and publish import path references to a Docker Registry as:
# ${KO_DOCKER_REPO}/<package name>-<hash of import path>
# When KO_DOCKER_REPO is ko.local, it is the same as if
# --local and --preserve-import-paths were passed.
# When KO_DOCKER_REPO is ko.local, it is the same as if --local and
# --preserve-import-paths were passed.
# If the import path is not provided, the current working directory is the
# default.
ko build github.com/foo/bar/cmd/baz github.com/foo/bar/cmd/blah

# Build and publish a relative import path as:
# ${KO_DOCKER_REPO}/<package name>-<hash of import path>
# When KO_DOCKER_REPO is ko.local, it is the same as if
# --local and --preserve-import-paths were passed.
# When KO_DOCKER_REPO is ko.local, it is the same as if --local and
# --preserve-import-paths were passed.
ko build ./cmd/blah

# Build and publish a relative import path as:
# ${KO_DOCKER_REPO}/<import path>
# When KO_DOCKER_REPO is ko.local, it is the same as if
# --local was passed.
# When KO_DOCKER_REPO is ko.local, it is the same as if --local was passed.
ko build --preserve-import-paths ./cmd/blah

# Build and publish import path references to a Docker
# daemon as:
# Build and publish import path references to a Docker daemon as:
# ko.local/<import path>
# This always preserves import paths.
ko build --local github.com/foo/bar/cmd/baz github.com/foo/bar/cmd/blah
Expand Down
25 changes: 14 additions & 11 deletions pkg/commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,36 +32,39 @@ func addBuild(topLevel *cobra.Command) {
Long: `This sub-command builds the provided import paths into Go binaries, containerizes them, and publishes them.`,
Aliases: []string{"publish"},
Example: `
# Build and publish import path references to a Docker
# Registry as:
# Build and publish import path references to a Docker Registry as:
# ${KO_DOCKER_REPO}/<package name>-<hash of import path>
# When KO_DOCKER_REPO is ko.local, it is the same as if
# --local and --preserve-import-paths were passed.
# When KO_DOCKER_REPO is ko.local, it is the same as if --local and
# --preserve-import-paths were passed.
# If the import path is not provided, the current working directory is the
# default.
ko build github.com/foo/bar/cmd/baz github.com/foo/bar/cmd/blah

# Build and publish a relative import path as:
# ${KO_DOCKER_REPO}/<package name>-<hash of import path>
# When KO_DOCKER_REPO is ko.local, it is the same as if
# --local and --preserve-import-paths were passed.
# When KO_DOCKER_REPO is ko.local, it is the same as if --local and
# --preserve-import-paths were passed.
ko build ./cmd/blah

# Build and publish a relative import path as:
# ${KO_DOCKER_REPO}/<import path>
# When KO_DOCKER_REPO is ko.local, it is the same as if
# --local was passed.
# When KO_DOCKER_REPO is ko.local, it is the same as if --local was passed.
ko build --preserve-import-paths ./cmd/blah

# Build and publish import path references to a Docker
# daemon as:
# Build and publish import path references to a Docker daemon as:
# ko.local/<import path>
# This always preserves import paths.
ko build --local github.com/foo/bar/cmd/baz github.com/foo/bar/cmd/blah`,
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if err := options.Validate(po, bo); err != nil {
return fmt.Errorf("validating options: %w", err)
}

if len(args) == 0 {
// Build the current directory by default.
args = []string{"."}
}

ctx := cmd.Context()

bo.InsecureRegistry = po.InsecureRegistry
Expand Down