devenv: unify slow_proxy_mac and slow_proxy (#34630)

* devenv: update slow_proxy block to work on mac

* devenv: removed unnecessary block slow_proxy_mac
This commit is contained in:
Gábor Farkas 2021-05-27 08:44:35 +02:00 committed by GitHub
parent 20d356947c
commit 49126bebaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 13 additions and 66 deletions

View File

@ -1,2 +1,2 @@
ORIGIN_SERVER=http://localhost:9090/
ORIGIN_SERVER=http://host.docker.internal:9090/
SLEEP_DURATION=60s

View File

@ -1,7 +1,10 @@
FROM golang:latest
FROM golang:latest as builder
ADD main.go /
WORKDIR /
RUN GO111MODULE=off go build -o main .
RUN GO111MODULE=off CGO_ENABLED=0 go build -o main .
FROM scratch
WORKDIR /
EXPOSE 3011
COPY --from=builder /main /main
ENTRYPOINT ["/main"]

View File

@ -1,8 +1,9 @@
slow_proxy:
build: docker/blocks/slow_proxy
network_mode: host
ports:
- "3011:3011"
extra_hosts:
- "host.docker.internal:host-gateway"
environment:
ORIGIN_SERVER: ${ORIGIN_SERVER}
SLEEP_DURATION: ${SLEEP_DURATION}

View File

@ -12,12 +12,14 @@ import (
func main() {
origin := os.Getenv("ORIGIN_SERVER")
if origin == "" {
origin = "http://localhost:9090/"
// it is never not-set, the default is in the `.env` file
log.Fatalf("missing env-variable ORIGIN_SERVER")
}
sleepDurationStr := os.Getenv("SLEEP_DURATION")
if sleepDurationStr == "" {
sleepDurationStr = "60s"
// it is never not-set, the default is in the `.env` file
log.Fatalf("missing env-variable SLEEP_DURATION")
}
sleep, err := time.ParseDuration(sleepDurationStr)

View File

@ -1,2 +0,0 @@
ORIGIN_SERVER=http://host.docker.internal:9090/
SLEEP_DURATION=60s

View File

@ -1,10 +0,0 @@
FROM golang:latest as builder
ADD main.go /
WORKDIR /
RUN GO111MODULE=off CGO_ENABLED=0 go build -o main .
FROM scratch
WORKDIR /
EXPOSE 3011
COPY --from=builder /main /main
ENTRYPOINT ["/main"]

View File

@ -1,7 +0,0 @@
slow_proxy_mac:
build: docker/blocks/slow_proxy_mac
ports:
- '3011:3011'
environment:
ORIGIN_SERVER: ${ORIGIN_SERVER}
SLEEP_DURATION: ${SLEEP_DURATION}

View File

@ -1,40 +0,0 @@
package main
import (
"log"
"net/http"
"net/http/httputil"
"net/url"
"os"
"time"
)
func main() {
origin := os.Getenv("ORIGIN_SERVER")
if origin == "" {
// it is never not-set, the default is in the `.env` file
log.Fatalf("missing env-variable ORIGIN_SERVER")
}
sleepDurationStr := os.Getenv("SLEEP_DURATION")
if sleepDurationStr == "" {
// it is never not-set, the default is in the `.env` file
log.Fatalf("missing env-variable SLEEP_DURATION")
}
sleep, err := time.ParseDuration(sleepDurationStr)
if err != nil {
log.Fatalf("failed to parse SLEEP_DURATION: %v", err)
}
originURL, _ := url.Parse(origin)
proxy := httputil.NewSingleHostReverseProxy(originURL)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
log.Printf("sleeping for %s then proxying request: url '%s', headers: '%v'", sleep.String(), r.RequestURI, r.Header)
<-time.After(sleep)
proxy.ServeHTTP(w, r)
})
log.Fatal(http.ListenAndServe(":3011", nil))
}