diff --git a/devenv/docker/blocks/slow_proxy_mac/.env b/devenv/docker/blocks/slow_proxy_mac/.env new file mode 100644 index 00000000000..74f4e9c1841 --- /dev/null +++ b/devenv/docker/blocks/slow_proxy_mac/.env @@ -0,0 +1,2 @@ +ORIGIN_SERVER=http://host.docker.internal:9090/ +SLEEP_DURATION=60s \ No newline at end of file diff --git a/devenv/docker/blocks/slow_proxy_mac/Dockerfile b/devenv/docker/blocks/slow_proxy_mac/Dockerfile index d48c945f5ab..735d433414c 100644 --- a/devenv/docker/blocks/slow_proxy_mac/Dockerfile +++ b/devenv/docker/blocks/slow_proxy_mac/Dockerfile @@ -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"] diff --git a/devenv/docker/blocks/slow_proxy_mac/docker-compose.yaml b/devenv/docker/blocks/slow_proxy_mac/docker-compose.yaml index 47347042df7..135c230c9bc 100644 --- a/devenv/docker/blocks/slow_proxy_mac/docker-compose.yaml +++ b/devenv/docker/blocks/slow_proxy_mac/docker-compose.yaml @@ -3,4 +3,5 @@ ports: - '3011:3011' environment: - ORIGIN_SERVER: 'http://host.docker.internal:9090/' + ORIGIN_SERVER: ${ORIGIN_SERVER} + SLEEP_DURATION: ${SLEEP_DURATION} \ No newline at end of file diff --git a/devenv/docker/blocks/slow_proxy_mac/main.go b/devenv/docker/blocks/slow_proxy_mac/main.go index dece2525c13..4c98eb9d17c 100644 --- a/devenv/docker/blocks/slow_proxy_mac/main.go +++ b/devenv/docker/blocks/slow_proxy_mac/main.go @@ -1,7 +1,6 @@ package main import ( - "fmt" "log" "net/http" "net/http/httputil" @@ -13,16 +12,26 @@ import ( func main() { origin := os.Getenv("ORIGIN_SERVER") if origin == "" { - origin = "http://host.docker.internal:9090/" + // it is never not-set, the default is in the `.env` file + log.Fatalf("missing env-variable ORIGIN_SERVER") } - sleep := time.Minute + 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) { - fmt.Printf("sleeping for %s then proxying request: %s", sleep.String(), r.RequestURI) + 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) })