@@ -35,8 +35,8 @@ paths like `github.com/google/ko/cmd`.
35
35
36
36
** One of the goals of ` ko ` is to make containers invisible infrastructure.**
37
37
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.
40
40
41
41
For example, you might use the following in a Kubernetes ` Deployment ` resource:
42
42
@@ -58,26 +58,19 @@ spec:
58
58
containers :
59
59
- name : hello-world
60
60
# 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
62
62
ports :
63
63
- containerPort : 8080
64
64
` ` `
65
65
66
- ### Determining supported import paths
66
+ ### What gets built?
67
67
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://`.
71
70
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.
76
73
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`
81
74
82
75
# ## Results
83
76
@@ -89,14 +82,14 @@ seconds (dominated by two `go build`s).
89
82
90
83
` ` ` shell
91
84
$ 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
93
86
2018/07/19 14:56:42 Publishing us.gcr.io/my-project/sleeper-ebdb8b8b13d4bbe1d3592de055016d37:latest
94
87
2018/07/19 14:56:43 mounted blob: sha256:57752e7f9593cbfb7101af994b136a369ecc8174332866622db32a264f3fbefd
95
88
2018/07/19 14:56:43 mounted blob: sha256:59df9d5b488aea2753ab7774ae41a9a3e96903f87ac699f3505960e744f36f7d
96
89
2018/07/19 14:56:43 mounted blob: sha256:739b3deec2edb17c512f507894c55c2681f9724191d820cdc01f668330724ca7
97
90
2018/07/19 14:56:44 us.gcr.io/my-project/sleeper-ebdb8b8b13d4bbe1d3592de055016d37:latest: digest: sha256:6c7b96a294cad3ce613aac23c8aca5f9dd12a894354ab276c157fb5c1c2e3326 size: 592
98
91
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
100
93
2018/07/19 14:56:46 Publishing us.gcr.io/my-project/controller-9e91872fd7c48124dbe6ea83944b87e9:latest
101
94
2018/07/19 14:56:46 mounted blob: sha256:007782ba6738188a59bf21b4d8e974f218615ee948c6357535d07e7248b2a560
102
95
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
131
124
132
125
` ` ` shell
133
126
$ 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
135
128
2018/07/19 14:57:35 Publishing us.gcr.io/my-project/sleeper-ebdb8b8b13d4bbe1d3592de055016d37:latest
136
129
2018/07/19 14:57:35 mounted blob: sha256:739b3deec2edb17c512f507894c55c2681f9724191d820cdc01f668330724ca7
137
130
2018/07/19 14:57:35 mounted blob: sha256:57752e7f9593cbfb7101af994b136a369ecc8174332866622db32a264f3fbefd
@@ -144,7 +137,7 @@ $ ko publish github.com/mattmoor/warm-image/cmd/sleeper
144
137
145
138
` ` ` shell
146
139
$ 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
148
141
2018/07/19 14:58:16 Publishing us.gcr.io/my-project/sleeper-ebdb8b8b13d4bbe1d3592de055016d37:latest
149
142
2018/07/19 14:58:17 mounted blob: sha256:59df9d5b488aea2753ab7774ae41a9a3e96903f87ac699f3505960e744f36f7d
150
143
2018/07/19 14:58:17 mounted blob: sha256:739b3deec2edb17c512f507894c55c2681f9724191d820cdc01f668330724ca7
@@ -218,9 +211,9 @@ spec:
218
211
It is notable that this is not the default (anymore) because certain popular
219
212
registries (including Docker Hub) do not support multi-level repository names.
220
213
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`.
224
217
225
218
In the case of `ko resolve`, `--selector` will render only the resources that are selected by the provided selector.
226
219
@@ -323,7 +316,10 @@ If neither is present, then `ko` will rely on its default behaviors.
323
316
324
317
# ## Overriding the default base image
325
318
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
327
323
for containers. There are a wide array of scenarios in which overriding this
328
324
makes sense, for example :
329
325
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:
383
379
384
380
` ` ` shell
385
381
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
387
383
2018/07/19 23:36:12 Loading ko.local/github.com/google/ko/cmd/test:703c205bf2f405af520b40536b87aafadcf181562b8faa6690fd2992084c8577
388
384
2018/07/19 23:36:13 Loaded ko.local/github.com/google/ko/cmd/test:703c205bf2f405af520b40536b87aafadcf181562b8faa6690fd2992084c8577
389
385
@@ -395,7 +391,7 @@ docker run -ti --rm ko.local/github.com/google/ko/cmd/test:703c205bf2f405af520b4
395
391
396
392
` ` ` shell
397
393
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
399
395
2018/07/19 23:38:25 Publishing us.gcr.io/my-project/test-294a7bdc57d85dc6ddeef5ba38a59fe9:latest
400
396
2018/07/19 23:38:26 mounted blob: sha256:988abcba36b5948da8baa1e3616b94c0b56da814b8f6ff3ae3ac316e375e093a
401
397
2018/07/19 23:38:26 mounted blob: sha256:57752e7f9593cbfb7101af994b136a369ecc8174332866622db32a264f3fbefd
@@ -419,7 +415,7 @@ ko completion
419
415
To use the completion script, you can copy the script in your bash_completion directory (e.g. /usr/local/etc/bash_completion.d/) :
420
416
` ` `
421
417
ko completion > /usr/local/etc/bash_completion.d/ko
422
- ` ` `
418
+ ` ` `
423
419
or source it in your shell by running :
424
420
` ` `
425
421
source <(ko completion)
0 commit comments