1
0
Fork 0
mirror of https://github.com/imjasonh/kontain.me synced 2026-07-08 09:04:54 +00:00

Try to migrate to GCP buildpacks

- use Go modulesa
- support paths in repos, since GCP samples are in subdirs
- use curl to fetch archives instead of wget, since GCP builder doesn't have wget
- remove -helpers=true which GCP buildpacks don't support

/lifecycle/exporter fails because GCR auth helper isn't setup, possibly
because -helpers isn't around anymore?
This commit is contained in:
Jason Hall 2020-05-29 17:59:22 -04:00
parent 7f6572d0a2
commit 11f3b02add
7 changed files with 62 additions and 421 deletions

View file

@ -1,6 +1,6 @@
baseImageOverrides:
github.com/imjasonh/kontain.me/cmd/ko: golang
github.com/imjasonh/kontain.me/cmd/buildpack: packs/samples:v3alpha2
github.com/imjasonh/kontain.me/cmd/buildpack: gcr.io/buildpacks/builder
github.com/imjasonh/kontain.me/cmd/viz: gcr.io/kontainme/graphviz
# Works with any of:

330
Gopkg.lock generated
View file

@ -1,330 +0,0 @@
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
[[projects]]
digest = "1:a325ce61868a1a85c2d8ce43bf4d00734d6419ae85853338c2b5951c11bcc594"
name = "cloud.google.com/go"
packages = [
"compute/metadata",
"datastore",
"iam",
"internal",
"internal/fields",
"internal/optional",
"internal/trace",
"internal/version",
"storage",
]
pruneopts = "UT"
revision = "8c41231e01b2085512d98153bcffb847ff9b4b9f"
version = "v0.38.0"
[[projects]]
digest = "1:6f9339c912bbdda81302633ad7e99a28dfa5a639c864061f1929510a9a64aa74"
name = "github.com/dustin/go-humanize"
packages = ["."]
pruneopts = "UT"
revision = "9f541cc9db5d55bce703bd99987c9d5cb8eea45e"
version = "v1.0.0"
[[projects]]
digest = "1:499b09c6fecbec76e839ef9acf07af100219048ed22b3ca7d78948ae2767e781"
name = "github.com/golang/protobuf"
packages = [
"proto",
"protoc-gen-go/descriptor",
"ptypes",
"ptypes/any",
"ptypes/duration",
"ptypes/struct",
"ptypes/timestamp",
"ptypes/wrappers",
]
pruneopts = "UT"
revision = "b5d812f8a3706043e23a9cd5babf2e5423744d30"
version = "v1.3.1"
[[projects]]
branch = "master"
digest = "1:476ba1ddf3f2329d3677f84c2b5e7d3635465ec5d85bc70050cbead931dda760"
name = "github.com/google/go-containerregistry"
packages = [
"pkg/authn",
"pkg/name",
"pkg/v1",
"pkg/v1/empty",
"pkg/v1/mutate",
"pkg/v1/partial",
"pkg/v1/random",
"pkg/v1/remote",
"pkg/v1/remote/transport",
"pkg/v1/stream",
"pkg/v1/tarball",
"pkg/v1/types",
"pkg/v1/v1util",
]
pruneopts = "UT"
revision = "1c6c7f61e8a5402b606c3c6db169fdcd1b0712b7"
[[projects]]
digest = "1:dc103a2b0c588c87eaae0ba653b36c6bf79f0cd2d5914fa6d9e0fa2d7ee4219f"
name = "github.com/google/ko"
packages = ["pkg/build"]
pruneopts = "UT"
revision = "021e392d3a3d2c318c79f34c4dd15da2402afce9"
version = "v0.1"
[[projects]]
digest = "1:582b704bebaa06b48c29b0cec224a6058a09c86883aaddabde889cd1a5f73e1b"
name = "github.com/google/uuid"
packages = ["."]
pruneopts = "UT"
revision = "0cd6bf5da1e1c83f8b45653022c74f71af0538a4"
version = "v1.1.1"
[[projects]]
digest = "1:f1f70abea1ab125d48396343b4c053f8fecfbdb943037bf3d29dc80c90fe60b3"
name = "github.com/googleapis/gax-go"
packages = ["v2"]
pruneopts = "UT"
revision = "beaecbbdd8af86aa3acf14180d53828ce69400b2"
version = "v2.0.4"
[[projects]]
digest = "1:67474f760e9ac3799f740db2c489e6423a4cde45520673ec123ac831ad849cb8"
name = "github.com/hashicorp/golang-lru"
packages = ["simplelru"]
pruneopts = "UT"
revision = "7087cb70de9f7a8bc0a10c375cb0d2280a8edf9c"
version = "v0.5.1"
[[projects]]
branch = "master"
digest = "1:b2a3ee6c6584219e30393fe61a85e9a10a7d9f966b7d66e9fedeb5ee5642195e"
name = "github.com/tmc/dot"
packages = ["."]
pruneopts = "UT"
revision = "6d252d5ff882ba9963502860f30ab3673c6c7322"
[[projects]]
digest = "1:429596ab6fea904f2ea2a74de9c95692e39a5a6269e778b770676374e7063f3e"
name = "go.opencensus.io"
packages = [
".",
"internal",
"internal/tagencoding",
"metric/metricdata",
"metric/metricproducer",
"plugin/ocgrpc",
"plugin/ochttp",
"plugin/ochttp/propagation/b3",
"resource",
"stats",
"stats/internal",
"stats/view",
"tag",
"trace",
"trace/internal",
"trace/propagation",
"trace/tracestate",
]
pruneopts = "UT"
revision = "df6e2001952312404b06f5f6f03fcb4aec1648e5"
version = "v0.21.0"
[[projects]]
branch = "master"
digest = "1:f04f91f699638081f3d9659950764321bc0602076fc5fd8177c18b185ad3fdd8"
name = "golang.org/x/net"
packages = [
"context",
"context/ctxhttp",
"http/httpguts",
"http2",
"http2/hpack",
"idna",
"internal/timeseries",
"trace",
]
pruneopts = "UT"
revision = "f4e77d36d62c17c2336347bb2670ddbd02d092b7"
[[projects]]
branch = "master"
digest = "1:645cb780e4f3177111b40588f0a7f5950efcfb473e7ff41d8d81b2ba5eaa6ed5"
name = "golang.org/x/oauth2"
packages = [
".",
"google",
"internal",
"jws",
"jwt",
]
pruneopts = "UT"
revision = "9f3314589c9a9136388751d9adae6b0ed400978a"
[[projects]]
branch = "master"
digest = "1:b521f10a2d8fa85c04a8ef4e62f2d1e14d303599a55d64dabf9f5a02f84d35eb"
name = "golang.org/x/sync"
packages = ["errgroup"]
pruneopts = "UT"
revision = "112230192c580c3556b8cee6403af37a4fc5f28c"
[[projects]]
branch = "master"
digest = "1:f42e547cbcaa2cf6548b0bb27a350f75db23340d062877fb534c06eb57934e8c"
name = "golang.org/x/sys"
packages = ["unix"]
pruneopts = "UT"
revision = "12bbe5a7a5209180b72cc7e3ed9da40442fe3246"
[[projects]]
digest = "1:8d8faad6b12a3a4c819a3f9618cb6ee1fa1cfc33253abeeea8b55336721e3405"
name = "golang.org/x/text"
packages = [
"collate",
"collate/build",
"internal/colltab",
"internal/gen",
"internal/language",
"internal/language/compact",
"internal/tag",
"internal/triegen",
"internal/ucd",
"language",
"secure/bidirule",
"transform",
"unicode/bidi",
"unicode/cldr",
"unicode/norm",
"unicode/rangetable",
]
pruneopts = "UT"
revision = "342b2e1fbaa52c93f31447ad2c6abc048c63e475"
version = "v0.3.2"
[[projects]]
digest = "1:5547ddc83919a19761cd976ed633ac3fd20e53341150140ba085d4569c8cbcdc"
name = "google.golang.org/api"
packages = [
"cloudbuild/v1",
"gensupport",
"googleapi",
"googleapi/internal/uritemplates",
"googleapi/transport",
"internal",
"iterator",
"option",
"storage/v1",
"transport",
"transport/grpc",
"transport/http",
"transport/http/internal/propagation",
]
pruneopts = "UT"
revision = "067bed655e9cbc26f4dbac8f8897b30756d90990"
version = "v0.4.0"
[[projects]]
digest = "1:15b86ee56687b2b842431678dacd1050900cd5ea24a47fa908ac32ce540664b7"
name = "google.golang.org/appengine"
packages = [
".",
"internal",
"internal/app_identity",
"internal/base",
"internal/datastore",
"internal/log",
"internal/modules",
"internal/remote_api",
"internal/socket",
"internal/urlfetch",
"socket",
"urlfetch",
]
pruneopts = "UT"
revision = "54a98f90d1c46b7731eb8fb305d2a321c30ef610"
version = "v1.5.0"
[[projects]]
branch = "master"
digest = "1:8507e4270c1e2fc10a8536a1ca832529b070307ce2b3aa1c82b285f205793871"
name = "google.golang.org/genproto"
packages = [
"googleapis/api/annotations",
"googleapis/datastore/v1",
"googleapis/iam/v1",
"googleapis/rpc/code",
"googleapis/rpc/status",
"googleapis/type/latlng",
]
pruneopts = "UT"
revision = "54afdca5d873f7b529e2ce3def1a99df16feda90"
[[projects]]
digest = "1:10e315fc07ce6c3252fc2467b10434e5bd742941d9d405cde49a13333dcf136a"
name = "google.golang.org/grpc"
packages = [
".",
"balancer",
"balancer/base",
"balancer/roundrobin",
"binarylog/grpc_binarylog_v1",
"codes",
"connectivity",
"credentials",
"credentials/internal",
"credentials/oauth",
"encoding",
"encoding/proto",
"grpclog",
"internal",
"internal/backoff",
"internal/balancerload",
"internal/binarylog",
"internal/channelz",
"internal/envconfig",
"internal/grpcrand",
"internal/grpcsync",
"internal/syscall",
"internal/transport",
"keepalive",
"metadata",
"naming",
"peer",
"resolver",
"resolver/dns",
"resolver/passthrough",
"stats",
"status",
"tap",
]
pruneopts = "UT"
revision = "25c4f928eaa6d96443009bd842389fb4fa48664e"
version = "v1.20.1"
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
input-imports = [
"cloud.google.com/go/compute/metadata",
"cloud.google.com/go/datastore",
"cloud.google.com/go/storage",
"github.com/dustin/go-humanize",
"github.com/google/go-containerregistry/pkg/authn",
"github.com/google/go-containerregistry/pkg/name",
"github.com/google/go-containerregistry/pkg/v1",
"github.com/google/go-containerregistry/pkg/v1/random",
"github.com/google/go-containerregistry/pkg/v1/remote",
"github.com/google/go-containerregistry/pkg/v1/types",
"github.com/google/ko/pkg/build",
"github.com/google/uuid",
"github.com/tmc/dot",
"golang.org/x/oauth2",
"google.golang.org/api/cloudbuild/v1",
"google.golang.org/api/googleapi",
"google.golang.org/api/option",
]
solver-name = "gps-cdcl"
solver-version = 1

View file

@ -1,46 +0,0 @@
# Gopkg.toml example
#
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"
#
# [prune]
# non-go = false
# go-tests = true
# unused-packages = true
[[constraint]]
name = "cloud.google.com/go"
version = "0.38.0"
[[constraint]]
branch = "master"
name = "github.com/google/go-containerregistry"
[[constraint]]
name = "github.com/google/ko"
version = "0.1.0"
[[constraint]]
name = "google.golang.org/api"
version = "0.4.0"
[prune]
go-tests = true
unused-packages = true

View file

@ -10,6 +10,7 @@ import (
"log"
"net/http"
"os"
"path/filepath"
"strings"
"time"
@ -106,16 +107,18 @@ func (s *server) serveBuildpackManifest(w http.ResponseWriter, r *http.Request)
}()
// Determine source repo and revision.
path := strings.TrimPrefix(r.URL.Path, "/v2/ko/")
parts := strings.Split(path, "/")
repo := strings.Join(parts[2:len(parts)-2], "/")
if repo == "" || repo == "buildpack" {
repo = "buildpack/sample-java-app"
}
parts := strings.Split(r.URL.Path, "/")
repo := strings.Join(parts[2:4], "/")
path := strings.Join(parts[4:len(parts)-2], "/")
revision := parts[len(parts)-1]
if revision == "latest" {
revision = "master"
}
if repo == "" || repo == "buildpack" {
repo = "googlecloudplatform/buildpack-samples"
path = "sample-go"
}
// Resolve branch/tag/whatever -> SHA
revision, err = s.resolveCommit(repo, revision)
if err != nil {
@ -133,7 +136,7 @@ func (s *server) serveBuildpackManifest(w http.ResponseWriter, r *http.Request)
}
// Fetch, detect and build source.
image, err := s.fetchAndBuild(src, layers, repo, revision)
image, err := s.fetchAndBuild(src, layers, repo, revision, path)
if err != nil {
s.error.Println("ERROR:", err)
serve.Error(w, err)
@ -229,7 +232,7 @@ func (s *server) prepareWorkspace() (string, string, error) {
return src, layers, nil
}
func (s *server) fetchAndBuild(src, layers, repo, revision string) (string, error) {
func (s *server) fetchAndBuild(src, layers, repo, revision, path string) (string, error) {
image := fmt.Sprintf("gcr.io/%s/built-%d", projectID, time.Now().Unix)
source := fmt.Sprintf("https://github.com/%s/archive/%s.tar.gz", repo, revision)
@ -241,15 +244,17 @@ func (s *server) fetchAndBuild(src, layers, repo, revision string) (string, erro
return "", fmt.Errorf("HEAD %s (%d): %s", source, resp.StatusCode, resp.Status)
}
srcpath := filepath.Join(src, path)
for _, cmd := range []string{
fmt.Sprintf("chown -R %d:%d %s", os.Geteuid(), os.Getgid(), src),
fmt.Sprintf("chown -R %d:%d %s", os.Geteuid(), os.Getgid(), layers),
fmt.Sprintf("wget -qO- %s | tar xvz --strip-components=1 -C %s", source, src),
fmt.Sprintf("ls -R %s", src),
fmt.Sprintf("/lifecycle/detector -app=%s -group=%s/group.toml -plan=%s/plan.toml", src, layers, layers),
fmt.Sprintf("/lifecycle/analyzer -layers=%s -helpers=true -group=%s/group.toml %s", layers, layers, image),
fmt.Sprintf("/lifecycle/builder -layers=%s -app=%s -group=%s/group.toml -plan=%s/plan.toml", layers, src, layers, layers),
fmt.Sprintf("/lifecycle/exporter -layers=%s -helpers=true -app=%s -image=%s -group=%s/group.toml %s", layers, src, base, layers, image),
fmt.Sprintf("curl -fsSL %s | tar xvz --strip-components=1 -C %s", source, src),
fmt.Sprintf("cd %s", srcpath),
fmt.Sprintf("/lifecycle/detector -app=%s -group=%s/group.toml -plan=%s/plan.toml", srcpath, layers, layers),
fmt.Sprintf("/lifecycle/analyzer -layers=%s -group=%s/group.toml %s", layers, layers, image),
fmt.Sprintf("/lifecycle/builder -layers=%s -app=%s -group=%s/group.toml -plan=%s/plan.toml", layers, srcpath, layers, layers),
fmt.Sprintf("/lifecycle/exporter -layers=%s -app=%s -image=%s -group=%s/group.toml %s", layers, srcpath, base, layers, image),
} {
if err := run.Do(s.info.Writer(), cmd); err != nil {
return "", fmt.Errorf("Running %q: %v", cmd, err)

View file

@ -2,55 +2,64 @@
set -euxo pipefail
project=kontainme
region=us-central1
case ${1:-"all"} in
viz | all)
docker build -t gcr.io/kontainme/graphviz -f cmd/viz/Dockerfile cmd/viz/
docker push gcr.io/kontainme/graphviz
KO_DOCKER_REPO=gcr.io/kontainme ko publish -P ./cmd/viz && \
gcloud --project=kontainme beta run deploy viz \
--image=gcr.io/kontainme/github.com/imjasonh/kontain.me/cmd/viz \
--region=us-central1
docker build -t gcr.io/${project}/graphviz -f cmd/viz/Dockerfile cmd/viz/
docker push gcr.io/${project}/graphviz
KO_DOCKER_REPO=gcr.io/${project} ko publish -P ./cmd/viz && \
gcloud --project=${project} beta run deploy viz \
--image=gcr.io/${project}/github.com/imjasonh/kontain.me/cmd/viz \
--region=${region} \
--platform=managed
;;
api | all)
KO_DOCKER_REPO=gcr.io/kontainme ko publish -P ./cmd/api && \
gcloud --project=kontainme beta run deploy api \
--image=gcr.io/kontainme/github.com/imjasonh/kontain.me/cmd/api \
KO_DOCKER_REPO=gcr.io/${project} ko publish -P ./cmd/api && \
gcloud --project=${project} beta run deploy api \
--image=gcr.io/${project}/github.com/imjasonh/kontain.me/cmd/api \
--memory=2Gi \
--concurrency=1 \
--region=us-central1
--region=${region} \
--platform=managed
;;
app | all)
KO_DOCKER_REPO=gcr.io/kontainme ko publish -P ./cmd/app && \
gcloud --project=kontainme beta run deploy app \
--image=gcr.io/kontainme/github.com/imjasonh/kontain.me/cmd/app \
--region=us-central1
KO_DOCKER_REPO=gcr.io/${project} ko publish -P ./cmd/app && \
gcloud --project=${project} beta run deploy app \
--image=gcr.io/${project}/github.com/imjasonh/kontain.me/cmd/app \
--region=${region} \
--platform=managed
;;
random | all)
KO_DOCKER_REPO=gcr.io/kontainme ko publish -P ./cmd/random && \
gcloud --project=kontainme beta run deploy random \
--image=gcr.io/kontainme/github.com/imjasonh/kontain.me/cmd/random \
--region=us-central1
KO_DOCKER_REPO=gcr.io/${project} ko publish -P ./cmd/random && \
gcloud --project=${project} beta run deploy random \
--image=gcr.io/${project}/github.com/imjasonh/kontain.me/cmd/random \
--region=${region} \
--platform=managed
;;
ko | all)
KO_DOCKER_REPO=gcr.io/kontainme ko publish -P ./cmd/ko && \
gcloud --project=kontainme beta run deploy ko \
--image=gcr.io/kontainme/github.com/imjasonh/kontain.me/cmd/ko \
KO_DOCKER_REPO=gcr.io/${project} ko publish -P ./cmd/ko && \
gcloud --project=${project} beta run deploy ko \
--image=gcr.io/${project}/github.com/imjasonh/kontain.me/cmd/ko \
--memory=2Gi \
--concurrency=1 \
--region=us-central1
--region=${region} \
--platform=managed
;;
buildpack | all)
KO_DOCKER_REPO=gcr.io/kontainme ko publish -P ./cmd/buildpack && \
gcloud --project=kontainme beta run deploy buildpack \
--image=gcr.io/kontainme/github.com/imjasonh/kontain.me/cmd/buildpack \
KO_DOCKER_REPO=gcr.io/${project} ko publish -P ./cmd/buildpack && \
gcloud --project=${project} beta run deploy buildpack \
--image=gcr.io/${project}/github.com/imjasonh/kontain.me/cmd/buildpack \
--memory=2Gi \
--concurrency=1 \
--region=us-central1
--region=${region} \
--platform=managed
;;
esac

3
go.mod Normal file
View file

@ -0,0 +1,3 @@
module github.com/imjasonh/kontain.me
go 1.14

View file

@ -9,11 +9,11 @@ time docker pull random.kontain.me/random:8x80
time docker pull ko.kontain.me/ko/github.com/knative/build/cmd/controller
time docker pull buildpack.kontain.me/buildpack/sample-java-app
time docker pull buildpack.kontain.me/buildpack/sample-java-app # caching!
time docker pull buildpack.kontain.me/buildpack/samples/apps/java-maven
time docker pull buildpack.kontain.me/buildpack/samples/apps/java-maven # caching!
tmp=$(mktemp -d)
git clone git@github.com:buildpack/sample-java-app.git $tmp
git clone git@github.com:buildpack/samples/ $tmp
project=$(gcloud config get-value project)
CLOUDSDK_API_ENDPOINT_OVERRIDES_CLOUDBUILD=https://api-an3qnndwmq-uc.a.run.app/ gcloud builds submit --tag=gcr.io/$project/built $tmp
CLOUDSDK_API_ENDPOINT_OVERRIDES_CLOUDBUILD=https://api-an3qnndwmq-uc.a.run.app/ gcloud builds submit --tag=gcr.io/$project/built $tmp/apps/java-maven
rm $tmp