From 60fe3d1e85bc874204e02e2dab421ca4760f1ec3 Mon Sep 17 00:00:00 2001 From: Jason Hall Date: Thu, 25 Apr 2019 17:44:04 -0400 Subject: [PATCH] Remove fwd frontend --- README.md | 17 ++++++----- deploy.sh | 4 --- fwd/.gcloudignore | 25 ---------------- fwd/app.go | 58 ------------------------------------ fwd/app.yaml | 13 -------- {fwd => kodata}/favicon.ico | Bin {fwd => kodata}/index.html | 0 main.go | 21 ++++++++----- 8 files changed, 22 insertions(+), 116 deletions(-) delete mode 100644 fwd/.gcloudignore delete mode 100644 fwd/app.go delete mode 100644 fwd/app.yaml rename {fwd => kodata}/favicon.ico (100%) rename {fwd => kodata}/index.html (100%) diff --git a/README.md b/README.md index 3ec83b4..05086f8 100644 --- a/README.md +++ b/README.md @@ -22,12 +22,13 @@ faster. ## How it works -The backend is implemented using [Google Cloud -Run](https://cloud.google.com/run), with an App Engine Go frontend to provide -SSL on a custom domain (source in [`fwd/`](./fwd/)). +The service is implemented using [Google Cloud +Run](https://cloud.google.com/run), with a [custom domain +mapping](https://cloud.google.com/run/docs/mapping-custom-domains) to +https://kontain.me which provides a managed SSL certificate. -When the app receives a request for an image manifest, it parses the request -and generates layers for the requested image, writing the blobs to [Google -Cloud Storage](https://cloud.google.com/storage/). After it receives the -manifest, `docker pull` fetches the blobs. The app simply redirects to Cloud -Storage to serve the blobs. Blobs are deleted after 10 days. +When the service receives a request for an image manifest, it parses the request +and generates layers for the requested image, writing the blobs to [Google Cloud +Storage](https://cloud.google.com/storage/). After it receives the manifest, +`docker pull` fetches the blobs. The app simply redirects to Cloud Storage to +serve the blobs. Blobs are deleted after 10 days. diff --git a/deploy.sh b/deploy.sh index 4371a09..481a5c2 100755 --- a/deploy.sh +++ b/deploy.sh @@ -1,12 +1,8 @@ #!/bin/bash -# Deploy backend KO_DOCKER_REPO=gcr.io/kontainme ko publish -P . && \ gcloud --project=kontainme beta run deploy app \ --image=gcr.io/kontainme/github.com/imjasonh/kontain.me \ --memory=2Gi \ --concurrency=1 \ --region=us-central1 - -# Deploy forwarding frontend -gcloud --project=kontainme app deploy -q fwd/ diff --git a/fwd/.gcloudignore b/fwd/.gcloudignore deleted file mode 100644 index 199e6d9..0000000 --- a/fwd/.gcloudignore +++ /dev/null @@ -1,25 +0,0 @@ -# This file specifies files that are *not* uploaded to Google Cloud Platform -# using gcloud. It follows the same syntax as .gitignore, with the addition of -# "#!include" directives (which insert the entries of the given .gitignore-style -# file at that point). -# -# For more information, run: -# $ gcloud topic gcloudignore -# -.gcloudignore -# If you would like to upload your .git directory, .gitignore file or files -# from your .gitignore file, remove the corresponding line -# below: -.git -.gitignore - -# Binaries for programs and plugins -*.exe -*.exe~ -*.dll -*.so -*.dylib -# Test binary, build with `go test -c` -*.test -# Output of the go coverage tool, specifically when used with LiteIDE -*.out \ No newline at end of file diff --git a/fwd/app.go b/fwd/app.go deleted file mode 100644 index a1aaf91..0000000 --- a/fwd/app.go +++ /dev/null @@ -1,58 +0,0 @@ -// 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 ( - "fmt" - "io" - "log" - "net/http" - "os" -) - -const appJunk = "https://app-an3qnndwmq-uc.a.run.app" - -func main() { - http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - url := fmt.Sprintf("%s%s", appJunk, r.URL.Path) - log.Printf("forwarding to %q", url) - req, err := http.NewRequest(r.Method, url, nil) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - resp, err := http.DefaultClient.Do(req) - if err != nil { - log.Printf("ERROR: %v", err) - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - for k, v := range resp.Header { - w.Header().Set(k, v[0]) - } - log.Printf("forwarding response: %d", resp.StatusCode) - w.WriteHeader(resp.StatusCode) - io.Copy(w, io.TeeReader(resp.Body, os.Stdout)) - }) - - port := os.Getenv("PORT") - if port == "" { - port = "8080" - log.Printf("Defaulting to port %s", port) - } - log.Printf("Listening on port %s", port) - log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", port), nil)) -} diff --git a/fwd/app.yaml b/fwd/app.yaml deleted file mode 100644 index 3cda5a1..0000000 --- a/fwd/app.yaml +++ /dev/null @@ -1,13 +0,0 @@ -runtime: go112 - -handlers: -- url: / - static_files: index.html - upload: index.html - -- url: /favicon.ico - static_files: favicon.ico - upload: favicon.ico - -- url: /.* - script: auto diff --git a/fwd/favicon.ico b/kodata/favicon.ico similarity index 100% rename from fwd/favicon.ico rename to kodata/favicon.ico diff --git a/fwd/index.html b/kodata/index.html similarity index 100% rename from fwd/index.html rename to kodata/index.html diff --git a/main.go b/main.go index 9a8f046..5feec5a 100644 --- a/main.go +++ b/main.go @@ -22,6 +22,7 @@ import ( "io/ioutil" "log" "net/http" + "os" "os/exec" "regexp" "strconv" @@ -30,7 +31,7 @@ import ( "cloud.google.com/go/storage" "github.com/google/go-containerregistry/pkg/name" - "github.com/google/go-containerregistry/pkg/v1" + v1 "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/ko/pkg/build" @@ -40,17 +41,21 @@ import ( const bucket = "kontainme" func main() { - http.HandleFunc("/", handler) + http.HandleFunc("/v2/", handler) + http.Handle("/", http.FileServer(http.Dir("/var/run/ko"))) + log.Println("Starting...") - log.Fatal(http.ListenAndServe(":8080", nil)) + port := os.Getenv("PORT") + if port == "" { + port = "8080" + log.Printf("Defaulting to port %s", port) + } + log.Printf("Listening on port %s", port) + log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", port), nil)) } func handler(w http.ResponseWriter, r *http.Request) { - log.Println(r.Method, r.URL) - if !strings.HasPrefix(r.URL.String(), "/v2/") { - http.Error(w, "not found", http.StatusNotFound) - return - } + log.Println("handler:", r.Method, r.URL) path := strings.TrimPrefix(r.URL.String(), "/v2/") switch {