├── Dockerfile └── httpenv.go /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:alpine 2 | COPY httpenv.go /go 3 | RUN go build httpenv.go 4 | FROM alpine 5 | COPY --from=0 /go/httpenv /httpenv 6 | CMD ["/httpenv"] 7 | EXPOSE 8888 8 | -------------------------------------------------------------------------------- /httpenv.go: -------------------------------------------------------------------------------- 1 | package main 2 | import ( 3 | "encoding/json" 4 | "fmt" 5 | "net/http" 6 | "os" 7 | "strings" 8 | ) 9 | func serve(w http.ResponseWriter, r *http.Request) { 10 | env := map[string]string{} 11 | for _, keyval := range os.Environ() { 12 | keyval := strings.SplitN(keyval, "=", 2) 13 | env[keyval[0]] = keyval[1] 14 | } 15 | bytes, err := json.Marshal(env) 16 | if err != nil { 17 | w.Write([]byte("{}")) 18 | return 19 | } 20 | w.Write([]byte(bytes)) 21 | } 22 | func main() { 23 | fmt.Printf("Starting httpenv listening on port 8888.\n") 24 | http.HandleFunc("/", serve) 25 | if err := http.ListenAndServe(":8888", nil); err != nil { 26 | panic(err) 27 | } 28 | } 29 | 30 | --------------------------------------------------------------------------------