diff --git a/hack/.linted_packages b/hack/.linted_packages index 7ab9eb282ff..ac486f7762a 100644 --- a/hack/.linted_packages +++ b/hack/.linted_packages @@ -482,6 +482,7 @@ test/images/port-forward-tester test/images/porter test/images/resource-consumer/consume-cpu test/images/serve-hostname +test/images/test-webserver test/integration/apiserver test/integration/client test/integration/configmap diff --git a/test/images/BUILD b/test/images/BUILD index 009d86244a1..6083d383bee 100644 --- a/test/images/BUILD +++ b/test/images/BUILD @@ -34,6 +34,7 @@ filegroup( "//test/images/porter:all-srcs", "//test/images/resource-consumer:all-srcs", "//test/images/serve-hostname:all-srcs", + "//test/images/test-webserver:all-srcs", ], tags = ["automanaged"], ) diff --git a/test/images/test-webserver/BUILD b/test/images/test-webserver/BUILD new file mode 100644 index 00000000000..a0f4bcac820 --- /dev/null +++ b/test/images/test-webserver/BUILD @@ -0,0 +1,34 @@ +package(default_visibility = ["//visibility:public"]) + +licenses(["notice"]) + +load( + "@io_bazel_rules_go//go:def.bzl", + "go_binary", + "go_library", +) + +go_binary( + name = "test-webserver", + library = ":go_default_library", + tags = ["automanaged"], +) + +go_library( + name = "go_default_library", + srcs = ["test-webserver.go"], + tags = ["automanaged"], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [":package-srcs"], + tags = ["automanaged"], +) diff --git a/test/images/test-webserver/Dockerfile b/test/images/test-webserver/Dockerfile new file mode 100644 index 00000000000..e14595f08e9 --- /dev/null +++ b/test/images/test-webserver/Dockerfile @@ -0,0 +1,19 @@ +# Copyright 2014 The Kubernetes Authors. +# +# 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. + +FROM scratch + +COPY test-webserver / +EXPOSE 80 +ENTRYPOINT ["/test-webserver"] diff --git a/test/images/test-webserver/Makefile b/test/images/test-webserver/Makefile new file mode 100644 index 00000000000..712f55b009f --- /dev/null +++ b/test/images/test-webserver/Makefile @@ -0,0 +1,25 @@ +# Copyright 2017 The Kubernetes Authors. +# +# 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. + +SRCS = test-webserver +ARCH ?= amd64 +TARGET ?= $(CURDIR) +GOLANG_VERSION ?= latest +SRC_DIR = $(notdir $(shell pwd)) +export + +bin: + ../image-util.sh bin $(SRCS) + +.PHONY: bin diff --git a/test/images/test-webserver/VERSION b/test/images/test-webserver/VERSION new file mode 100644 index 00000000000..d3827e75a5c --- /dev/null +++ b/test/images/test-webserver/VERSION @@ -0,0 +1 @@ +1.0 diff --git a/test/images/test-webserver/test-webserver.go b/test/images/test-webserver/test-webserver.go new file mode 100644 index 00000000000..ee496b0b5b0 --- /dev/null +++ b/test/images/test-webserver/test-webserver.go @@ -0,0 +1,51 @@ +/* +Copyright 2014 The Kubernetes Authors. + +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. +*/ + +// A tiny web server that serves a static file. +package main + +import ( + "flag" + "fmt" + "log" + "net/http" +) + +var ( + port = flag.Int("port", 80, "Port number.") +) + +func main() { + flag.Parse() + + fs := http.StripPrefix("/", http.FileServer(http.Dir("/"))) + + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Cache-Control", "private") + // Needed for local proxy to Kubernetes API server to work. + w.Header().Set("Access-Control-Allow-Origin", "*") + w.Header().Set("Access-Control-Allow-Credentials", "true") + w.Header().Set("Access-Control-Allow-Methods", "GET, POST, OPTIONS") + w.Header().Set("Access-Control-Allow-Headers", "DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,Cache-Control,Content-Type") + // Disable If-Modified-Since so update-demo isn't broken by 304s + r.Header.Del("If-Modified-Since") + fs.ServeHTTP(w, r) + }) + + go log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", *port), nil)) + + select {} +}