Skip to content

Commit

Permalink
Add a deprecation notice when ko:// is not specified.
Browse files Browse the repository at this point in the history
Related: ko-build#158
  • Loading branch information
mattmoor committed May 3, 2020
1 parent 86ea380 commit e6200fe
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
23 changes: 8 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ paths like `github.com/google/ko/cmd`.

**One of the goals of `ko` is to make containers invisible infrastructure.**
Simply replace image references in your Kubernetes yaml with the import path for
your Go binary, and `ko` will handle containerizing and publishing that
container image as needed.
your Go binary prefixed with `ko://`, and `ko` will handle containerizing and
publishing that container image as needed.

For example, you might use the following in a Kubernetes `Deployment` resource:

Expand All @@ -58,26 +58,19 @@ spec:
containers:
- name: hello-world
# This is the import path for the Go binary to build and run.
image: github.com/mattmoor/examples/http/cmd/helloworld
image: ko://github.com/mattmoor/examples/http/cmd/helloworld
ports:
- containerPort: 8080
```
### Determining supported import paths
### What gets built?
Similar to other tooling in the Go ecosystem, `ko` expects to execute in the
context of your `$GOPATH`. This is used to determine what package(s) `ko`
is expected to build.
`ko` will attempt to containerize and build any string within the yaml prefixed
with `ko://`.

Suppose `GOPATH` is `~/gopath` and the current directory is
`~/gopath/src/github.com/mattmoor/examples`. `ko` will deduce the base import
path to be `github.com/mattmoor/examples`, and any references to subpackages
of this will be built, containerized and published.
The legacy behavior of detecting import paths is deprecated and will be removed
in a coming release.

For example, any of the following would be matched:
* `github.com/mattmoor/examples`
* `github.com/mattmoor/examples/cmd/foo`
* `github.com/mattmoor/examples/bar`

### Results

Expand Down
4 changes: 1 addition & 3 deletions cmd/ko/test/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ apiVersion: v1
kind: Pod
metadata:
name: kodata
annotations:
sidecar.istio.io/inject: "false"
spec:
containers:
- name: obiwan
image: github.com/google/ko/cmd/ko/test
image: ko://github.com/google/ko/cmd/ko/test
restartPolicy: Never
17 changes: 17 additions & 0 deletions pkg/build/gobuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,20 @@ func NewGo(options ...Option) (Interface, error) {
return gbo.Open()
}

const Deprecation158 = `NOTICE!
-----------------------------------------------------------------
We will start requiring ko:// in a coming release. Please prefix
the following import path for things to continue working:
%s
For more information see:
https:/google/ko/issues/158
-----------------------------------------------------------------
`

// IsSupportedReference implements build.Interface
//
// Only valid importpaths that provide commands (i.e., are "package main") are
Expand All @@ -177,6 +191,9 @@ func (g *gobuild) IsSupportedReference(s string) bool {
}
return false
} else if p.IsCommand() {
if !ref.IsStrict() {
log.Printf(Deprecation158, s)
}
return true
} else if ref.IsStrict() {
log.Fatalf(`%q does not have "package main"`, ref.String())
Expand Down
4 changes: 4 additions & 0 deletions pkg/commands/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"fmt"
gb "go/build"
"strings"

"github.com/google/go-containerregistry/pkg/name"
"github.com/google/ko/pkg/build"
Expand Down Expand Up @@ -50,6 +51,9 @@ func publishImages(ctx context.Context, importpaths []string, pub publish.Interf
return nil, err
}
}
if !strings.HasPrefix(importpath, build.StrictScheme) {
importpath = build.StrictScheme + importpath
}

if !b.IsSupportedReference(importpath) {
return nil, fmt.Errorf("importpath %q is not supported", importpath)
Expand Down

0 comments on commit e6200fe

Please sign in to comment.