Skip to content

Commit 7e95f46

Browse files
committed
added logging
1 parent 695b7b8 commit 7e95f46

3 files changed

Lines changed: 111 additions & 1 deletion

File tree

.github/workflows/run-samples.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,38 @@ jobs:
128128
env:
129129
LOCALSTACK_AUTH_TOKEN: ${{ secrets.TEST_LOCALSTACK_AUTH_TOKEN }}
130130

131+
- name: Docker state snapshot
132+
# Capture the full Docker state on failure to diagnose missing web app containers.
133+
if: failure()
134+
run: |
135+
echo "=== All Docker containers (running + stopped) ==="
136+
docker ps -a --format "table {{.Names}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}" 2>&1
137+
echo ""
138+
echo "=== Docker images ==="
139+
docker images --format "table {{.Repository}}\t{{.Tag}}\t{{.Size}}\t{{.ID}}" 2>&1
140+
echo ""
141+
echo "=== Exited container logs ==="
142+
for c in $(docker ps -a --filter "status=exited" --format "{{.Names}}" 2>/dev/null); do
143+
echo "--- [$c] (last 50 lines) ---"
144+
docker logs "$c" --tail 50 2>&1
145+
done
146+
131147
- name: Get LocalStack Logs
132148
# Captured on failure or success to provide a detailed audit trail of the emulator's activity.
133149
if: always()
134150
run: make logs
151+
152+
- name: Get LocalStack Logs (webapp filtered)
153+
# Filtered view of LocalStack logs to surface web app container creation issues.
154+
if: failure()
155+
run: |
156+
LS_CONTAINER=$(docker ps --format "{{.Names}}" | grep -i "localstack" | head -1)
157+
if [ -n "$LS_CONTAINER" ]; then
158+
echo "=== LocalStack logs filtered for web app / container issues ==="
159+
docker logs "$LS_CONTAINER" 2>&1 | grep -iE "(ls-local-webapp|webapp.*deploy|container.*create|container.*start|pip.*install|requirements\.txt|cryptography|certificates|import.*error|module.*not.*found|build.*fail|gunicorn|flask|startup.*command|oryx|ModuleNotFoundError|Traceback)" | tail -200 || echo "(no matching lines)"
160+
echo ""
161+
echo "=== LocalStack logs filtered for ERROR/EXCEPTION ==="
162+
docker logs "$LS_CONTAINER" 2>&1 | grep -iE "(ERROR|EXCEPTION|FATAL|CRITICAL)" | tail -100 || echo "(no errors found)"
163+
else
164+
echo "No LocalStack container found"
165+
fi

samples/web-app-sql-database/python/scripts/deploy.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,48 @@ else
479479
exit 1
480480
fi
481481

482+
# ============================================================
483+
# DEBUG: Post-deployment diagnostics
484+
# ============================================================
485+
echo "=== DEBUG: Post-deployment container state ==="
486+
487+
echo "--- All running Docker containers ---"
488+
docker ps --format "table {{.Names}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}" 2>&1
489+
490+
echo "--- All Docker containers (including stopped/exited) ---"
491+
docker ps -a --format "table {{.Names}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}" 2>&1
492+
493+
echo "--- Docker images ---"
494+
docker images --format "table {{.Repository}}\t{{.Tag}}\t{{.Size}}" 2>&1
495+
496+
# Find the LocalStack main container and show relevant logs
497+
LS_CONTAINER=$(docker ps --format "{{.Names}}" | grep -i "localstack" | head -1)
498+
if [ -n "$LS_CONTAINER" ]; then
499+
echo "--- LocalStack container [$LS_CONTAINER] logs (last 100 lines, filtered for webapp/container/deploy) ---"
500+
docker logs "$LS_CONTAINER" --tail 100 2>&1 | grep -iE "(webapp|container|deploy|error|exception|pip|install|cryptography|certificates|failed|build)" || echo "(no matching log lines found)"
501+
502+
echo "--- LocalStack container [$LS_CONTAINER] logs (last 50 lines, unfiltered) ---"
503+
docker logs "$LS_CONTAINER" --tail 50 2>&1
504+
else
505+
echo "WARNING: No LocalStack container found"
506+
fi
507+
508+
# Check for any recently exited containers
509+
EXITED_CONTAINERS=$(docker ps -a --filter "status=exited" --format "{{.Names}}\t{{.Image}}\t{{.Status}}" 2>&1)
510+
if [ -n "$EXITED_CONTAINERS" ]; then
511+
echo "--- Recently exited containers ---"
512+
echo "$EXITED_CONTAINERS"
513+
# Show logs from any exited container that might be the web app
514+
docker ps -a --filter "status=exited" --format "{{.Names}}" | while read -r c; do
515+
echo "--- Logs from exited container [$c] (last 30 lines) ---"
516+
docker logs "$c" --tail 30 2>&1
517+
done
518+
else
519+
echo "--- No exited containers found ---"
520+
fi
521+
522+
echo "=== END DEBUG: Post-deployment diagnostics ==="
523+
482524
# Get web app URL
483525
WEB_APP_URL=$($AZ webapp show \
484526
--name "$WEB_APP_NAME" \

samples/web-app-sql-database/python/scripts/get-web-app-url.sh

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,49 @@ call_web_app() {
105105

106106
# Get the Docker container name (with retries, as the container may take time to start after deployment)
107107
echo "Finding container name with prefix [ls-$web_app_name]..."
108-
MAX_RETRIES=30
108+
MAX_RETRIES=18
109109
RETRY_INTERVAL=10
110110
container_name=""
111111
for ((attempt=1; attempt<=MAX_RETRIES; attempt++)); do
112112
container_name=$(get_docker_container_name_by_prefix "ls-$web_app_name") && break
113113
container_name=""
114+
115+
# Print full diagnostics on first, every 6th, and last attempt
116+
if [ "$attempt" -eq 1 ] || [ "$((attempt % 6))" -eq 0 ] || [ "$attempt" -eq "$MAX_RETRIES" ]; then
117+
echo "=== DEBUG (attempt $attempt/$MAX_RETRIES): Container diagnostics ==="
118+
119+
echo "--- All running containers ---"
120+
docker ps --format "table {{.Names}}\t{{.Image}}\t{{.Status}}" 2>&1
121+
122+
echo "--- All containers (including stopped/exited) ---"
123+
docker ps -a --format "table {{.Names}}\t{{.Image}}\t{{.Status}}" 2>&1
124+
125+
echo "--- Docker images ---"
126+
docker images --format "table {{.Repository}}\t{{.Tag}}\t{{.ID}}" 2>&1
127+
128+
# Check LocalStack logs for web app container creation errors
129+
LS_CONTAINER=$(docker ps --format "{{.Names}}" | grep -i "localstack" | head -1)
130+
if [ -n "$LS_CONTAINER" ]; then
131+
echo "--- LocalStack logs (last 50 lines, filtered for webapp/container/error) ---"
132+
docker logs "$LS_CONTAINER" --tail 200 2>&1 | grep -iE "(ls-${web_app_name}|webapp.*container|container.*webapp|pip.*install|requirements|cryptography|certificates|import.*error|module.*not.*found|build.*fail|error.*build|startup|gunicorn|flask)" | tail -50 || echo "(no matching log lines)"
133+
134+
echo "--- LocalStack logs (last 30 lines, unfiltered) ---"
135+
docker logs "$LS_CONTAINER" --tail 30 2>&1
136+
fi
137+
138+
# Show logs from any exited containers
139+
EXITED=$(docker ps -a --filter "status=exited" --format "{{.Names}}" 2>/dev/null)
140+
if [ -n "$EXITED" ]; then
141+
echo "--- Exited container logs ---"
142+
echo "$EXITED" | while read -r c; do
143+
echo " [$c] logs (last 20 lines):"
144+
docker logs "$c" --tail 20 2>&1 | sed 's/^/ /'
145+
done
146+
fi
147+
148+
echo "=== END DEBUG ==="
149+
fi
150+
114151
if [ "$attempt" -lt "$MAX_RETRIES" ]; then
115152
echo "Attempt $attempt/$MAX_RETRIES: Container not found yet. Waiting ${RETRY_INTERVAL}s..."
116153
sleep "$RETRY_INTERVAL"

0 commit comments

Comments
 (0)