diff --git a/cmd/app/kodata/index.html b/cmd/app/kodata/index.html
index 4a872d2..69f7ac4 100644
--- a/cmd/app/kodata/index.html
+++ b/cmd/app/kodata/index.html
@@ -22,13 +22,13 @@ bytes. You can request a specific size and shape of random image. For example,
ko.kontain.me
-docker pull ko.kontain.me/ko/[import path] serves an image
+
docker pull ko.kontain.me/[import path] serves an image
containing a Go binary fetched using go get and built into a
container image using ko.
For example,
-docker pull ko.kontain.me/ko/github.com/google/ko/cmd/ko will fetch,
+docker pull ko.kontain.me/github.com/google/ko/cmd/ko will fetch,
build and (eventually) serve a Docker image containing ko itself.
Koception!
diff --git a/cmd/ko/main.go b/cmd/ko/main.go
index b17d810..190083d 100644
--- a/cmd/ko/main.go
+++ b/cmd/ko/main.go
@@ -76,20 +76,24 @@ func (s *server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
case strings.Contains(path, "/manifests/"):
s.serveKoManifest(w, r)
default:
- serve.Error(w, serve.ErrNotFound)
+ http.Error(w, "Not found", http.StatusNotFound)
}
}
-// konta.in/ko/github.com/knative/build/cmd/controller -> ko build and serve
+// ko.kontain.me/github.com/knative/build/cmd/controller -> ko build and serve
func (s *server) serveKoManifest(w http.ResponseWriter, r *http.Request) {
- path := strings.TrimPrefix(r.URL.Path, "/v2/ko/")
+ path := strings.TrimPrefix(r.URL.Path, "/v2/")
+ path = strings.TrimPrefix(path, "ko/") // To handle legacy behavior.
parts := strings.Split(path, "/")
ip := strings.Join(parts[:len(parts)-2], "/")
+ // "go get" the package
tag := parts[len(parts)-1]
s.info.Printf("requested image tag :%s", tag)
// go get the package.
+ // TODO: Check image tag for version, resolve branches -> commits and redirect to img:
+ // TODO: For requests for commit SHAs, check if it's already built and serve that instead.
s.info.Printf("go get %s...", ip)
if err := run.Do(s.info.Writer(), fmt.Sprintf("go get %s", ip)); err != nil {
s.error.Printf("ERROR (go get): %s", err)
@@ -97,9 +101,6 @@ func (s *server) serveKoManifest(w http.ResponseWriter, r *http.Request) {
return
}
- // TODO: Check image tag for version, resolve branches -> commits and redirect to img:
- // TODO: For requests for commit SHAs, check if it's already built and serve that instead.
-
// ko build the package.
g, err := build.NewGo(
build.WithBaseImages(s.getBaseImage),
@@ -107,20 +108,20 @@ func (s *server) serveKoManifest(w http.ResponseWriter, r *http.Request) {
)
if err != nil {
s.error.Printf("ERROR (build.NewGo): %s", err)
- serve.Error(w, serve.ErrInvalid)
+ serve.Error(w, err)
return
}
ip = build.StrictScheme + ip
if !g.IsSupportedReference(ip) {
s.error.Printf("ERROR (IsSupportedReference(%q)): false", ip)
- serve.Error(w, serve.ErrInvalid)
+ serve.Error(w, fmt.Errorf("Import path %q is not package main", ip))
return
}
s.info.Printf("ko build %s...", ip)
br, err := g.Build(context.Background(), ip)
if err != nil {
s.error.Printf("ERROR (ko build): %s", err)
- serve.Error(w, serve.ErrInvalid)
+ serve.Error(w, err)
return
}
if idx, ok := br.(v1.ImageIndex); ok {
diff --git a/pkg/serve/error.go b/pkg/serve/error.go
index 42f1975..37fe519 100644
--- a/pkg/serve/error.go
+++ b/pkg/serve/error.go
@@ -8,13 +8,10 @@ import (
"github.com/google/go-containerregistry/pkg/v1/remote/transport"
)
-var (
- ErrNotFound = errors.New("repository or commit not found")
- ErrInvalid = errors.New("requested manifest is invalid")
-)
+var ErrNotFound = errors.New("repository or commit not found")
func Error(w http.ResponseWriter, err error) {
- code := "INTERNAL_ERROR"
+ code := "MANIFEST_UNKNOWN"
httpCode := http.StatusNotFound
if terr, ok := err.(*transport.Error); ok {
http.Error(w, "", terr.StatusCode)
@@ -22,13 +19,6 @@ func Error(w http.ResponseWriter, err error) {
return
}
- if err == ErrNotFound {
- code = "MANIFEST_UNKNOWN"
- } else if err == ErrInvalid {
- code = "NAME_INVALID"
- httpCode = http.StatusBadRequest
- }
-
http.Error(w, "", httpCode)
json.NewEncoder(w).Encode(&resp{
Errors: []e{{