feat: all routes working for caddy and add tests
This commit is contained in:
parent
3949c432f5
commit
11ca8f626e
5
core/caddy/Dockerfile
Normal file
5
core/caddy/Dockerfile
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
FROM alpine:3.21
|
||||
|
||||
COPY config/ /caddyfiles/
|
||||
|
||||
CMD ["sh", "-c", "cp -r /caddyfiles/. /etc/caddy/ && echo 'Caddyfiles copied.'"]
|
||||
|
|
@ -1,10 +1,21 @@
|
|||
services:
|
||||
caddy-init:
|
||||
container_name: caddy-init
|
||||
build:
|
||||
context: .
|
||||
volumes:
|
||||
- caddy-caddyfiles:/etc/caddy
|
||||
restart: "no"
|
||||
|
||||
caddy:
|
||||
container_name: caddy
|
||||
image: caddy:2.10.2-alpine
|
||||
restart: unless-stopped
|
||||
depends_on:
|
||||
caddy-init:
|
||||
condition: service_completed_successfully
|
||||
ports:
|
||||
- "80:80"
|
||||
- "8080:80"
|
||||
volumes:
|
||||
- caddy-caddyfiles:/etc/caddy
|
||||
- caddy-data:/data
|
||||
|
|
@ -21,3 +32,5 @@ volumes:
|
|||
networks:
|
||||
proxy:
|
||||
name: proxy
|
||||
driver: bridge
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
http://outils.localhost {
|
||||
http://outils.ft-chatons.local {
|
||||
header X-Chatons "miaou"
|
||||
|
||||
respond /healthcheck "OK"
|
||||
|
|
@ -16,12 +16,15 @@ http://outils.localhost {
|
|||
}
|
||||
|
||||
handle /ip {
|
||||
respond "{{.ClientIP}"
|
||||
respond "{http.request.remote.host}"
|
||||
}
|
||||
|
||||
handle_path /b64/encode/* {
|
||||
templates
|
||||
respond `{{ .Req.URL.Path | trimPrefix "/" | b64enc }}`
|
||||
}
|
||||
|
||||
handle_path /b64/decode/* {
|
||||
templates
|
||||
respond `{{ .Req.URL.Path | trimPrefix "/" | b64dec }}`
|
||||
}
|
||||
}
|
||||
69
core/tools/test-caddy
Normal file
69
core/tools/test-caddy
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
DOMAIN_NAME="http://outils.ft-chatons.local:8080"
|
||||
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m'
|
||||
|
||||
now=$(date +"%Y-%m-%d %H:%M:%S")
|
||||
|
||||
test_endpoint() {
|
||||
local name="$1"
|
||||
local url="$2"
|
||||
local expected_code="$3"
|
||||
local expected_body="$4"
|
||||
local match_mode="${5:-exact}"
|
||||
local follow_redirects="${6:-false}"
|
||||
|
||||
echo -n "Testing $name... "
|
||||
|
||||
local tmp
|
||||
tmp=$(mktemp)
|
||||
|
||||
local curl_args=(-s -o "$tmp" -w "%{http_code}" "$url")
|
||||
if [ "$follow_redirects" = "true" ]; then
|
||||
curl_args=(-s -L -o "$tmp" -w "%{http_code}" "$url")
|
||||
fi
|
||||
|
||||
local code
|
||||
code=$(curl "${curl_args[@]}" 2>/dev/null || echo "000")
|
||||
|
||||
local body
|
||||
body=$(cat "$tmp")
|
||||
rm -f "$tmp"
|
||||
|
||||
if [ "$code" != "$expected_code" ]; then
|
||||
echo -e "${RED}✗ FAIL${NC} (HTTP $code, expected $expected_code)"
|
||||
echo "Response: $body"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ -n "$expected_body" ]; then
|
||||
if [ "$match_mode" = "regex" ]; then
|
||||
if [[ ! "$body" =~ $expected_body ]]; then
|
||||
echo -e "${RED}✗ FAIL${NC} (body mismatch)"
|
||||
echo "Response: $body"
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
if [ "$body" != "$expected_body" ]; then
|
||||
echo -e "${RED}✗ FAIL${NC} (body mismatch)"
|
||||
echo "Response: $body"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
echo -e "${GREEN}✓ OK${NC} (HTTP $code)"
|
||||
return 0
|
||||
}
|
||||
|
||||
test_endpoint "Health Check" "$DOMAIN_NAME/healthcheck" "200" "OK"
|
||||
test_endpoint "Date Check" "$DOMAIN_NAME/date" "200" "^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}$" "regex"
|
||||
test_endpoint "IP check" "$DOMAIN_NAME/ip" "200" "^[0-9]{1,3}(\.[0-9]{1,3}){3}$" "regex"
|
||||
test_endpoint "Encode base64" "$DOMAIN_NAME/b64/encode/test" "200" "dGVzdA=="
|
||||
test_endpoint "Decode base64" "$DOMAIN_NAME/b64/decode/dGVzdA==" "200" "test"
|
||||
test_endpoint "Hello Check" "$DOMAIN_NAME/hello/Chatons" "200" "Hello Chatons!"
|
||||
test_endpoint "Root redirect" "$DOMAIN_NAME/" "200" "Hello world!" "exact" "true"
|
||||
20
justfile
Normal file
20
justfile
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
default:
|
||||
just --list
|
||||
|
||||
## Start the compose of the param
|
||||
start container="":
|
||||
docker compose -f core/{{container}}/compose.yml up -d
|
||||
|
||||
## Stop the compose of the param
|
||||
stop container="caddy":
|
||||
docker compose -f core/{{container}}/compose.yml down
|
||||
|
||||
## Restart all the compose
|
||||
re: stop
|
||||
docker volume rm $(docker volume ls -q) || true
|
||||
docker system prune -af
|
||||
docker volume prune -f
|
||||
just start caddy
|
||||
|
||||
tests:
|
||||
bash core/tools/test-caddy
|
||||
Loading…
Reference in a new issue