mirror of
https://github.com/imjasonh/kontain.me
synced 2026-07-08 00:55:14 +00:00
Build multi-arch images in ko.kontain.me
Also increase memory and CPU limits to new max for ko and buildpack. Also also return an error when mirroring an unknown media type.
This commit is contained in:
parent
12d902a40a
commit
c9299e2a5e
5 changed files with 63 additions and 12 deletions
|
|
@ -16,6 +16,7 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
|
|
@ -26,6 +27,7 @@ import (
|
|||
"github.com/google/go-containerregistry/pkg/name"
|
||||
v1 "github.com/google/go-containerregistry/pkg/v1"
|
||||
"github.com/google/go-containerregistry/pkg/v1/remote"
|
||||
"github.com/google/go-containerregistry/pkg/v1/types"
|
||||
"github.com/google/ko/pkg/build"
|
||||
"github.com/imjasonh/kontain.me/pkg/run"
|
||||
"github.com/imjasonh/kontain.me/pkg/serve"
|
||||
|
|
@ -74,13 +76,24 @@ func (s *server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
func getDefaultBaseImage(string) (v1.Image, error) {
|
||||
func getDefaultBaseImage(string) (build.Result, error) {
|
||||
// TODO: memoize
|
||||
ref, err := name.ParseReference("gcr.io/distroless/base", name.WeakValidation)
|
||||
ref, err := name.ParseReference("gcr.io/distroless/static:nonroot", name.WeakValidation)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return remote.Image(ref)
|
||||
d, err := remote.Head(ref)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch d.MediaType {
|
||||
case types.DockerManifestList:
|
||||
return remote.Index(ref)
|
||||
case types.DockerManifestSchema2:
|
||||
return remote.Image(ref)
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown media type: %s", d.MediaType)
|
||||
}
|
||||
}
|
||||
|
||||
// konta.in/ko/github.com/knative/build/cmd/controller -> ko build and serve
|
||||
|
|
@ -113,21 +126,32 @@ func (s *server) serveKoManifest(w http.ResponseWriter, r *http.Request) {
|
|||
serve.Error(w, serve.ErrInvalid)
|
||||
return
|
||||
}
|
||||
ip = build.StrictScheme + ip
|
||||
if !g.IsSupportedReference(ip) {
|
||||
s.error.Printf("ERROR (IsSupportedReference): %s", err)
|
||||
serve.Error(w, serve.ErrInvalid)
|
||||
return
|
||||
}
|
||||
s.info.Printf("ko build %s...", ip)
|
||||
img, err := g.Build(context.Background(), ip)
|
||||
br, err := g.Build(context.Background(), ip)
|
||||
if err != nil {
|
||||
s.error.Printf("ERROR (ko build): %s", err)
|
||||
serve.Error(w, serve.ErrInvalid)
|
||||
return
|
||||
}
|
||||
if err := serve.Manifest(w, r, img); err != nil {
|
||||
s.error.Printf("ERROR (serve.Manifest): %v", err)
|
||||
serve.Error(w, err)
|
||||
if idx, ok := br.(v1.ImageIndex); ok {
|
||||
if err := serve.Index(w, r, idx); err != nil {
|
||||
s.error.Printf("ERROR (serve.Index): %v", err)
|
||||
serve.Error(w, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
if img, ok := br.(v1.Image); ok {
|
||||
if err := serve.Manifest(w, r, img); err != nil {
|
||||
s.error.Printf("ERROR (serve.Manifest): %v", err)
|
||||
serve.Error(w, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
serve.Error(w, errors.New("image was not image or index"))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -124,8 +124,11 @@ func (s *server) serveMirrorManifest(w http.ResponseWriter, r *http.Request) {
|
|||
serve.Error(w, err)
|
||||
return
|
||||
}
|
||||
default:
|
||||
err := fmt.Errorf("unknown media type: %s", d.MediaType)
|
||||
s.error.Printf("ERROR (serveMirrorManifest): %v", err)
|
||||
serve.Error(w, err)
|
||||
}
|
||||
|
||||
} else {
|
||||
serve.Blob(w, r, d.Digest.String())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue