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 Sep 24, 2020
1 parent 8b52ec2 commit 1f56214
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 73 deletions.
24 changes: 9 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,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 +79,14 @@ containerize, and redeploy a non-trivial Kubernetes controller app in seconds

```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 @@ -129,7 +126,7 @@ published.

```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 @@ -143,7 +140,7 @@ on `GOPATH`.

```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 @@ -354,12 +351,9 @@ 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 for containers. There are a wide array of scenarios in which overriding
this makes sense, for example:
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,
1. Replacing this streamlined base image with another with better debugging
Expand Down Expand Up @@ -417,7 +411,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 @@ -429,7 +423,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 @@ -168,40 +168,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
39 changes: 23 additions & 16 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 Down Expand Up @@ -45,7 +46,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 @@ -56,8 +57,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 @@ -93,6 +94,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 @@ -103,8 +106,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 @@ -115,9 +118,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 @@ -163,7 +166,7 @@ func TestGoBuildNoKoData(t *testing.T) {
t.Fatalf("NewGo() = %v", err)
}

result, err := ng.Build(context.Background(), filepath.Join(importpath, "cmd", "ko"))
result, err := ng.Build(context.Background(), StrictScheme+filepath.Join(importpath, "cmd", "ko"))
if err != nil {
t.Fatalf("Build() = %v", err)
}
Expand All @@ -188,7 +191,7 @@ func TestGoBuildNoKoData(t *testing.T) {

// Check that rebuilding the image again results in the same image digest.
t.Run("check determinism", func(t *testing.T) {
result2, err := ng.Build(context.Background(), filepath.Join(importpath, "cmd", "ko"))
result2, err := ng.Build(context.Background(), StrictScheme+filepath.Join(importpath, "cmd", "ko"))
if err != nil {
t.Fatalf("Build() = %v", err)
}
Expand Down Expand Up @@ -379,7 +382,11 @@ func validateImage(t *testing.T, img v1.Image, baseLayers int64, creationTime v1
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)
}

func TestGoBuild(t *testing.T) {
Expand All @@ -400,7 +407,7 @@ func TestGoBuild(t *testing.T) {
t.Fatalf("NewGo() = %v", err)
}

result, err := ng.Build(context.Background(), filepath.Join(importpath, "cmd", "ko", "test"))
result, err := ng.Build(context.Background(), StrictScheme+filepath.Join(importpath, "cmd", "ko", "test"))
if err != nil {
t.Fatalf("Build() = %v", err)
}
Expand All @@ -414,7 +421,7 @@ func TestGoBuild(t *testing.T) {

// Check that rebuilding the image again results in the same image digest.
t.Run("check determinism", func(t *testing.T) {
result2, err := ng.Build(context.Background(), filepath.Join(importpath, "cmd", "ko", "test"))
result2, err := ng.Build(context.Background(), StrictScheme+filepath.Join(importpath, "cmd", "ko", "test"))
if err != nil {
t.Fatalf("Build() = %v", err)
}
Expand Down Expand Up @@ -454,7 +461,7 @@ func TestGoBuildIndex(t *testing.T) {
t.Fatalf("NewGo() = %v", err)
}

result, err := ng.Build(context.Background(), filepath.Join(importpath, "cmd", "ko", "test"))
result, err := ng.Build(context.Background(), StrictScheme+filepath.Join(importpath, "cmd", "ko", "test"))
if err != nil {
t.Fatalf("Build() = %v", err)
}
Expand Down Expand Up @@ -483,7 +490,7 @@ func TestGoBuildIndex(t *testing.T) {

// Check that rebuilding the image again results in the same image digest.
t.Run("check determinism", func(t *testing.T) {
result2, err := ng.Build(context.Background(), filepath.Join(importpath, "cmd", "ko", "test"))
result2, err := ng.Build(context.Background(), StrictScheme+filepath.Join(importpath, "cmd", "ko", "test"))
if err != nil {
t.Fatalf("Build() = %v", err)
}
Expand Down Expand Up @@ -524,7 +531,7 @@ func TestNestedIndex(t *testing.T) {
t.Fatalf("NewGo() = %v", err)
}

_, err = ng.Build(context.Background(), filepath.Join(importpath, "cmd", "ko", "test"))
_, err = ng.Build(context.Background(), StrictScheme+filepath.Join(importpath, "cmd", "ko", "test"))
if err == nil {
t.Fatal("Build() expected err")
}
Expand Down
17 changes: 1 addition & 16 deletions pkg/commands/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,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 @@ -159,11 +149,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 1f56214

Please sign in to comment.