Last active
October 15, 2018 20:58
-
-
Save kevinjqiu/4828d7b2d9ed1d99b4b49d0b431e01ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM golang:1.8-alpine | |
ADD . /go/src/hello-app | |
RUN go install hello-app | |
FROM alpine:latest | |
COPY --from=0 /go/bin/hello-app . | |
ENV PORT 8080 | |
CMD ["./hello-app"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import requests | |
import math | |
def r(l): | |
print('Trying {}'.format(l)) | |
try: | |
r = requests.get('http://10.138.252.7:8080/?l={}'.format(int(l)), timeout=1) | |
print('Good') | |
return True | |
except requests.exceptions.ReadTimeout: | |
print('Bad') | |
return False | |
def bisect(min, max): | |
if min == max: | |
return r(min) | |
mid = math.floor((min+max)/2) | |
if r(mid): | |
return bisect(mid+1, max) | |
else: | |
return bisect(min, mid) | |
if __name__ == '__main__': | |
good = int(sys.argv[1]) | |
bad = int(sys.argv[2]) | |
bisect(good, bad) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Copyright 2017 Google Inc. | |
* | |
* 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. | |
*/ | |
// [START all] | |
package main | |
import ( | |
"fmt" | |
"log" | |
"net/http" | |
"os" | |
"strconv" | |
"strings" | |
) | |
func main() { | |
// use PORT environment variable, or default to 8080 | |
port := "8080" | |
if fromEnv := os.Getenv("PORT"); fromEnv != "" { | |
port = fromEnv | |
} | |
// register hello function to handle all requests | |
server := http.NewServeMux() | |
server.HandleFunc("/", hello) | |
// start the web server on port and accept requests | |
log.Printf("Server listening on port %s", port) | |
err := http.ListenAndServe(":"+port, server) | |
log.Fatal(err) | |
} | |
// hello responds to the request with a plain-text "Hello, world" message. | |
func hello(w http.ResponseWriter, r *http.Request) { | |
log.Printf("Serving request: %s", r.URL.Path) | |
var ( | |
len int | |
err error | |
) | |
values, ok := r.URL.Query()["l"] | |
if !ok { | |
len = 1 | |
} else { | |
len, err = strconv.Atoi(values[0]) | |
if err != nil { | |
len = 1 | |
} | |
} | |
fmt.Fprintf(w, "%s", strings.Repeat("x", len)) | |
} | |
// [END all] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
push: | |
docker build -t kevinjqiu/hello-app:1 . | |
docker push kevinjqiu/hello-app:1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: v1 | |
kind: Service | |
metadata: | |
labels: | |
run: web | |
name: web-external | |
spec: | |
ports: | |
- port: 8080 | |
protocol: TCP | |
targetPort: 8080 | |
selector: | |
run: web | |
sessionAffinity: None | |
type: LoadBalancer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: v1 | |
kind: Service | |
metadata: | |
annotations: | |
cloud.google.com/load-balancer-type: Internal | |
labels: | |
run: web | |
name: web-internal | |
spec: | |
ports: | |
- port: 8080 | |
protocol: TCP | |
targetPort: 8080 | |
selector: | |
run: web | |
sessionAffinity: None | |
type: LoadBalancer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment