Skip to content

Commit

Permalink
Remove deprecated things.
Browse files Browse the repository at this point in the history
Fixes: #158
Fixes: #160
  • Loading branch information
mattmoor committed May 4, 2020
1 parent d45c527 commit eb984f3
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 67 deletions.
21 changes: 7 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ spec:
`ko` will attempt to containerize and build any string within the yaml prefixed
with `ko://`.

The legacy behavior of detecting import paths is deprecated and will be removed
in a coming release.


### Results

Employing this convention enables `ko` to have effectively zero configuration
Expand All @@ -82,14 +78,14 @@ seconds (dominated by two `go build`s).

```shell
$ ko apply -f config/
2018/07/19 14:56:41 Using base gcr.io/distroless/static:latest for github.com/mattmoor/warm-image/cmd/sleeper
2018/07/19 14:56:41 Using base gcr.io/distroless/static:nonroot for github.com/mattmoor/warm-image/cmd/sleeper
2018/07/19 14:56:42 Publishing us.gcr.io/my-project/sleeper-ebdb8b8b13d4bbe1d3592de055016d37:latest
2018/07/19 14:56:43 mounted blob: sha256:57752e7f9593cbfb7101af994b136a369ecc8174332866622db32a264f3fbefd
2018/07/19 14:56:43 mounted blob: sha256:59df9d5b488aea2753ab7774ae41a9a3e96903f87ac699f3505960e744f36f7d
2018/07/19 14:56:43 mounted blob: sha256:739b3deec2edb17c512f507894c55c2681f9724191d820cdc01f668330724ca7
2018/07/19 14:56:44 us.gcr.io/my-project/sleeper-ebdb8b8b13d4bbe1d3592de055016d37:latest: digest: sha256:6c7b96a294cad3ce613aac23c8aca5f9dd12a894354ab276c157fb5c1c2e3326 size: 592
2018/07/19 14:56:44 Published us.gcr.io/my-project/sleeper-ebdb8b8b13d4bbe1d3592de055016d37@sha256:6c7b96a294cad3ce613aac23c8aca5f9dd12a894354ab276c157fb5c1c2e3326
2018/07/19 14:56:45 Using base gcr.io/distroless/static:latest for github.com/mattmoor/warm-image/cmd/controller
2018/07/19 14:56:45 Using base gcr.io/distroless/static:nonroot for github.com/mattmoor/warm-image/cmd/controller
2018/07/19 14:56:46 Publishing us.gcr.io/my-project/controller-9e91872fd7c48124dbe6ea83944b87e9:latest
2018/07/19 14:56:46 mounted blob: sha256:007782ba6738188a59bf21b4d8e974f218615ee948c6357535d07e7248b2a560
2018/07/19 14:56:46 mounted blob: sha256:57752e7f9593cbfb7101af994b136a369ecc8174332866622db32a264f3fbefd
Expand Down Expand Up @@ -124,7 +120,7 @@ an argument. It prints the images' published digests after each image is publish

```shell
$ ko publish github.com/mattmoor/warm-image/cmd/sleeper
2018/07/19 14:57:34 Using base gcr.io/distroless/static:latest for github.com/mattmoor/warm-image/cmd/sleeper
2018/07/19 14:57:34 Using base gcr.io/distroless/static:nonroot for github.com/mattmoor/warm-image/cmd/sleeper
2018/07/19 14:57:35 Publishing us.gcr.io/my-project/sleeper-ebdb8b8b13d4bbe1d3592de055016d37:latest
2018/07/19 14:57:35 mounted blob: sha256:739b3deec2edb17c512f507894c55c2681f9724191d820cdc01f668330724ca7
2018/07/19 14:57:35 mounted blob: sha256:57752e7f9593cbfb7101af994b136a369ecc8174332866622db32a264f3fbefd
Expand All @@ -137,7 +133,7 @@ $ ko publish github.com/mattmoor/warm-image/cmd/sleeper

```shell
$ ko publish ./cmd/sleeper
2018/07/19 14:58:16 Using base gcr.io/distroless/static:latest for github.com/mattmoor/warm-image/cmd/sleeper
2018/07/19 14:58:16 Using base gcr.io/distroless/static:nonroot for github.com/mattmoor/warm-image/cmd/sleeper
2018/07/19 14:58:16 Publishing us.gcr.io/my-project/sleeper-ebdb8b8b13d4bbe1d3592de055016d37:latest
2018/07/19 14:58:17 mounted blob: sha256:59df9d5b488aea2753ab7774ae41a9a3e96903f87ac699f3505960e744f36f7d
2018/07/19 14:58:17 mounted blob: sha256:739b3deec2edb17c512f507894c55c2681f9724191d820cdc01f668330724ca7
Expand Down Expand Up @@ -316,10 +312,7 @@ If neither is present, then `ko` will rely on its default behaviors.

### Overriding the default base image

> Notice: the use of `:latest` will be deprecated in favor of `:nonroot` in a
> coming release. See https://github.com/google/ko/issues/160 for more info.

By default, `ko` makes use of `gcr.io/distroless/static:latest` as the base image
By default, `ko` makes use of `gcr.io/distroless/static:nonroot` as the base image
for containers. There are a wide array of scenarios in which overriding this
makes sense, for example:
1. Pinning to a particular digest of this image for repeatable builds,
Expand Down Expand Up @@ -379,7 +372,7 @@ This produces identical output to being run within the container locally:

```shell
ko publish -L ./cmd/test
2018/07/19 23:36:11 Using base gcr.io/distroless/static:latest for github.com/google/ko/cmd/test
2018/07/19 23:36:11 Using base gcr.io/distroless/static:nonroot for github.com/google/ko/cmd/test
2018/07/19 23:36:12 Loading ko.local/github.com/google/ko/cmd/test:703c205bf2f405af520b40536b87aafadcf181562b8faa6690fd2992084c8577
2018/07/19 23:36:13 Loaded ko.local/github.com/google/ko/cmd/test:703c205bf2f405af520b40536b87aafadcf181562b8faa6690fd2992084c8577
Expand All @@ -391,7 +384,7 @@ docker run -ti --rm ko.local/github.com/google/ko/cmd/test:703c205bf2f405af520b4

```shell
ko apply -f cmd/ko/test/test.yaml
2018/07/19 23:38:24 Using base gcr.io/distroless/static:latest for github.com/google/ko/cmd/test
2018/07/19 23:38:24 Using base gcr.io/distroless/static:nonroot for github.com/google/ko/cmd/test
2018/07/19 23:38:25 Publishing us.gcr.io/my-project/test-294a7bdc57d85dc6ddeef5ba38a59fe9:latest
2018/07/19 23:38:26 mounted blob: sha256:988abcba36b5948da8baa1e3616b94c0b56da814b8f6ff3ae3ac316e375e093a
2018/07/19 23:38:26 mounted blob: sha256:57752e7f9593cbfb7101af994b136a369ecc8174332866622db32a264f3fbefd
Expand Down
32 changes: 6 additions & 26 deletions pkg/build/gobuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,40 +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://github.com/google/ko/issues/158
-----------------------------------------------------------------
`

// IsSupportedReference implements build.Interface
//
// Only valid importpaths that provide commands (i.e., are "package main") are
// supported.
func (g *gobuild) IsSupportedReference(s string) bool {
ref := newRef(s)
if p, err := g.importPackage(ref); err != nil {
if ref.IsStrict() {
log.Fatalf("%q is not supported: %v", ref.String(), err)
}
if !ref.IsStrict() {
return false
}
p, err := g.importPackage(ref)
if err != nil {
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())
}
return false
return p.IsCommand()
}

// importPackage wraps go/build.Import to handle go modules.
Expand Down
29 changes: 18 additions & 11 deletions pkg/build/gobuild_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package build
import (
"archive/tar"
"context"
"fmt"
gb "go/build"
"io"
"io/ioutil"
Expand All @@ -43,7 +44,7 @@ func TestGoBuildIsSupportedRef(t *testing.T) {

// Supported import paths.
for _, importpath := range []string{
"github.com/google/ko/cmd/ko", // ko can build itself.
"ko://github.com/google/ko/cmd/ko", // ko can build itself.
} {
t.Run(importpath, func(t *testing.T) {
if !ng.IsSupportedReference(importpath) {
Expand All @@ -54,8 +55,8 @@ func TestGoBuildIsSupportedRef(t *testing.T) {

// Unsupported import paths.
for _, importpath := range []string{
"github.com/google/ko/pkg/build", // not a command.
"github.com/google/ko/pkg/nonexistent", // does not exist.
"ko://github.com/google/ko/pkg/build", // not a command.
"ko://github.com/google/ko/pkg/nonexistent", // does not exist.
} {
t.Run(importpath, func(t *testing.T) {
if ng.IsSupportedReference(importpath) {
Expand Down Expand Up @@ -91,6 +92,8 @@ func TestGoBuildIsSupportedRefWithModules(t *testing.T) {
// make all referenced deps commands
"github.com/google/ko/cmd/ko/test": &gb.Package{Name: "main"},
"github.com/some/module/cmd": &gb.Package{Name: "main"},

"github.com/google/ko/pkg/build": &gb.Package{Name: "build"},
}),
}

Expand All @@ -101,8 +104,8 @@ func TestGoBuildIsSupportedRefWithModules(t *testing.T) {

// Supported import paths.
for _, importpath := range []string{
"github.com/google/ko/cmd/ko/test", // ko can build the test package.
"github.com/some/module/cmd", // ko can build commands in dependent modules
"ko://github.com/google/ko/cmd/ko/test", // ko can build the test package.
"ko://github.com/some/module/cmd", // ko can build commands in dependent modules
} {
t.Run(importpath, func(t *testing.T) {
if !ng.IsSupportedReference(importpath) {
Expand All @@ -113,9 +116,9 @@ func TestGoBuildIsSupportedRefWithModules(t *testing.T) {

// Unsupported import paths.
for _, importpath := range []string{
"github.com/google/ko/pkg/build", // not a command.
"github.com/google/ko/pkg/nonexistent", // does not exist.
"github.com/google/ko/cmd/ko", // not in this module.
"ko://github.com/google/ko/pkg/build", // not a command.
"ko://github.com/google/ko/pkg/nonexistent", // does not exist.
"ko://github.com/google/ko/cmd/ko", // not in this module.
} {
t.Run(importpath, func(t *testing.T) {
if ng.IsSupportedReference(importpath) {
Expand Down Expand Up @@ -161,7 +164,7 @@ func TestGoBuildNoKoData(t *testing.T) {
t.Fatalf("NewGo() = %v", err)
}

img, err := ng.Build(context.Background(), path.Join(importpath, "cmd", "ko"))
img, err := ng.Build(context.Background(), StrictScheme+path.Join(importpath, "cmd", "ko"))
if err != nil {
t.Fatalf("Build() = %v", err)
}
Expand Down Expand Up @@ -241,7 +244,7 @@ func TestGoBuild(t *testing.T) {
t.Fatalf("NewGo() = %v", err)
}

img, err := ng.Build(context.Background(), path.Join(importpath, "cmd", "ko", "test"))
img, err := ng.Build(context.Background(), StrictScheme+path.Join(importpath, "cmd", "ko", "test"))
if err != nil {
t.Fatalf("Build() = %v", err)
}
Expand Down Expand Up @@ -401,5 +404,9 @@ func TestGoBuild(t *testing.T) {
type stubBuildContext map[string]*gb.Package

func (s stubBuildContext) Import(path string, srcDir string, mode gb.ImportMode) (*gb.Package, error) {
return s[path], nil
p, ok := s[path]
if ok {
return p, nil
}
return nil, fmt.Errorf("not found: %s", path)
}
17 changes: 1 addition & 16 deletions pkg/commands/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,9 @@ func createCancellableContext() context.Context {
return ctx
}

const Deprecation160 = `NOTICE!
-----------------------------------------------------------------
We are changing the default base image in a subsequent release.
For more information (including how to suppress this message):
https://github.com/google/ko/issues/160
-----------------------------------------------------------------
`

func init() {
// If omitted, use this base image.
viper.SetDefault("defaultBaseImage", "gcr.io/distroless/static:nonroot")
viper.SetConfigName(".ko") // .yaml is implicit
viper.SetEnvPrefix("KO")
viper.AutomaticEnv()
Expand All @@ -109,11 +99,6 @@ func init() {
}
}

if !viper.IsSet("defaultBaseImage") {
viper.Set("defaultBaseImage", "gcr.io/distroless/static:latest")
log.Print(Deprecation160)
}

ref := viper.GetString("defaultBaseImage")
dbi, err := name.ParseReference(ref)
if err != nil {
Expand Down

0 comments on commit eb984f3

Please sign in to comment.