Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make build image verbose #99

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions docker-compose.e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ services:
target: coreruleset
volumes:
- ./docker/e2e/e2e-rules.conf:/etc/coraza-spoa/rules/000-e2e-rules.conf
- cor:/var/log/coraza-spoa
ports:
- 9000:9000
command:
[
"sh",
"-c",
"/usr/bin/coraza-spoa --config /etc/coraza-spoa/config.yaml 2>&1 | tee /var/log/coraza-spoa/coraza.log"
]
haproxy:
depends_on:
- coraza
Expand All @@ -19,12 +28,9 @@ services:
[
"sh",
"-c",
"haproxy -f /usr/local/etc/haproxy/haproxy.cfg | tee /var/lib/haproxy/hap.log"
"haproxy -d -f /usr/local/etc/haproxy/haproxy.cfg 2>&1 | tee /var/lib/haproxy/hap.log"
]
ports: [ "4000:80" ]
links:
- "coraza:coraza"
- "httpbin:httpbin"
ports: [ "4000:4000" ]
volumes:
- type: bind
source: ./docker/haproxy
Expand All @@ -34,13 +40,12 @@ services:
depends_on:
- haproxy
- coraza
links:
- "haproxy:haproxy"
- "httpbin:httpbin"
build:
context: docker/e2e
dockerfile: ./Dockerfile.curl
volumes:
- hap:/haproxy
- cor:/coraza
volumes:
hap:
cor:
2 changes: 1 addition & 1 deletion docker/e2e/Dockerfile.curl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ RUN apk add --no-cache bash

COPY ./e2e.sh /workspace/e2e.sh

ENV HAPROXY_HOST=haproxy:80
ENV HAPROXY_HOST=haproxy:4000
ENV HTTPBIN_HOST=httpbin:8080

CMD ["bash", "/workspace/e2e.sh"]
19 changes: 16 additions & 3 deletions docker/e2e/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
HAPROXY_HOST=${HAPROXY_HOST:-"localhost:4000"}
HTTPBIN_HOST=${HTTPBIN_HOST:-"localhost:8080"}
HAPROXY_LOGS='/haproxy/hap.log'
CORAZA_LOGS='/coraza/coraza.log'
CURL_MAX_TIME=${CURL_MAX_TIME:-"2"}

[[ "${DEBUG}" == "true" ]] && set -x

Expand All @@ -25,6 +27,17 @@ truePositiveBodyPayload="maliciouspayload"
trueNegativeBodyPayloadForResponseBody="Hello world"
truePositiveBodyPayloadForResponseBody="responsebodycode"


# print_logs prints haproxy and coraza logs
function print_logs() {
echo ' ---------------------- haproxy ---------------------'
cat "${HAPROXY_LOGS}"
echo ' ---------------------- coraza ---------------------'
cat "${CORAZA_LOGS}"
}
trap print_logs EXIT


# wait_for_service waits until the given URL returns a 200 status code.
# $1: The URL to send requests to.
# $2: The max number of requests to send before giving up.
Expand All @@ -33,7 +46,7 @@ function wait_for_service() {
local url=${1}
local max=${2}
while [[ "${status_code}" -ne "200" ]]; do
status_code=$(curl --write-out "%{http_code}" --silent --output /dev/null "${url}")
status_code=$(curl --max-time "${CURL_MAX_TIME}" --write-out "%{http_code}" --silent --output /dev/null "${url}")
sleep 1
echo -ne "[Wait] Waiting for response from ${url}. Timeout: ${max}s \r"
((max-=1))
Expand All @@ -53,7 +66,7 @@ function wait_for_service() {
function check_status() {
local url=${1}
local status=${2}
local args=("${@:3}" --write-out '%{http_code}' --silent --output /dev/null)
local args=("${@:3}" --max-time "${CURL_MAX_TIME}" --write-out '%{http_code}' --silent --output /dev/null)
status_code=$(curl "${args[@]}" "${url}")
if [[ "${status_code}" -ne ${status} ]] ; then
echo "[Fail] Unexpected response with code ${status_code} from ${url}"
Expand All @@ -70,7 +83,7 @@ function check_status() {
function check_body() {
local url=${1}
local empty=${2}
local args=("${@:3}" --silent)
local args=("${@:3}" --silent --max-time "${CURL_MAX_TIME}")
response_body=$(curl "${args[@]}" "${url}")
if [[ "${empty}" == "true" ]] && [[ -n "${response_body}" ]]; then
echo -e "[Fail] Unexpected response with a body. Body dump:\n${response_body}"
Expand Down
1 change: 1 addition & 0 deletions docker/haproxy/haproxy.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ frontend stats
frontend test_frontend
mode http
bind *:80
bind *:4000
bind *:443 ssl crt /usr/local/etc/haproxy/example.com.pem alpn h2,http/1.1
unique-id-format %[uuid()]
unique-id-header X-Unique-ID
Expand Down
Loading