Skip to content

Commit c2b862d

Browse files
author
Scott Nichols
authored
Move ko binary to root of project. (ko-build#257)
* Move ko binary to root of project. * go.mod says required golang version is 1.14 * go install uses the folder name * lint and copyright bump * moving the test file changed the test hash. * more refs of cmd/test * add deprecation message
1 parent 64b28d0 commit c2b862d

File tree

16 files changed

+101
-34
lines changed

16 files changed

+101
-34
lines changed

.github/workflows/kind-e2e.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,12 @@ jobs:
131131
- name: Run Smoke Test
132132
run: |
133133
# Test with kind load
134-
KO_DOCKER_REPO=kind.local ko apply --platform=all -f ./cmd/ko/test
134+
KO_DOCKER_REPO=kind.local ko apply --platform=all -f ./test
135135
kubectl wait --timeout=10s --for=condition=Ready pod/kodata
136136
kubectl delete pod kodata
137137
138138
# Test with registry
139-
ko apply --platform=all -f ./cmd/ko/test
139+
ko apply --platform=all -f ./test
140140
kubectl wait --timeout=60s --for=condition=Ready pod/kodata
141141
kubectl delete pod kodata
142142

README.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313

1414
`ko` can be installed and upgraded by running:
1515

16-
**Note**: Golang version `1.12.0` or higher is required.
16+
**Note**: Golang version `1.14.0` or higher is required.
1717

1818
```shell
19-
GO111MODULE=on go get github.com/google/ko/cmd/ko
19+
go get github.com/google/ko
2020
```
2121

2222
## Authenticating
@@ -49,7 +49,7 @@ like `github.com/google/ko/cmd`.
4949

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

@@ -409,27 +409,27 @@ for referencing them should be through the `KO_DATA_PATH` environment variable.
409409
The intent of this is to enable users to test things outside of `ko` as follows:
410410

411411
```shell
412-
KO_DATA_PATH=$PWD/cmd/ko/test/kodata go run ./cmd/ko/test/*.go
412+
KO_DATA_PATH=$PWD/test/kodata go run ./test/*.go
413413
2018/07/19 23:35:20 Hello there
414414
```
415415

416416
This produces identical output to being run within the container locally:
417417

418418
```shell
419-
ko publish -L ./cmd/test
420-
2018/07/19 23:36:11 Using base gcr.io/distroless/static:nonroot for github.com/google/ko/cmd/test
421-
2018/07/19 23:36:12 Loading ko.local/github.com/google/ko/cmd/test:703c205bf2f405af520b40536b87aafadcf181562b8faa6690fd2992084c8577
422-
2018/07/19 23:36:13 Loaded ko.local/github.com/google/ko/cmd/test:703c205bf2f405af520b40536b87aafadcf181562b8faa6690fd2992084c8577
419+
ko publish -L ./test
420+
2018/07/19 23:36:11 Using base gcr.io/distroless/static:nonroot for github.com/google/ko/test
421+
2018/07/19 23:36:12 Loading ko.local/github.com/google/ko/test:703c205bf2f405af520b40536b87aafadcf181562b8faa6690fd2992084c8577
422+
2018/07/19 23:36:13 Loaded ko.local/github.com/google/ko/test:703c205bf2f405af520b40536b87aafadcf181562b8faa6690fd2992084c8577
423423
424-
docker run -ti --rm ko.local/github.com/google/ko/cmd/test:703c205bf2f405af520b40536b87aafadcf181562b8faa6690fd2992084c8577
424+
docker run -ti --rm ko.local/github.com/google/ko/test:703c205bf2f405af520b40536b87aafadcf181562b8faa6690fd2992084c8577
425425
2018/07/19 23:36:25 Hello there
426426
```
427427

428428
... or on cluster:
429429

430430
```shell
431-
ko apply -f cmd/ko/test/test.yaml
432-
2018/07/19 23:38:24 Using base gcr.io/distroless/static:nonroot for github.com/google/ko/cmd/test
431+
ko apply -f test/test.yaml
432+
2018/07/19 23:38:24 Using base gcr.io/distroless/static:nonroot for github.com/google/ko/test
433433
2018/07/19 23:38:25 Publishing us.gcr.io/my-project/test-294a7bdc57d85dc6ddeef5ba38a59fe9:latest
434434
2018/07/19 23:38:26 mounted blob: sha256:988abcba36b5948da8baa1e3616b94c0b56da814b8f6ff3ae3ac316e375e093a
435435
2018/07/19 23:38:26 mounted blob: sha256:57752e7f9593cbfb7101af994b136a369ecc8174332866622db32a264f3fbefd

cmd/ko/main.go

+15
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414

1515
package main
1616

17+
// HEY! YOU! This file has moved to the root of the project.
18+
// !! PLEASE DO NOT ADD NEW FEATURES HERE !!
19+
// Only sync with the root/main.go.
20+
1721
import (
1822
"log"
1923
"os"
@@ -25,6 +29,15 @@ import (
2529
"github.com/spf13/cobra"
2630
)
2731

32+
const Deprecation258 = `NOTICE!
33+
-----------------------------------------------------------------
34+
Please install ko from github.com/google/ko.
35+
36+
For more information see:
37+
https://github.com/google/ko/issues/258
38+
-----------------------------------------------------------------
39+
`
40+
2841
func main() {
2942
logs.Warn.SetOutput(os.Stderr)
3043
logs.Progress.SetOutput(os.Stderr)
@@ -49,6 +62,8 @@ func main() {
4962
// Just add a `ko login` command:
5063
cmds.AddCommand(cranecmd.NewCmdAuthLogin())
5164

65+
log.Print(Deprecation258)
66+
5267
if err := cmds.Execute(); err != nil {
5368
log.Fatalf("error during command execution: %v", err)
5469
}

cmd/ko/test/kodata/HEAD

-1
This file was deleted.

cmd/ko/test/kodata/refs

-1
This file was deleted.

hack/update-deps.sh

+1
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ go mod vendor
2929
# Delete all vendored broken symlinks.
3030
# From https://stackoverflow.com/questions/22097130/delete-all-broken-symbolic-links-with-a-line
3131
find vendor/ -type l -exec sh -c 'for x; do [ -e "$x" ] || rm "$x"; done' _ {} +
32+

integration_test.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ sed -i 's/Hello World/TEST/g' ./vendor/github.com/go-training/helloworld/main.go
2929

3030
echo "Building ko"
3131

32-
RESULT="$(GO111MODULE="on" GOFLAGS="-mod=vendor" go build ./cmd/ko)"
32+
RESULT="$(GO111MODULE="on" GOFLAGS="-mod=vendor" go build .)"
3333

3434
echo "Beginning scenarios."
3535

main.go

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
Copyright 2020 Google LLC All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package main
18+
19+
import (
20+
"log"
21+
"os"
22+
23+
cranecmd "github.com/google/go-containerregistry/cmd/crane/cmd"
24+
"github.com/google/go-containerregistry/pkg/logs"
25+
"github.com/spf13/cobra"
26+
27+
"github.com/google/ko/pkg/commands"
28+
)
29+
30+
func main() {
31+
logs.Warn.SetOutput(os.Stderr)
32+
logs.Progress.SetOutput(os.Stderr)
33+
34+
// Parent command to which all subcommands are added.
35+
cmds := &cobra.Command{
36+
Use: "ko",
37+
Short: "Rapidly iterate with Go, Containers, and Kubernetes.",
38+
Run: func(cmd *cobra.Command, args []string) {
39+
cmd.Help()
40+
},
41+
}
42+
commands.AddKubeCommands(cmds)
43+
44+
// Also add the auth group from crane to facilitate logging into a
45+
// registry.
46+
cmds.AddCommand(cranecmd.NewCmdAuth())
47+
48+
if err := cmds.Execute(); err != nil {
49+
log.Fatal("error during command execution:", err)
50+
}
51+
}

pkg/build/gobuild_test.go

+14-14
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func TestGoBuildIsSupportedRef(t *testing.T) {
4646

4747
// Supported import paths.
4848
for _, importpath := range []string{
49-
"ko://github.com/google/ko/cmd/ko", // ko can build itself.
49+
"ko://github.com/google/ko", // ko can build itself.
5050
} {
5151
t.Run(importpath, func(t *testing.T) {
5252
if err := ng.IsSupportedReference(importpath); err != nil {
@@ -76,7 +76,7 @@ func TestGoBuildIsSupportedRefWithModules(t *testing.T) {
7676

7777
mods := &modules{
7878
main: &modInfo{
79-
Path: "github.com/google/ko/cmd/ko/test",
79+
Path: "github.com/google/ko/test",
8080
Dir: ".",
8181
},
8282
deps: map[string]*modInfo{
@@ -92,8 +92,8 @@ func TestGoBuildIsSupportedRefWithModules(t *testing.T) {
9292
withModuleInfo(mods),
9393
withBuildContext(stubBuildContext{
9494
// make all referenced deps commands
95-
"github.com/google/ko/cmd/ko/test": &gb.Package{Name: "main"},
96-
"github.com/some/module/cmd": &gb.Package{Name: "main"},
95+
"github.com/google/ko/test": &gb.Package{Name: "main"},
96+
"github.com/some/module/cmd": &gb.Package{Name: "main"},
9797

9898
"github.com/google/ko/pkg/build": &gb.Package{Name: "build"},
9999
}),
@@ -106,8 +106,8 @@ func TestGoBuildIsSupportedRefWithModules(t *testing.T) {
106106

107107
// Supported import paths.
108108
for _, importpath := range []string{
109-
"ko://github.com/google/ko/cmd/ko/test", // ko can build the test package.
110-
"ko://github.com/some/module/cmd", // ko can build commands in dependent modules
109+
"ko://github.com/google/ko/test", // ko can build the test package.
110+
"ko://github.com/some/module/cmd", // ko can build commands in dependent modules
111111
} {
112112
t.Run(importpath, func(t *testing.T) {
113113
if err := ng.IsSupportedReference(importpath); err != nil {
@@ -120,7 +120,7 @@ func TestGoBuildIsSupportedRefWithModules(t *testing.T) {
120120
for _, importpath := range []string{
121121
"ko://github.com/google/ko/pkg/build", // not a command.
122122
"ko://github.com/google/ko/pkg/nonexistent", // does not exist.
123-
"ko://github.com/google/ko/cmd/ko", // not in this module.
123+
"ko://github.com/google/ko", // not in this module.
124124
} {
125125
t.Run(importpath, func(t *testing.T) {
126126
if err := ng.IsSupportedReference(importpath); err == nil {
@@ -167,7 +167,7 @@ func TestGoBuildNoKoData(t *testing.T) {
167167
t.Fatalf("NewGo() = %v", err)
168168
}
169169

170-
result, err := ng.Build(context.Background(), StrictScheme+filepath.Join(importpath, "cmd", "ko"))
170+
result, err := ng.Build(context.Background(), StrictScheme+importpath)
171171
if err != nil {
172172
t.Fatalf("Build() = %v", err)
173173
}
@@ -192,7 +192,7 @@ func TestGoBuildNoKoData(t *testing.T) {
192192

193193
// Check that rebuilding the image again results in the same image digest.
194194
t.Run("check determinism", func(t *testing.T) {
195-
result2, err := ng.Build(context.Background(), StrictScheme+filepath.Join(importpath, "cmd", "ko"))
195+
result2, err := ng.Build(context.Background(), StrictScheme+importpath)
196196
if err != nil {
197197
t.Fatalf("Build() = %v", err)
198198
}
@@ -409,7 +409,7 @@ func TestGoBuild(t *testing.T) {
409409
t.Fatalf("NewGo() = %v", err)
410410
}
411411

412-
result, err := ng.Build(context.Background(), StrictScheme+filepath.Join(importpath, "cmd", "ko", "test"))
412+
result, err := ng.Build(context.Background(), StrictScheme+filepath.Join(importpath, "test"))
413413
if err != nil {
414414
t.Fatalf("Build() = %v", err)
415415
}
@@ -423,7 +423,7 @@ func TestGoBuild(t *testing.T) {
423423

424424
// Check that rebuilding the image again results in the same image digest.
425425
t.Run("check determinism", func(t *testing.T) {
426-
result2, err := ng.Build(context.Background(), StrictScheme+filepath.Join(importpath, "cmd", "ko", "test"))
426+
result2, err := ng.Build(context.Background(), StrictScheme+filepath.Join(importpath, "test"))
427427
if err != nil {
428428
t.Fatalf("Build() = %v", err)
429429
}
@@ -465,7 +465,7 @@ func TestGoBuildIndex(t *testing.T) {
465465
t.Fatalf("NewGo() = %v", err)
466466
}
467467

468-
result, err := ng.Build(context.Background(), StrictScheme+filepath.Join(importpath, "cmd", "ko", "test"))
468+
result, err := ng.Build(context.Background(), StrictScheme+filepath.Join(importpath, "test"))
469469
if err != nil {
470470
t.Fatalf("Build() = %v", err)
471471
}
@@ -494,7 +494,7 @@ func TestGoBuildIndex(t *testing.T) {
494494

495495
// Check that rebuilding the image again results in the same image digest.
496496
t.Run("check determinism", func(t *testing.T) {
497-
result2, err := ng.Build(context.Background(), StrictScheme+filepath.Join(importpath, "cmd", "ko", "test"))
497+
result2, err := ng.Build(context.Background(), StrictScheme+filepath.Join(importpath, "test"))
498498
if err != nil {
499499
t.Fatalf("Build() = %v", err)
500500
}
@@ -536,7 +536,7 @@ func TestNestedIndex(t *testing.T) {
536536
t.Fatalf("NewGo() = %v", err)
537537
}
538538

539-
_, err = ng.Build(context.Background(), StrictScheme+filepath.Join(importpath, "cmd", "ko", "test"))
539+
_, err = ng.Build(context.Background(), StrictScheme+filepath.Join(importpath, "test"))
540540
if err == nil {
541541
t.Fatal("Build() expected err")
542542
}

pkg/publish/daemon_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func init() {
4848
}
4949

5050
func TestDaemon(t *testing.T) {
51-
importpath := "github.com/google/ko/cmd/ko"
51+
importpath := "github.com/google/ko"
5252
img, err := random.Image(1024, 1)
5353
if err != nil {
5454
t.Fatalf("random.Image() = %v", err)
@@ -65,7 +65,7 @@ func TestDaemon(t *testing.T) {
6565
func TestDaemonTags(t *testing.T) {
6666
Tags = nil
6767

68-
importpath := "github.com/google/ko/cmd/ko"
68+
importpath := "github.com/google/ko"
6969
img, err := random.Image(1024, 1)
7070
if err != nil {
7171
t.Fatalf("random.Image() = %v", err)
@@ -78,7 +78,7 @@ func TestDaemonTags(t *testing.T) {
7878
t.Errorf("Publish() = %v, wanted prefix %v", got, want)
7979
}
8080

81-
expected := []string{"ko.local/099ba5bcefdead87f92606265fb99ac0:v2.0.0", "ko.local/099ba5bcefdead87f92606265fb99ac0:v1.2.3", "ko.local/099ba5bcefdead87f92606265fb99ac0:production"}
81+
expected := []string{"ko.local/98b8c7facdad74510a7cae0cd368eb4e:v2.0.0", "ko.local/98b8c7facdad74510a7cae0cd368eb4e:v1.2.3", "ko.local/98b8c7facdad74510a7cae0cd368eb4e:production"}
8282

8383
for i, v := range expected {
8484
if Tags[i] != v {
File renamed without changes.

test/kodata/HEAD

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../.git/HEAD
File renamed without changes.

test/kodata/refs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../.git/refs
File renamed without changes.

cmd/ko/test/test.yaml renamed to test/test.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ metadata:
1818
spec:
1919
containers:
2020
- name: obiwan
21-
image: ko://github.com/google/ko/cmd/ko/test
21+
image: ko://github.com/google/ko/test
2222
restartPolicy: Never

0 commit comments

Comments
 (0)