Skip to content

Commit 1b138f3

Browse files
prometherionoktalz
authored andcommitted
BUG/MINOR: ci: embedding proxy-protocol image
Signed-off-by: Dario Tranchitella <[email protected]>
1 parent cd54596 commit 1b138f3

File tree

8 files changed

+89
-2
lines changed

8 files changed

+89
-2
lines changed

.gitlab-ci.yml

+2
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ docker-build:
175175
#- docker image tag $CI_REGISTRY_GO/golang:$GO_VERSION-alpine golang:$GO_VERSION-alpine
176176
- docker pull -q $CI_REGISTRY_GO/haproxytech/http-echo:latest
177177
- docker image tag $CI_REGISTRY_GO/haproxytech/http-echo:latest haproxytech/http-echo:latest
178+
- docker pull -q $CI_REGISTRY_GO/haproxytech/proxy-protocol:latest
179+
- docker image tag $CI_REGISTRY_GO/haproxytech/proxy-protocol:latest haproxytech/proxy-protocol:latest
178180
- wget -nv -O /usr/local/bin/kind https://github.com/kubernetes-sigs/kind/releases/download/${KIND}/kind-linux-amd64
179181
- chmod +x /usr/local/bin/kind
180182
- wget -nv -O /usr/local/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/${KUBECTL}/bin/linux/amd64/kubectl

deploy/tests/create.sh

+5-1
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,15 @@ fi
4040
printf %80s |tr " " "="; echo ""
4141
if [ -n "${GITLAB_CI}" ]; then
4242
echo "haproxytech/http-echo:latest pulled from CI registry"
43+
echo "haproxytech/proxy-protocol:latest pulled from CI registry"
4344
else
4445
docker build --build-arg TARGETPLATFORM="linux/amd64" -t haproxytech/http-echo -f deploy/tests/images/http-echo/Dockerfile deploy/tests/images/http-echo
46+
docker build --build-arg TARGETPLATFORM="linux/amd64" -t haproxytech/proxy-protocol -f deploy/tests/images/proxy-protocol/Dockerfile deploy/tests/images/proxy-protocol
4547
fi
4648
echo "loading image http-echo in kind"
47-
kind load docker-image haproxytech/http-echo:latest --name=$clustername
49+
kind load docker-image haproxytech/http-echo:latest --name=$clustername
50+
echo "loading image proxy-protocol in kind"
51+
kind load docker-image haproxytech/proxy-protocol:latest --name=$clustername
4852

4953
printf %80s |tr " " "="; echo ""
5054
echo "Create HAProxy namespace ..."

deploy/tests/e2e/send-proxy-protocol/config/deploy.yaml.tmpl

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ spec:
1414
spec:
1515
containers:
1616
- name: http-echo
17-
image: 'quay.io/prometherion/proxy-protocol-app:latest'
17+
image: 'haproxytech/proxy-protocol:latest'
18+
imagePullPolicy: IfNotPresent
1819
ports:
1920
- name: http
2021
containerPort: 8080
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM golang:1.22-alpine AS builder
2+
3+
COPY *.go /src/
4+
COPY go.mod /src/go.mod
5+
COPY go.sum /src/go.sum
6+
7+
RUN cd /src && go build -o proxy-protocol
8+
9+
FROM alpine:3
10+
WORKDIR /app
11+
COPY --from=builder /src/proxy-protocol .
12+
13+
ENTRYPOINT ["./proxy-protocol"]
14+
CMD []
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# proxy-protocol
2+
3+
A simple Go web server backed by PROXY Protocol.
4+
5+
## How to use
6+
7+
```bash
8+
docker build -t haproxytech/proxy-protocol -f deploy/tests/images/proxy-protocol/Dockerfile deploy/tests/images/proxy-protocol
9+
docker run -p 8080:8080 --rm -t haproxytech/proxy-protocol
10+
```
11+
12+
## Output example
13+
14+
```
15+
$: curl --haproxy-protocol --http1.1 http://localhost:8080/
16+
hello!
17+
````
18+
19+
## Credits
20+
21+
[github.com/pires/go-proxyproto](https://github.com/pires/go-proxyproto)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module proxy-protocol
2+
3+
go 1.22.0
4+
5+
require github.com/pires/go-proxyproto v0.8.0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
github.com/pires/go-proxyproto v0.8.0 h1:5unRmEAPbHXHuLjDg01CxJWf91cw3lKHc/0xzKpXEe0=
2+
github.com/pires/go-proxyproto v0.8.0/go.mod h1:iknsfgnH8EkjrMeMyvfKByp9TiBZCKZM0jx2xmKqnVY=
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"net"
6+
"net/http"
7+
"os"
8+
9+
"github.com/pires/go-proxyproto"
10+
)
11+
12+
func main() {
13+
// Create a TCP listener on port 8080
14+
addr := ":8080"
15+
tcpListener, err := net.Listen("tcp", addr)
16+
if err != nil {
17+
fmt.Fprintf(os.Stderr, "Error creating TCP listener: %v\n", err)
18+
os.Exit(1)
19+
}
20+
21+
// Wrap it with the PROXY protocol listener
22+
proxyListener := &proxyproto.Listener{Listener: tcpListener}
23+
24+
// Ensure the listener is closed on shutdown
25+
defer proxyListener.Close()
26+
27+
// HTTP handler
28+
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
29+
fmt.Fprint(w, "hello!")
30+
})
31+
32+
// Serve using custom listener
33+
fmt.Printf("Listening on %s with PROXY protocol support...\n", addr)
34+
if err := http.Serve(proxyListener, nil); err != nil {
35+
fmt.Fprintf(os.Stderr, "HTTP server error: %v\n", err)
36+
os.Exit(1)
37+
}
38+
}

0 commit comments

Comments
 (0)