Skip to content

Commit 71c40c4

Browse files
author
Robert Schönthal
committed
feat(docs): add docs
1 parent f7a2f58 commit 71c40c4

File tree

5 files changed

+137
-24
lines changed

5 files changed

+137
-24
lines changed

.github/workflows/release.yaml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,26 @@ jobs:
1313
packages: write
1414
env:
1515
REGISTRY: ghcr.io
16-
IMAGE_NAME: ${{ github.repository }}
16+
1717
steps:
1818
- name: Checkout
1919
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
2020

21+
- name: lowercase github.repository
22+
run: |
23+
echo "IMAGE_NAME=`echo ${{github.repository}} | tr '[:upper:]' '[:lower:]'`" >> ${GITHUB_ENV}
24+
2125
- name: Login to GitHub Container Registry
2226
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3
2327
with:
2428
registry: ${{ env.REGISTRY }}
2529
username: ${{ github.actor }}
2630
password: ${{ github.token }}
2731

28-
- uses: docker/build-push-action@v2
32+
- uses: docker/build-push-action@v6
2933
with:
30-
tags: "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}"
34+
tags: |
35+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
36+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
3137
push: true
38+
platforms: linux/amd64

.github/workflows/test.yaml

Lines changed: 103 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,58 @@ on:
66
- main
77

88
jobs:
9-
build:
9+
test:
1010
runs-on: ubuntu-latest
1111
permissions:
1212
contents: read
1313
packages: write
14+
actions: read
15+
security-events: write
1416
env:
1517
REGISTRY: ghcr.io
16-
IMAGE_NAME: ${{ github.repository }}
1718
steps:
1819
- name: Checkout
1920
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
2021

21-
- uses: docker/build-push-action@v2
22+
- name: lowercase github.repository
23+
run: |
24+
echo "IMAGE_NAME=`echo ${{ env.REGISTRY }}/${{ github.repository }}:${{ github.sha }} | tr '[:upper:]' '[:lower:]'`" >> ${GITHUB_ENV}
25+
26+
- uses: docker/build-push-action@v6
2227
with:
23-
tags: "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}"
24-
push: true
28+
tags: "${{ env.IMAGE_NAME }}"
29+
platforms: linux/amd64
30+
31+
-
32+
name: Scan for vulnerabilities
33+
uses: crazy-max/ghaction-container-scan@v3
34+
id: scan
35+
env:
36+
TRIVY_DISABLE_VEX_NOTICE: true
37+
with:
38+
image: ${{ env.IMAGE_NAME }}
39+
annotations: true
40+
severity_threshold: HIGH
41+
dockerfile: ./Dockerfile
42+
-
43+
name: Upload SARIF file
44+
if: ${{ steps.scan.outputs.sarif != '' }}
45+
uses: github/codeql-action/upload-sarif@v2
46+
with:
47+
sarif_file: ${{ steps.scan.outputs.sarif }}
2548

2649
# cookie strategy
2750
- name: Run Docker Image with Cookie Strategy
28-
run: docker run --name statista_proxy -d -p80:80 -e STRATEGY=COOKIE -e OLD_DOMAIN=haproxy.com:443 -e NEW_DOMAIN=apache.org:443 -e COOKIE_STRATEGY_NAME="my_app_routing=new" statista_proxy
51+
run: |
52+
docker run --name statista_proxy -d -p80:80 \
53+
-e STRATEGY=COOKIE \
54+
-e OLD_DOMAIN=haproxy.com:443 -e NEW_DOMAIN=apache.org:443 \
55+
-e COOKIE_STRATEGY_NAME="my_app_routing=new" \
56+
"${{ env.IMAGE_NAME }}"
57+
58+
sleep 2
59+
docker ps -a
60+
docker logs statista_proxy
2961
3062
- name: Test Docker Image with Cookie Strategy without cookie
3163
run: |
@@ -41,7 +73,17 @@ jobs:
4173

4274
# percentage strategy
4375
- name: Run Docker Image with Percentage Strategy
44-
run: docker run --name statista_proxy -d -p80:80 -e STRATEGY=PERCENTAGE -e OLD_DOMAIN=haproxy.com:443 -e NEW_DOMAIN=apache.org:443 -e PERCENTAGE_NEW=50 -e PERCENTAGE_OLD=50 -e COOKIE_PERCENTAGE_NAME=my_app statista_proxy
76+
run: |
77+
docker run --name statista_proxy -d -p80:80 \
78+
-e STRATEGY=PERCENTAGE \
79+
-e OLD_DOMAIN=haproxy.com:443 -e NEW_DOMAIN=apache.org:443 \
80+
-e PERCENTAGE_NEW=50 -e PERCENTAGE_OLD=50 \
81+
-e COOKIE_PERCENTAGE_NAME=my_app \
82+
"${{ env.IMAGE_NAME }}"
83+
84+
sleep 2
85+
docker ps -a
86+
docker logs statista_proxy
4587
4688
- name: Test Docker Image with Percentage Strategy backend selection
4789
run: |
@@ -53,14 +95,65 @@ jobs:
5395
5496
- name: Test Docker Image with Percentage Strategy with sticky cookie on new domain
5597
run: |
56-
curl -Is localhost:80 --cookie "my_app=new_domain" | grep -i -e "server: nginx"
98+
curl -Is localhost:80 --cookie "my_app=new_domain" | grep -i -e "x-served-by: cache-"
5799
58100
- name: Test Docker Image with Percentage Strategy with round robin
59101
# sadly we dont know which server serves us first, so we have to check both
60102
run: |
61-
curl -Is localhost:80 | grep -i -e "server: " -e "set-cookie: my_app=new_domain; path=/" -e "set-cookie: my_app=old_domain; path=/"
62-
curl -Is localhost:80 | grep -i -e "server: " -e "set-cookie: my_app=new_domain; path=/" -e "set-cookie: my_app=old_domain; path=/"
103+
curl -Is localhost:80 | grep -i -e "server:" -e "x-served-by:" -e "set-cookie: my_app=new_domain; path=/" -e "set-cookie: my_app=old_domain; path=/"
104+
curl -Is localhost:80 | grep -i -e "server:" -e "x-served-by:" -e "set-cookie: my_app=new_domain; path=/" -e "set-cookie: my_app=old_domain; path=/"
63105
64106
- name: Stop the Percentage Strategy Docker Image
65107
if: success() || failure()
66108
run: docker rm -f statista_proxy
109+
110+
# variable validation
111+
- name: Run Docker Image with Invalid new Percentage
112+
run: |
113+
set +e
114+
115+
docker run \
116+
-e STRATEGY=PERCENTAGE \
117+
-e OLD_DOMAIN=haproxy.com:443 -e NEW_DOMAIN=apache.org:443 \
118+
-e PERCENTAGE_NEW=foo -e PERCENTAGE_OLD=50 \
119+
-e COOKIE_PERCENTAGE_NAME=my_app \
120+
"${{ env.IMAGE_NAME }}"
121+
122+
if [[ $? == 1 ]]; then exit 0; else exit 1; fi
123+
124+
- name: Run Docker Image with Invalid old Percentage
125+
run: |
126+
set +e
127+
128+
docker run \
129+
-e STRATEGY=PERCENTAGE \
130+
-e OLD_DOMAIN=haproxy.com:443 -e NEW_DOMAIN=apache.org:443 \
131+
-e PERCENTAGE_NEW=50 -e PERCENTAGE_OLD=foo \
132+
-e COOKIE_PERCENTAGE_NAME=my_app \
133+
"${{ env.IMAGE_NAME }}"
134+
135+
if [[ $? == 1 ]]; then exit 0; else exit 1; fi
136+
137+
- name: Run Docker Image with Invalid old domain
138+
run: |
139+
set +e
140+
141+
docker run \
142+
-e STRATEGY=PERCENTAGE \
143+
-e NEW_DOMAIN=apache.org:443 \
144+
-e COOKIE_PERCENTAGE_NAME=my_app \
145+
"${{ env.IMAGE_NAME }}"
146+
147+
if [[ $? == 1 ]]; then exit 0; else exit 1; fi
148+
149+
- name: Run Docker Image with Invalid new domain
150+
run: |
151+
set +e
152+
153+
docker run \
154+
-e STRATEGY=PERCENTAGE \
155+
-e OLD_DOMAIN=haproxy.com:443 -e NEW_DOMAIN=apache.org:lol \
156+
-e COOKIE_PERCENTAGE_NAME=my_app \
157+
"${{ env.IMAGE_NAME }}"
158+
159+
if [[ $? == 1 ]]; then exit 0; else exit 1; fi

Dockerfile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
FROM haproxy:lts-alpine
22

3+
LABEL org.opencontainers.image.source=https://github.com/statista-oss/proxy-router
4+
LABEL org.opencontainers.image.description="haproxy configurable through env vars for different routing strategies"
5+
36
USER root
47
RUN apk add --no-cache curl socat
58

69
USER haproxy
710

8-
# defaults
9-
ENV PERCENTAGE_NEW=0
10-
ENV PERCENTAGE_OLD=100
11-
1211
COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg
1312

README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# Statista Proxy
1+
# Routing Proxy
2+
3+
uses HAPROXY under the hood.
24

35
> route between your legacy and your new application using different strategies
46
@@ -8,8 +10,9 @@ set the following environment variables for this container:
810

911
```bash
1012
STRATEGY=PERCENTAGE | COOKIE
11-
OLD_DOMAIN=old.statista.com
12-
COOKIE_STRATEGY_NAME=my_app_routing=new
13+
OLD_DOMAIN=old.domain.com:443
14+
NEW_DOMAIN=new.domain.com:443
15+
COOKIE_STRATEGY_NAME="my_app_routing=new"
1316
COOKIE_PERCENTAGE_NAME=my_app_sticky_name
1417
PERCENTAGE_OLD=70
1518
PERCENTAGE_NEW=30
@@ -32,8 +35,6 @@ this cookie will taken into account when a forced routing to the new application
3235
### COOKIE_PERCENTAGE_NAME
3336
this is the name of the cookie for implementing the sticky session
3437

35-
> this cookie needs to be present in our [cookie consent](https://forms.office.com/pages/responsepage.aspx?id=OfiFB67f4U-gaID-j8YfK0gVGkEOyf1NiUPPYqdVPa5UNFFUUVNPSEZNMDVSOExKNDE0NksxQURSMi4u&route=shorturl)
36-
3738
### PERCENTAGE_OLD
3839
how much traffic should be routed to the old application
3940

@@ -83,3 +84,8 @@ curl -I localhost:80
8384
curl -I --cookie "my_app_routing=new" localhost:80
8485
```
8586
> should be the new application
87+
88+
89+
## Usage
90+
91+
tbd

haproxy.cfg

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
global
22
# enable runtime api via socket, run this inside the container
3-
# echo "get var proc.cookie_percentage_name" | socat stdio unix-connect:/tmp/haproxy.sock
3+
# echo "get var proc.strategy" | socat stdio unix-connect:/tmp/haproxy.sock
44
# see https://www.haproxy.com/documentation/haproxy-runtime-api/
55
stats socket /tmp/haproxy.sock user haproxy group haproxy mode 660 level admin
66

77
# strategy can be either "PERCENTAGE" or "COOKIE"
8-
set-var proc.strategy str("${STRATEGY}")
8+
set-var proc.strategy env(STRATEGY)
9+
10+
# default some environment variables
11+
presetenv PERCENTAGE_NEW "0"
12+
presetenv PERCENTAGE_OLD "100"
13+
14+
# we source them from the environment here to actually typecheck them
15+
set-var proc.percentage_new int("${PERCENTAGE_NEW}")
16+
set-var proc.percentage_old int("${PERCENTAGE_OLD}")
917

1018
#log stdout format raw local0
1119

0 commit comments

Comments
 (0)