Skip to content

Commit

Permalink
test: added helloworld service for testing multiple bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
chetan committed Sep 10, 2022
1 parent be636f7 commit 2f18114
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
49 changes: 49 additions & 0 deletions testing/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,54 @@ services:
restart: unless-stopped
ports:
- 6380:6379

helloworld:
build:
dockerfile: ./helloworld/Dockerfile
context: ./
restart: unless-stopped
ports:
- 5555:5555
- 5566:5566
labels:
- "traefik.enable=true"
- "traefik.http.routers.hello1.rule=Host(`hello1.local`)"
- "traefik.http.routers.hello1.service=hello1"
- "traefik.http.routers.hello1.tls=true"
- "traefik.http.routers.hello1.tls.certresolver=default"
- "traefik.http.services.hello1.loadbalancer.server.scheme=http"
- "traefik.http.services.hello1.loadbalancer.server.port=5555"
- "traefik.http.routers.hello2.rule=Host(`hello2.local`)"
- "traefik.http.routers.hello2.service=hello2"
- "traefik.http.routers.hello2.tls=true"
- "traefik.http.routers.hello2.tls.certresolver=default"
- "traefik.http.services.hello2.loadbalancer.server.scheme=http"
- "traefik.http.services.hello2.loadbalancer.server.port=5566"

# This service is the same as above except that it does not have a label
# which explicitly maps the port and so it fails to correctly determine which
# port to tell traefik to connect to. i.e., both services connect to 5555.
hellodetect:
build:
dockerfile: ./helloworld/Dockerfile
context: ./
restart: unless-stopped
ports:
- 5577:5555
- 5588:5566
labels:
- "traefik.enable=true"
- "traefik.http.routers.hello-detect.rule=Host(`hello-detect.local`)"
- "traefik.http.routers.hello-detect.service=hello-detect"
- "traefik.http.routers.hello-detect.tls=true"
- "traefik.http.routers.hello-detect.tls.certresolver=default"
- "traefik.http.services.hello-detect.loadbalancer.server.scheme=http"
- "traefik.http.routers.hello-detect2.rule=Host(`hello-detect2.local`)"
- "traefik.http.routers.hello-detect2.service=hello-detect2"
- "traefik.http.routers.hello-detect2.tls=true"
- "traefik.http.routers.hello-detect2.tls.certresolver=default"
- "traefik.http.services.hello-detect2.loadbalancer.server.scheme=http"

nginx:
image: "nginx:alpine"
restart: unless-stopped
Expand All @@ -23,6 +71,7 @@ services:
- "traefik.http.routers.nginx.tls.certresolver=default"
- "traefik.http.services.nginx.loadbalancer.server.scheme=http"
- "traefik.http.services.nginx.loadbalancer.server.port=8088"

pihole:
image: "pihole/pihole:latest"
restart: unless-stopped
Expand Down
6 changes: 6 additions & 0 deletions testing/helloworld/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM golang

COPY * /go/
RUN go build -o helloworld ./

ENTRYPOINT ["./helloworld"]
23 changes: 23 additions & 0 deletions testing/helloworld/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package main

import (
"fmt"
"io"
"net/http"
)

func main() {
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "Hello from port 5555")
})
fmt.Println("listening on port 5555")
go http.ListenAndServe(":5555", mux)

mux2 := http.NewServeMux()
mux2.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "Hello from port 5566")
})
fmt.Println("listening on port 5566")
http.ListenAndServe(":5566", mux2)
}

0 comments on commit 2f18114

Please sign in to comment.