feat: add lint, build, test, push pipeline with SHA-pinned actions
- Split single build job into 4 jobs: lint, build, test, push - SHA-pin all actions for supply chain security - Use ChristopherHX artifact actions (Gitea-compatible) - Switch to root build context (Dockerfile does COPY ../public) - Add tests/test.sh with Docker bridge gateway networking
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
IMAGE="${1:?Usage: test.sh <image>}"
|
||||
CONTAINER_NAME="test-$(echo "$IMAGE" | tr ':/' '-')-$$"
|
||||
PASSED=0
|
||||
FAILED=0
|
||||
TOTAL=0
|
||||
|
||||
cleanup() {
|
||||
docker rm -f "$CONTAINER_NAME" >/dev/null 2>&1 || true
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
assert() {
|
||||
local name="$1" expected="$2" actual="$3"
|
||||
TOTAL=$((TOTAL + 1))
|
||||
if [ "$expected" = "$actual" ]; then
|
||||
echo " PASS: $name"
|
||||
PASSED=$((PASSED + 1))
|
||||
else
|
||||
echo " FAIL: $name (expected: '$expected', got: '$actual')"
|
||||
FAILED=$((FAILED + 1))
|
||||
fi
|
||||
}
|
||||
|
||||
echo "Running container: $IMAGE"
|
||||
docker run -d --name "$CONTAINER_NAME" -p 8080:80 "$IMAGE" >/dev/null
|
||||
|
||||
DOCKER_GW=$(docker network inspect bridge --format '{{range .IPAM.Config}}{{.Gateway}}{{end}}')
|
||||
BASE_URL="http://${DOCKER_GW}:8080"
|
||||
|
||||
echo "Waiting for container on ${DOCKER_GW}:8080..."
|
||||
for i in $(seq 1 30); do
|
||||
if [ "$(curl -s -o /dev/null -w '%{http_code}' "$BASE_URL/" 2>/dev/null)" != "000" ]; then
|
||||
echo "Container ready after ${i}s"
|
||||
break
|
||||
fi
|
||||
if [ "$i" -eq 30 ]; then
|
||||
echo "FAIL: Container did not become ready within 30s"
|
||||
docker logs "$CONTAINER_NAME"
|
||||
exit 1
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
|
||||
echo ""
|
||||
echo "Test: GET / (basic_auth should return 401)"
|
||||
STATUS=$(curl -s -o /dev/null -w '%{http_code}' "$BASE_URL/")
|
||||
|
||||
assert "HTTP status is 401 (Unauthorized)" "401" "$STATUS"
|
||||
|
||||
echo ""
|
||||
echo "Results: $PASSED/$TOTAL passed, $FAILED failed"
|
||||
[ "$FAILED" -eq 0 ]
|
||||
Reference in New Issue
Block a user