Skip to content

Commit d45c527

Browse files
authored
This adds the deprecation notices for ko:// and nonroot (ko-build#161)
* Add a deprecation notice when `defaultBaseImage` is not specified. Related: ko-build#160 * Add a deprecation notice when `ko://` is not specified. Related: ko-build#158 * Add a sample import path.
1 parent 6cbfe96 commit d45c527

File tree

6 files changed

+61
-30
lines changed

6 files changed

+61
-30
lines changed

.ko.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
defaultBaseImage: gcr.io/distroless/static:nonroot

README.md

+22-26
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ paths like `github.com/google/ko/cmd`.
3535

3636
**One of the goals of `ko` is to make containers invisible infrastructure.**
3737
Simply replace image references in your Kubernetes yaml with the import path for
38-
your Go binary, and `ko` will handle containerizing and publishing that
39-
container image as needed.
38+
your Go binary prefixed with `ko://` (e.g. `ko://github.com/google/ko/cmd/ko`),
39+
and `ko` will handle containerizing and publishing that container image as needed.
4040

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

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

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

77-
For example, any of the following would be matched:
78-
* `github.com/mattmoor/examples`
79-
* `github.com/mattmoor/examples/cmd/foo`
80-
* `github.com/mattmoor/examples/bar`
8174

8275
### Results
8376

@@ -89,14 +82,14 @@ seconds (dominated by two `go build`s).
8982

9083
```shell
9184
$ ko apply -f config/
92-
2018/07/19 14:56:41 Using base gcr.io/distroless/base:latest for github.com/mattmoor/warm-image/cmd/sleeper
85+
2018/07/19 14:56:41 Using base gcr.io/distroless/static:latest for github.com/mattmoor/warm-image/cmd/sleeper
9386
2018/07/19 14:56:42 Publishing us.gcr.io/my-project/sleeper-ebdb8b8b13d4bbe1d3592de055016d37:latest
9487
2018/07/19 14:56:43 mounted blob: sha256:57752e7f9593cbfb7101af994b136a369ecc8174332866622db32a264f3fbefd
9588
2018/07/19 14:56:43 mounted blob: sha256:59df9d5b488aea2753ab7774ae41a9a3e96903f87ac699f3505960e744f36f7d
9689
2018/07/19 14:56:43 mounted blob: sha256:739b3deec2edb17c512f507894c55c2681f9724191d820cdc01f668330724ca7
9790
2018/07/19 14:56:44 us.gcr.io/my-project/sleeper-ebdb8b8b13d4bbe1d3592de055016d37:latest: digest: sha256:6c7b96a294cad3ce613aac23c8aca5f9dd12a894354ab276c157fb5c1c2e3326 size: 592
9891
2018/07/19 14:56:44 Published us.gcr.io/my-project/sleeper-ebdb8b8b13d4bbe1d3592de055016d37@sha256:6c7b96a294cad3ce613aac23c8aca5f9dd12a894354ab276c157fb5c1c2e3326
99-
2018/07/19 14:56:45 Using base gcr.io/distroless/base:latest for github.com/mattmoor/warm-image/cmd/controller
92+
2018/07/19 14:56:45 Using base gcr.io/distroless/static:latest for github.com/mattmoor/warm-image/cmd/controller
10093
2018/07/19 14:56:46 Publishing us.gcr.io/my-project/controller-9e91872fd7c48124dbe6ea83944b87e9:latest
10194
2018/07/19 14:56:46 mounted blob: sha256:007782ba6738188a59bf21b4d8e974f218615ee948c6357535d07e7248b2a560
10295
2018/07/19 14:56:46 mounted blob: sha256:57752e7f9593cbfb7101af994b136a369ecc8174332866622db32a264f3fbefd
@@ -131,7 +124,7 @@ an argument. It prints the images' published digests after each image is publish
131124

132125
```shell
133126
$ ko publish github.com/mattmoor/warm-image/cmd/sleeper
134-
2018/07/19 14:57:34 Using base gcr.io/distroless/base:latest for github.com/mattmoor/warm-image/cmd/sleeper
127+
2018/07/19 14:57:34 Using base gcr.io/distroless/static:latest for github.com/mattmoor/warm-image/cmd/sleeper
135128
2018/07/19 14:57:35 Publishing us.gcr.io/my-project/sleeper-ebdb8b8b13d4bbe1d3592de055016d37:latest
136129
2018/07/19 14:57:35 mounted blob: sha256:739b3deec2edb17c512f507894c55c2681f9724191d820cdc01f668330724ca7
137130
2018/07/19 14:57:35 mounted blob: sha256:57752e7f9593cbfb7101af994b136a369ecc8174332866622db32a264f3fbefd
@@ -144,7 +137,7 @@ $ ko publish github.com/mattmoor/warm-image/cmd/sleeper
144137

145138
```shell
146139
$ ko publish ./cmd/sleeper
147-
2018/07/19 14:58:16 Using base gcr.io/distroless/base:latest for github.com/mattmoor/warm-image/cmd/sleeper
140+
2018/07/19 14:58:16 Using base gcr.io/distroless/static:latest for github.com/mattmoor/warm-image/cmd/sleeper
148141
2018/07/19 14:58:16 Publishing us.gcr.io/my-project/sleeper-ebdb8b8b13d4bbe1d3592de055016d37:latest
149142
2018/07/19 14:58:17 mounted blob: sha256:59df9d5b488aea2753ab7774ae41a9a3e96903f87ac699f3505960e744f36f7d
150143
2018/07/19 14:58:17 mounted blob: sha256:739b3deec2edb17c512f507894c55c2681f9724191d820cdc01f668330724ca7
@@ -218,9 +211,9 @@ spec:
218211
It is notable that this is not the default (anymore) because certain popular
219212
registries (including Docker Hub) do not support multi-level repository names.
220213

221-
`ko resolve`, `ko apply`, and `ko create` accept an optional `--selector` or `-l`
222-
flag, similar to `kubectl`, which can be used to filter the resources from the
223-
input Kubernetes YAMLs by their `metadata.labels`.
214+
`ko resolve`, `ko apply`, and `ko create` accept an optional `--selector` or `-l`
215+
flag, similar to `kubectl`, which can be used to filter the resources from the
216+
input Kubernetes YAMLs by their `metadata.labels`.
224217

225218
In the case of `ko resolve`, `--selector` will render only the resources that are selected by the provided selector.
226219

@@ -323,7 +316,10 @@ If neither is present, then `ko` will rely on its default behaviors.
323316

324317
### Overriding the default base image
325318

326-
By default, `ko` makes use of `gcr.io/distroless/base:latest` as the base image
319+
> Notice: the use of `:latest` will be deprecated in favor of `:nonroot` in a
320+
> coming release. See https://github.com/google/ko/issues/160 for more info.
321+
322+
By default, `ko` makes use of `gcr.io/distroless/static:latest` as the base image
327323
for containers. There are a wide array of scenarios in which overriding this
328324
makes sense, for example:
329325
1. Pinning to a particular digest of this image for repeatable builds,
@@ -383,7 +379,7 @@ This produces identical output to being run within the container locally:
383379

384380
```shell
385381
ko publish -L ./cmd/test
386-
2018/07/19 23:36:11 Using base gcr.io/distroless/base:latest for github.com/google/ko/cmd/test
382+
2018/07/19 23:36:11 Using base gcr.io/distroless/static:latest for github.com/google/ko/cmd/test
387383
2018/07/19 23:36:12 Loading ko.local/github.com/google/ko/cmd/test:703c205bf2f405af520b40536b87aafadcf181562b8faa6690fd2992084c8577
388384
2018/07/19 23:36:13 Loaded ko.local/github.com/google/ko/cmd/test:703c205bf2f405af520b40536b87aafadcf181562b8faa6690fd2992084c8577
389385
@@ -395,7 +391,7 @@ docker run -ti --rm ko.local/github.com/google/ko/cmd/test:703c205bf2f405af520b4
395391

396392
```shell
397393
ko apply -f cmd/ko/test/test.yaml
398-
2018/07/19 23:38:24 Using base gcr.io/distroless/base:latest for github.com/google/ko/cmd/test
394+
2018/07/19 23:38:24 Using base gcr.io/distroless/static:latest for github.com/google/ko/cmd/test
399395
2018/07/19 23:38:25 Publishing us.gcr.io/my-project/test-294a7bdc57d85dc6ddeef5ba38a59fe9:latest
400396
2018/07/19 23:38:26 mounted blob: sha256:988abcba36b5948da8baa1e3616b94c0b56da814b8f6ff3ae3ac316e375e093a
401397
2018/07/19 23:38:26 mounted blob: sha256:57752e7f9593cbfb7101af994b136a369ecc8174332866622db32a264f3fbefd
@@ -419,7 +415,7 @@ ko completion
419415
To use the completion script, you can copy the script in your bash_completion directory (e.g. /usr/local/etc/bash_completion.d/):
420416
```
421417
ko completion > /usr/local/etc/bash_completion.d/ko
422-
```
418+
```
423419
or source it in your shell by running:
424420
```
425421
source <(ko completion)

cmd/ko/test/test.yaml

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ apiVersion: v1
1515
kind: Pod
1616
metadata:
1717
name: kodata
18-
annotations:
19-
sidecar.istio.io/inject: "false"
2018
spec:
2119
containers:
2220
- name: obiwan
23-
image: github.com/google/ko/cmd/ko/test
21+
image: ko://github.com/google/ko/cmd/ko/test
2422
restartPolicy: Never

pkg/build/gobuild.go

+17
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,20 @@ func NewGo(options ...Option) (Interface, error) {
165165
return gbo.Open()
166166
}
167167

168+
const Deprecation158 = `NOTICE!
169+
-----------------------------------------------------------------
170+
We will start requiring ko:// in a coming release. Please prefix
171+
the following import path for things to continue working:
172+
173+
%s
174+
175+
For more information see:
176+
177+
https://github.com/google/ko/issues/158
178+
179+
-----------------------------------------------------------------
180+
`
181+
168182
// IsSupportedReference implements build.Interface
169183
//
170184
// Only valid importpaths that provide commands (i.e., are "package main") are
@@ -177,6 +191,9 @@ func (g *gobuild) IsSupportedReference(s string) bool {
177191
}
178192
return false
179193
} else if p.IsCommand() {
194+
if !ref.IsStrict() {
195+
log.Printf(Deprecation158, s)
196+
}
180197
return true
181198
} else if ref.IsStrict() {
182199
log.Fatalf(`%q does not have "package main"`, ref.String())

pkg/commands/config.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,19 @@ func createCancellableContext() context.Context {
8080
return ctx
8181
}
8282

83+
const Deprecation160 = `NOTICE!
84+
-----------------------------------------------------------------
85+
We are changing the default base image in a subsequent release.
86+
87+
For more information (including how to suppress this message):
88+
89+
https://github.com/google/ko/issues/160
90+
91+
-----------------------------------------------------------------
92+
`
93+
8394
func init() {
8495
// If omitted, use this base image.
85-
viper.SetDefault("defaultBaseImage", "gcr.io/distroless/static:latest")
8696
viper.SetConfigName(".ko") // .yaml is implicit
8797
viper.SetEnvPrefix("KO")
8898
viper.AutomaticEnv()
@@ -99,6 +109,11 @@ func init() {
99109
}
100110
}
101111

112+
if !viper.IsSet("defaultBaseImage") {
113+
viper.Set("defaultBaseImage", "gcr.io/distroless/static:latest")
114+
log.Print(Deprecation160)
115+
}
116+
102117
ref := viper.GetString("defaultBaseImage")
103118
dbi, err := name.ParseReference(ref)
104119
if err != nil {

pkg/commands/publisher.go

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"context"
1919
"fmt"
2020
gb "go/build"
21+
"strings"
2122

2223
"github.com/google/go-containerregistry/pkg/name"
2324
"github.com/google/ko/pkg/build"
@@ -50,6 +51,9 @@ func publishImages(ctx context.Context, importpaths []string, pub publish.Interf
5051
return nil, err
5152
}
5253
}
54+
if !strings.HasPrefix(importpath, build.StrictScheme) {
55+
importpath = build.StrictScheme + importpath
56+
}
5357

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

0 commit comments

Comments
 (0)