Update serve_hostname

1) FROM busybox
2) Log source IP
3) bump to v1.2
This commit is contained in:
Tim Hockin 2015-08-04 13:37:12 -07:00
parent d04fce045e
commit 384bcbb21b
3 changed files with 18 additions and 7 deletions

View File

@ -1,4 +1,4 @@
FROM scratch
FROM busybox
MAINTAINER Tim Hockin <thockin@google.com>
ADD serve_hostname /serve_hostname
ADD serve_hostname.go /serve_hostname.go

View File

@ -1,17 +1,23 @@
all: serve_hostname
TAG = 1.1
TAG = v1.2
PREFIX = gcr.io/google_containers
TEST_PREFIX = gcr.io/_b_k8s_authenticated_test
serve_hostname: serve_hostname.go
CGO_ENABLED=0 go build -a -installsuffix cgo --ldflags '-w' ./serve_hostname.go
container: serve_hostname
sudo docker build -t gcr.io/google_containers/serve_hostname:$(TAG) .
sudo docker tag gcr.io/google_containers/serve_hostname:$(TAG) gcr.io/_b_k8s_authenticated_test/serve_hostname:$(TAG)
docker build -t $(PREFIX)/serve_hostname:$(TAG) .
if [ -n "$(TEST_PREFIX)" ]; then \
docker tag -f $(PREFIX)/serve_hostname:$(TAG) $(TEST_PREFIX)/serve_hostname:$(TAG); \
fi
push:
gcloud docker push gcr.io/google_containers/serve_hostname:$(TAG)
gcloud docker push gcr.io/_b_k8s_authenticated_test/serve_hostname:$(TAG)
gcloud docker push $(PREFIX)/serve_hostname:$(TAG)
if [ -n "$(TEST_PREFIX)" ]; then \
gcloud docker push $(TEST_PREFIX)/serve_hostname:$(TAG); \
fi
clean:
rm -f serve_hostname

View File

@ -56,6 +56,7 @@ func main() {
if err != nil {
log.Fatalf("Error from Accept(): %s", err)
}
log.Printf("TCP request from %s", conn.RemoteAddr().String())
conn.Write([]byte(hostname))
conn.Close()
}
@ -77,12 +78,16 @@ func main() {
if err != nil {
log.Fatalf("Error from ReadFrom(): %s", err)
}
log.Printf("UDP request from %s", cliAddr.String())
sock.WriteTo([]byte(hostname), cliAddr)
}
}()
}
if *doHttp {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "%s", hostname) })
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
log.Printf("HTTP request from %s", r.RemoteAddr)
fmt.Fprintf(w, "%s", hostname)
})
go log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", *port), nil))
}