initial commit
This commit is contained in:
commit
0e6be50e37
23 changed files with 1069 additions and 0 deletions
15
testapp/api/Dockerfile
Normal file
15
testapp/api/Dockerfile
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
FROM golang:alpine
|
||||
ARG VERSION
|
||||
RUN mkdir /build
|
||||
ADD . /build/
|
||||
WORKDIR /build
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -a -gcflags '-e' -ldflags "-X main.version=$VERSION -s -w" -o main .
|
||||
RUN echo -e "root:x:0:0:root:/:\nappuser:x:1000:1000:appuser:/:" > /etc/passwd
|
||||
RUN echo -e "root:x:0:root\nappuser:x:1000:" > /etc/group
|
||||
FROM scratch
|
||||
COPY --from=0 /build/main /
|
||||
COPY --from=0 /etc/passwd /etc/
|
||||
COPY --from=0 /etc/group /etc/
|
||||
USER appuser
|
||||
EXPOSE 8080
|
||||
ENTRYPOINT ["/main"]
|
||||
13
testapp/api/Makefile
Normal file
13
testapp/api/Makefile
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
CC=docker
|
||||
APP=api
|
||||
TAG=127.0.0.1:5000/testapp/$(APP):$(VERSION)
|
||||
|
||||
all: build push
|
||||
|
||||
build:
|
||||
$(CC) build --build-arg VERSION=$(VERSION) -t $(TAG) .
|
||||
|
||||
push:
|
||||
$(CC) push $(TAG)
|
||||
|
||||
.PHONY: build push
|
||||
109
testapp/api/api-v1-istio.yaml
Normal file
109
testapp/api/api-v1-istio.yaml
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: testapp-api
|
||||
labels:
|
||||
app: testapp-api
|
||||
version: v1
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: testapp-api
|
||||
version: v1
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: testapp-api
|
||||
version: v1
|
||||
spec:
|
||||
containers:
|
||||
- name: testapp-api
|
||||
image: 127.0.0.1:5000/testapp/api:v1
|
||||
imagePullPolicy: Always
|
||||
ports:
|
||||
- containerPort: 8080
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: testapp-api
|
||||
labels:
|
||||
app: testapp-api
|
||||
spec:
|
||||
ports:
|
||||
- port: 8080
|
||||
name: http
|
||||
selector:
|
||||
app: testapp-api
|
||||
---
|
||||
apiVersion: networking.istio.io/v1alpha3
|
||||
kind: ServiceEntry
|
||||
metadata:
|
||||
name: httpbin
|
||||
spec:
|
||||
hosts:
|
||||
- httpbin.org
|
||||
ports:
|
||||
- number: 80
|
||||
name: http-port
|
||||
protocol: HTTP
|
||||
resolution: DNS
|
||||
location: MESH_EXTERNAL
|
||||
---
|
||||
apiVersion: networking.istio.io/v1alpha3
|
||||
kind: Gateway
|
||||
metadata:
|
||||
name: httpbin
|
||||
spec:
|
||||
selector:
|
||||
istio: egressgateway
|
||||
servers:
|
||||
- port:
|
||||
number: 80
|
||||
name: http
|
||||
protocol: HTTP
|
||||
hosts:
|
||||
- httpbin.org
|
||||
---
|
||||
apiVersion: networking.istio.io/v1alpha3
|
||||
kind: DestinationRule
|
||||
metadata:
|
||||
name: httpbin
|
||||
spec:
|
||||
host: istio-egressgateway.istio-system.svc.cluster.local
|
||||
subsets:
|
||||
- name: httpbin
|
||||
---
|
||||
apiVersion: networking.istio.io/v1alpha3
|
||||
kind: VirtualService
|
||||
metadata:
|
||||
name: httpbin-egress
|
||||
spec:
|
||||
hosts:
|
||||
- httpbin.org
|
||||
gateways:
|
||||
- httpbin
|
||||
- mesh
|
||||
http:
|
||||
- match:
|
||||
- gateways:
|
||||
- mesh
|
||||
port: 80
|
||||
route:
|
||||
- destination:
|
||||
host: istio-egressgateway.istio-system.svc.cluster.local
|
||||
subset: httpbin
|
||||
port:
|
||||
number: 80
|
||||
weight: 100
|
||||
- match:
|
||||
- gateways:
|
||||
- httpbin
|
||||
port: 80
|
||||
route:
|
||||
- destination:
|
||||
host: httpbin.org
|
||||
port:
|
||||
number: 80
|
||||
weight: 100
|
||||
38
testapp/api/api-v1.yaml
Normal file
38
testapp/api/api-v1.yaml
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: testapp-api
|
||||
labels:
|
||||
app: testapp-api
|
||||
version: v1
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: testapp-api
|
||||
version: v1
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: testapp-api
|
||||
version: v1
|
||||
spec:
|
||||
containers:
|
||||
- name: testapp-api
|
||||
image: 127.0.0.1:5000/testapp/api:v1
|
||||
imagePullPolicy: Always
|
||||
ports:
|
||||
- containerPort: 8080
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: testapp-api
|
||||
labels:
|
||||
app: testapp-api
|
||||
spec:
|
||||
ports:
|
||||
- port: 8080
|
||||
name: http
|
||||
selector:
|
||||
app: testapp-api
|
||||
63
testapp/api/main.go
Normal file
63
testapp/api/main.go
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
var version string
|
||||
|
||||
func get(c *http.Client, url string) (body string, err error) {
|
||||
resp, err := c.Get(url)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
b, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
body = string(b)
|
||||
return
|
||||
}
|
||||
|
||||
func main() {
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
log.Printf("%s %s %s", r.RemoteAddr, r.Method, r.URL)
|
||||
h, err := os.Hostname()
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
c := &http.Client{Transport: &http.Transport{
|
||||
DialContext: (&net.Dialer{
|
||||
Timeout: 5 * time.Second,
|
||||
}).DialContext,
|
||||
}}
|
||||
health, err := get(c, "http://testapp-db:8080/healthz")
|
||||
if err != nil {
|
||||
health = err.Error()
|
||||
}
|
||||
ext, err := get(c, "http://httpbin.org/robots.txt")
|
||||
if err != nil {
|
||||
ext = err.Error()
|
||||
}
|
||||
fmt.Fprintf(w, "%s (%s) DB Health: '%s' external GET: '%s'", h, version, health, ext)
|
||||
})
|
||||
http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
|
||||
log.Printf("%s %s %s", r.RemoteAddr, r.Method, r.URL)
|
||||
fmt.Fprintf(w, "api: ok")
|
||||
})
|
||||
s := &http.Server{
|
||||
ReadTimeout: 5 * time.Second,
|
||||
WriteTimeout: 10 * time.Second,
|
||||
IdleTimeout: 120 * time.Second,
|
||||
Addr: ":8080",
|
||||
}
|
||||
log.Fatal(s.ListenAndServe())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue