From 783fd5a905771585e9fded706ed0b7ea2bddb697 Mon Sep 17 00:00:00 2001 From: 98001yash Date: Mon, 12 Oct 2026 15:31:17 +0530 Subject: [PATCH 1/2] ci: validate Docker image at runtime --- .github/workflows/ci.yml | 46 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 875f1ca..c181572 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,3 +53,49 @@ jobs: - name: Build Docker image run: docker build -t distributed-traffic-control:${{ github.sha }} . + + - name: Validate Docker image at runtime + shell: bash + run: | + set -Eeuo pipefail + + IMAGE="distributed-traffic-control:${GITHUB_SHA}" + CONTAINER="traffic-control-ci-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}" + + cleanup() { + docker rm -f "$CONTAINER" >/dev/null 2>&1 || true + } + trap cleanup EXIT + + docker run -d \ + --name "$CONTAINER" \ + -p 127.0.0.1::8081 \ + -e SERVER_PORT=8081 \ + -e REDIS_HOST=127.0.0.1 \ + -e REDIS_PORT=6379 \ + -e NODE_ID=ci-validation \ + -e LEASE_DURATION=PT30S \ + -e LEASE_CAPACITY=10 \ + "$IMAGE" + + PORT=$(docker port "$CONTAINER" 8081/tcp | awk -F: '{print $NF}') + + for attempt in $(seq 1 30); do + if curl --fail --silent "http://127.0.0.1:${PORT}/actuator/health"; then + echo + echo "Docker image runtime validation passed." + exit 0 + fi + + if [ "$(docker inspect -f '{{.State.Running}}' "$CONTAINER")" != "true" ]; then + echo "Container exited before becoming healthy." + docker logs "$CONTAINER" + exit 1 + fi + + sleep 2 + done + + echo "Application health endpoint did not become ready in time." + docker logs "$CONTAINER" + exit 1 From 8e88965d8e8020a15a2344ac5a1c00c7c1aa962f Mon Sep 17 00:00:00 2001 From: 98001yash Date: Mon, 12 Oct 2026 15:37:12 +0530 Subject: [PATCH 2/2] ci: validate Docker image at runtime --- .github/workflows/ci.yml | 43 +++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c181572..9352215 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -60,25 +60,50 @@ jobs: set -Eeuo pipefail IMAGE="distributed-traffic-control:${GITHUB_SHA}" - CONTAINER="traffic-control-ci-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}" + NETWORK="traffic-control-ci-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}" + REDIS_CONTAINER="${NETWORK}-redis" + APP_CONTAINER="${NETWORK}-app" cleanup() { - docker rm -f "$CONTAINER" >/dev/null 2>&1 || true + docker rm -f "$APP_CONTAINER" "$REDIS_CONTAINER" >/dev/null 2>&1 || true + docker network rm "$NETWORK" >/dev/null 2>&1 || true } trap cleanup EXIT + docker network create "$NETWORK" + + docker run -d \ + --name "$REDIS_CONTAINER" \ + --network "$NETWORK" \ + redis:7-alpine + + for attempt in $(seq 1 15); do + if docker exec "$REDIS_CONTAINER" redis-cli ping | grep -q PONG; then + break + fi + + if [ "$attempt" -eq 15 ]; then + echo "Redis did not become ready." + docker logs "$REDIS_CONTAINER" + exit 1 + fi + + sleep 2 + done + docker run -d \ - --name "$CONTAINER" \ + --name "$APP_CONTAINER" \ + --network "$NETWORK" \ -p 127.0.0.1::8081 \ -e SERVER_PORT=8081 \ - -e REDIS_HOST=127.0.0.1 \ + -e REDIS_HOST="$REDIS_CONTAINER" \ -e REDIS_PORT=6379 \ -e NODE_ID=ci-validation \ -e LEASE_DURATION=PT30S \ -e LEASE_CAPACITY=10 \ "$IMAGE" - PORT=$(docker port "$CONTAINER" 8081/tcp | awk -F: '{print $NF}') + PORT=$(docker port "$APP_CONTAINER" 8081/tcp | awk -F: '{print $NF}') for attempt in $(seq 1 30); do if curl --fail --silent "http://127.0.0.1:${PORT}/actuator/health"; then @@ -87,9 +112,9 @@ jobs: exit 0 fi - if [ "$(docker inspect -f '{{.State.Running}}' "$CONTAINER")" != "true" ]; then - echo "Container exited before becoming healthy." - docker logs "$CONTAINER" + if [ "$(docker inspect -f '{{.State.Running}}' "$APP_CONTAINER")" != "true" ]; then + echo "Application container exited before becoming healthy." + docker logs "$APP_CONTAINER" exit 1 fi @@ -97,5 +122,5 @@ jobs: done echo "Application health endpoint did not become ready in time." - docker logs "$CONTAINER" + docker logs "$APP_CONTAINER" exit 1