1
0
Fork 0
mirror of https://github.com/imjasonh/kontain.me synced 2026-07-21 22:48:19 +00:00

Remove fwd frontend

This commit is contained in:
Jason Hall 2019-04-25 17:44:04 -04:00
parent c1447b830a
commit 60fe3d1e85
8 changed files with 22 additions and 116 deletions

View file

@ -22,12 +22,13 @@ faster.
## How it works ## How it works
The backend is implemented using [Google Cloud The service is implemented using [Google Cloud
Run](https://cloud.google.com/run), with an App Engine Go frontend to provide Run](https://cloud.google.com/run), with a [custom domain
SSL on a custom domain (source in [`fwd/`](./fwd/)). 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 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 and generates layers for the requested image, writing the blobs to [Google Cloud
Cloud Storage](https://cloud.google.com/storage/). After it receives the Storage](https://cloud.google.com/storage/). After it receives the manifest,
manifest, `docker pull` fetches the blobs. The app simply redirects to Cloud `docker pull` fetches the blobs. The app simply redirects to Cloud Storage to
Storage to serve the blobs. Blobs are deleted after 10 days. serve the blobs. Blobs are deleted after 10 days.

View file

@ -1,12 +1,8 @@
#!/bin/bash #!/bin/bash
# Deploy backend
KO_DOCKER_REPO=gcr.io/kontainme ko publish -P . && \ KO_DOCKER_REPO=gcr.io/kontainme ko publish -P . && \
gcloud --project=kontainme beta run deploy app \ gcloud --project=kontainme beta run deploy app \
--image=gcr.io/kontainme/github.com/imjasonh/kontain.me \ --image=gcr.io/kontainme/github.com/imjasonh/kontain.me \
--memory=2Gi \ --memory=2Gi \
--concurrency=1 \ --concurrency=1 \
--region=us-central1 --region=us-central1
# Deploy forwarding frontend
gcloud --project=kontainme app deploy -q fwd/

View file

@ -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

View file

@ -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))
}

View file

@ -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

View file

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

Before After
Before After

21
main.go
View file

@ -22,6 +22,7 @@ import (
"io/ioutil" "io/ioutil"
"log" "log"
"net/http" "net/http"
"os"
"os/exec" "os/exec"
"regexp" "regexp"
"strconv" "strconv"
@ -30,7 +31,7 @@ import (
"cloud.google.com/go/storage" "cloud.google.com/go/storage"
"github.com/google/go-containerregistry/pkg/name" "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/random"
"github.com/google/go-containerregistry/pkg/v1/remote" "github.com/google/go-containerregistry/pkg/v1/remote"
"github.com/google/ko/pkg/build" "github.com/google/ko/pkg/build"
@ -40,17 +41,21 @@ import (
const bucket = "kontainme" const bucket = "kontainme"
func main() { func main() {
http.HandleFunc("/", handler) http.HandleFunc("/v2/", handler)
http.Handle("/", http.FileServer(http.Dir("/var/run/ko")))
log.Println("Starting...") 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) { func handler(w http.ResponseWriter, r *http.Request) {
log.Println(r.Method, r.URL) log.Println("handler:", r.Method, r.URL)
if !strings.HasPrefix(r.URL.String(), "/v2/") {
http.Error(w, "not found", http.StatusNotFound)
return
}
path := strings.TrimPrefix(r.URL.String(), "/v2/") path := strings.TrimPrefix(r.URL.String(), "/v2/")
switch { switch {