Skip to content

Commit

Permalink
build: Imply current import path (ko-build#717)
Browse files Browse the repository at this point in the history
* build: Imply current import path

* update generated docs
  • Loading branch information
imjasonh authored Jun 16, 2022
1 parent 821a4a7 commit 1a5551d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
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

0 comments on commit 1a5551d

Please sign in to comment.