1
0
mirror of https://github.com/ko-build/ko.git synced 2025-02-07 19:30:23 +02:00

Remove deprecated things. (#162)

Fixes: https://github.com/google/ko/issues/158
Fixes: https://github.com/google/ko/issues/160
This commit is contained in:
Matt Moore 2020-09-24 16:14:58 -07:00 committed by GitHub
parent 8b52ec2374
commit 33e66aca49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 73 deletions

View File

@ -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
@ -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
@ -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
@ -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
@ -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
@ -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
@ -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

View File

@ -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
} 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
p, err := g.importPackage(ref)
if err != nil {
return false
}
return p.IsCommand()
}
// importPackage wraps go/build.Import to handle go modules.

View File

@ -17,6 +17,7 @@ package build
import (
"archive/tar"
"context"
"fmt"
gb "go/build"
"io"
"io/ioutil"
@ -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) {
@ -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) {
@ -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"},
}),
}
@ -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) {
@ -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) {
@ -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)
}
@ -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)
}
@ -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) {
@ -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)
}
@ -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)
}
@ -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)
}
@ -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)
}
@ -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")
}

View File

@ -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()
@ -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 {