move contrib/for-tests to test/images
This commit is contained in:
2
test/images/porter/.gitignore
vendored
Normal file
2
test/images/porter/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
porter
|
||||
.tag
|
18
test/images/porter/Dockerfile
Normal file
18
test/images/porter/Dockerfile
Normal file
@@ -0,0 +1,18 @@
|
||||
# Copyright 2015 Google Inc. All rights reserved.
|
||||
#
|
||||
# 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
|
||||
MAINTAINER Daniel Smith <dbsmith@google.com>
|
||||
ADD porter porter
|
||||
ENTRYPOINT ["/porter"]
|
32
test/images/porter/Makefile
Normal file
32
test/images/porter/Makefile
Normal file
@@ -0,0 +1,32 @@
|
||||
# Use:
|
||||
#
|
||||
# `make porter` will build porter.
|
||||
# `make tag` will suggest a tag.
|
||||
# `make container` will build a container-- you must supply a tag.
|
||||
# `make push` will push the container-- you must supply a tag.
|
||||
|
||||
REPO ?= gcr.io/google_containers
|
||||
|
||||
porter: porter.go
|
||||
CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags '-w' ./porter.go
|
||||
|
||||
.tag: porter
|
||||
md5sum porter | cut -d " " -f 1 > .tag
|
||||
|
||||
tag: .tag
|
||||
@echo "Suggest using TAG=$(shell cat .tag)"
|
||||
@echo "$$ make container TAG=$(shell cat .tag)"
|
||||
@echo "or"
|
||||
@echo "$$ make push TAG=$(shell cat .tag)"
|
||||
|
||||
container:
|
||||
$(if $(TAG),,$(error TAG is not defined. Use 'make tag' to see a suggestion))
|
||||
docker build -t $(REPO)/porter:$(TAG) .
|
||||
|
||||
push:
|
||||
$(if $(TAG),,$(error TAG is not defined. Use 'make tag' to see a suggestion))
|
||||
gcloud docker push $(REPO)/porter:$(TAG)
|
||||
|
||||
clean:
|
||||
rm -f porter
|
||||
rm -f .tag
|
5
test/images/porter/README.md
Normal file
5
test/images/porter/README.md
Normal file
@@ -0,0 +1,5 @@
|
||||
This directory contains go source, Dockerfile and Makefile for making a test
|
||||
container which serves requested data on ports specified in ENV variables.
|
||||
|
||||
|
||||
[]()
|
35
test/images/porter/pod.json
Normal file
35
test/images/porter/pod.json
Normal file
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"kind": "Pod",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "porter"
|
||||
},
|
||||
"spec": {
|
||||
"containers": [
|
||||
{
|
||||
"name": "porter",
|
||||
"image": "gcr.io/google_containers/porter:59ad46ed2c56ba50fa7f1dc176c07c37",
|
||||
"env": [
|
||||
{
|
||||
"name": "SERVE_PORT_80",
|
||||
"value": "foo"
|
||||
},
|
||||
{
|
||||
"name": "SERVE_PORT_81",
|
||||
"value": "<html><head></head><body><a href=\"/rewriteme\">rewritten link</a></body></html>"
|
||||
}
|
||||
],
|
||||
"ports": [
|
||||
{
|
||||
"name": "p80",
|
||||
"containerPort": 80
|
||||
},
|
||||
{
|
||||
"name": "p81",
|
||||
"containerPort": 81
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
59
test/images/porter/porter.go
Normal file
59
test/images/porter/porter.go
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
Copyright 2015 The Kubernetes Authors All rights reserved.
|
||||
|
||||
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 binary for testing ports.
|
||||
//
|
||||
// Reads env vars; for every var of the form SERVE_PORT_X, where X is a valid
|
||||
// port number, porter starts an HTTP server which serves the env var's value
|
||||
// in response to any query.
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const prefix = "SERVE_PORT_"
|
||||
|
||||
func main() {
|
||||
for _, vk := range os.Environ() {
|
||||
// Put everything before the first = sign in parts[0], and
|
||||
// everything else in parts[1] (even if there are multiple =
|
||||
// characters).
|
||||
parts := strings.SplitN(vk, "=", 2)
|
||||
key := parts[0]
|
||||
value := parts[1]
|
||||
if strings.HasPrefix(key, prefix) {
|
||||
port := strings.TrimPrefix(key, prefix)
|
||||
go servePort(port, value)
|
||||
}
|
||||
}
|
||||
|
||||
select {}
|
||||
}
|
||||
|
||||
func servePort(port, value string) {
|
||||
s := &http.Server{
|
||||
Addr: "0.0.0.0:" + port,
|
||||
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprint(w, value)
|
||||
}),
|
||||
}
|
||||
log.Printf("server on port %q failed: %v", port, s.ListenAndServe())
|
||||
}
|
Reference in New Issue
Block a user