Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move ko binary to root of project. #257

Merged
merged 7 commits into from
Dec 22, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@

`ko` can be installed and upgraded by running:

**Note**: Golang version `1.12.0` or higher is required.
**Note**: Golang version `1.14.0` or higher is required.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is 1.14 required now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is what the go mod file says.


```shell
GO111MODULE=on go get github.com/google/ko/cmd/ko
go get github.com/google/ko
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should we do for users that install from cmd/ko today in scripts? This change would break them without a lot of help about what changed or how to fix it.

Can we keep cmd/ko/main.go as an alias for a release or two with a deprecation warning?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was always my plan to keep both. We have a lot of tooling that hardcodes installing ko from the ./cmd/ko path.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change would break them without a lot of help about what changed or how to fix it.

It never broke them, I left ./cmd/ko in the PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did drop ./cmd/ko/test

```

## Authenticating
Expand Down Expand Up @@ -49,7 +49,7 @@ like `github.com/google/ko/cmd`.

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

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

```shell
KO_DATA_PATH=$PWD/cmd/ko/test/kodata go run ./cmd/ko/test/*.go
KO_DATA_PATH=$PWD/test/kodata go run ./test/*.go
2018/07/19 23:35:20 Hello there
```

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: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
2018/07/19 23:36:11 Using base gcr.io/distroless/static:nonroot for github.com/google/ko/test
2018/07/19 23:36:12 Loading ko.local/github.com/google/ko/test:703c205bf2f405af520b40536b87aafadcf181562b8faa6690fd2992084c8577
2018/07/19 23:36:13 Loaded ko.local/github.com/google/ko/test:703c205bf2f405af520b40536b87aafadcf181562b8faa6690fd2992084c8577

docker run -ti --rm ko.local/github.com/google/ko/cmd/test:703c205bf2f405af520b40536b87aafadcf181562b8faa6690fd2992084c8577
docker run -ti --rm ko.local/github.com/google/ko/test:703c205bf2f405af520b40536b87aafadcf181562b8faa6690fd2992084c8577
2018/07/19 23:36:25 Hello there
```

... or on cluster:

```shell
ko apply -f cmd/ko/test/test.yaml
ko apply -f test/test.yaml
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
Expand Down
1 change: 0 additions & 1 deletion cmd/ko/test/kodata/HEAD

This file was deleted.

1 change: 0 additions & 1 deletion cmd/ko/test/kodata/refs

This file was deleted.

5 changes: 5 additions & 0 deletions hack/update-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,8 @@ go mod vendor
# Delete all vendored broken symlinks.
# From https://stackoverflow.com/questions/22097130/delete-all-broken-symbolic-links-with-a-line
find vendor/ -type l -exec sh -c 'for x; do [ -e "$x" ] || rm "$x"; done' _ {} +


# HACK HACK HACK:
# Until we can cleanly remove it, copy root ko.go and move it to ./cmd/ko
cp ${PROJECT_ROOT}/ko.go ${PROJECT_ROOT}/cmd/ko/main.go
2 changes: 1 addition & 1 deletion integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ sed -i 's/Hello World/TEST/g' ./vendor/github.com/go-training/helloworld/main.go

echo "Building ko"

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

echo "Beginning scenarios."

Expand Down
49 changes: 49 additions & 0 deletions ko.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2018 Google LLC All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
"log"
"os"

"github.com/google/go-containerregistry/pkg/logs"
"github.com/google/ko/pkg/commands"

cranecmd "github.com/google/go-containerregistry/cmd/crane/cmd"
"github.com/spf13/cobra"
)

func main() {
n3wscott marked this conversation as resolved.
Show resolved Hide resolved
logs.Warn.SetOutput(os.Stderr)
logs.Progress.SetOutput(os.Stderr)

// Parent command to which all subcommands are added.
cmds := &cobra.Command{
Use: "ko",
Short: "Rapidly iterate with Go, Containers, and Kubernetes.",
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
},
}
commands.AddKubeCommands(cmds)

// Also add the auth group from crane to facilitate logging into a
// registry.
cmds.AddCommand(cranecmd.NewCmdAuth())

if err := cmds.Execute(); err != nil {
log.Fatalf("error during command execution: %v", err)
}
}
24 changes: 12 additions & 12 deletions pkg/build/gobuild_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestGoBuildIsSupportedRef(t *testing.T) {

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

mods := &modules{
main: &modInfo{
Path: "github.com/google/ko/cmd/ko/test",
Path: "github.com/google/ko/test",
Dir: ".",
},
deps: map[string]*modInfo{
Expand All @@ -92,7 +92,7 @@ func TestGoBuildIsSupportedRefWithModules(t *testing.T) {
withModuleInfo(mods),
withBuildContext(stubBuildContext{
// make all referenced deps commands
"github.com/google/ko/cmd/ko/test": &gb.Package{Name: "main"},
"github.com/google/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 @@ -106,7 +106,7 @@ func TestGoBuildIsSupportedRefWithModules(t *testing.T) {

// Supported import paths.
for _, importpath := range []string{
"ko://github.com/google/ko/cmd/ko/test", // ko can build the test package.
"ko://github.com/google/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) {
Expand All @@ -120,7 +120,7 @@ func TestGoBuildIsSupportedRefWithModules(t *testing.T) {
for _, importpath := range []string{
"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.
"ko://github.com/google/ko", // not in this module.
} {
t.Run(importpath, func(t *testing.T) {
if err := ng.IsSupportedReference(importpath); err == nil {
Expand Down Expand Up @@ -166,7 +166,7 @@ func TestGoBuildNoKoData(t *testing.T) {
t.Fatalf("NewGo() = %v", err)
}

result, err := ng.Build(context.Background(), StrictScheme+filepath.Join(importpath, "cmd", "ko"))
result, err := ng.Build(context.Background(), StrictScheme+importpath)
if err != nil {
t.Fatalf("Build() = %v", err)
}
Expand All @@ -191,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(), StrictScheme+filepath.Join(importpath, "cmd", "ko"))
result2, err := ng.Build(context.Background(), StrictScheme+importpath)
if err != nil {
t.Fatalf("Build() = %v", err)
}
Expand Down Expand Up @@ -407,7 +407,7 @@ func TestGoBuild(t *testing.T) {
t.Fatalf("NewGo() = %v", err)
}

result, err := ng.Build(context.Background(), StrictScheme+filepath.Join(importpath, "cmd", "ko", "test"))
result, err := ng.Build(context.Background(), StrictScheme+filepath.Join(importpath, "test"))
if err != nil {
t.Fatalf("Build() = %v", err)
}
Expand All @@ -421,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(), StrictScheme+filepath.Join(importpath, "cmd", "ko", "test"))
result2, err := ng.Build(context.Background(), StrictScheme+filepath.Join(importpath, "test"))
if err != nil {
t.Fatalf("Build() = %v", err)
}
Expand Down Expand Up @@ -461,7 +461,7 @@ func TestGoBuildIndex(t *testing.T) {
t.Fatalf("NewGo() = %v", err)
}

result, err := ng.Build(context.Background(), StrictScheme+filepath.Join(importpath, "cmd", "ko", "test"))
result, err := ng.Build(context.Background(), StrictScheme+filepath.Join(importpath, "test"))
if err != nil {
t.Fatalf("Build() = %v", err)
}
Expand Down Expand Up @@ -490,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(), StrictScheme+filepath.Join(importpath, "cmd", "ko", "test"))
result2, err := ng.Build(context.Background(), StrictScheme+filepath.Join(importpath, "test"))
if err != nil {
t.Fatalf("Build() = %v", err)
}
Expand Down Expand Up @@ -531,7 +531,7 @@ func TestNestedIndex(t *testing.T) {
t.Fatalf("NewGo() = %v", err)
}

_, err = ng.Build(context.Background(), StrictScheme+filepath.Join(importpath, "cmd", "ko", "test"))
_, err = ng.Build(context.Background(), StrictScheme+filepath.Join(importpath, "test"))
if err == nil {
t.Fatal("Build() expected err")
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/publish/daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func init() {
}

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

importpath := "github.com/google/ko/cmd/ko"
importpath := "github.com/google/ko"
img, err := random.Image(1024, 1)
if err != nil {
t.Fatalf("random.Image() = %v", err)
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions test/kodata/HEAD
File renamed without changes.
1 change: 1 addition & 0 deletions test/kodata/refs
File renamed without changes.
2 changes: 1 addition & 1 deletion cmd/ko/test/test.yaml → test/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ metadata:
spec:
containers:
- name: obiwan
image: ko://github.com/google/ko/cmd/ko/test
image: ko://github.com/google/ko/test
restartPolicy: Never