Skip to content

Commit

Permalink
Merge pull request #419 from lanedirt/418-improve-docker-compose-buil…
Browse files Browse the repository at this point in the history
…d-test-workflow

Update workflow test to show error if HTTP check fails
  • Loading branch information
lanedirt authored Nov 25, 2024
2 parents 48d3d26 + 5caa583 commit 88c10b5
Showing 1 changed file with 51 additions and 58 deletions.
109 changes: 51 additions & 58 deletions .github/workflows/docker-compose-build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# This workflow will test if building the Docker Compose containers from scratch works.
name: Docker Compose Build

on:
Expand All @@ -18,83 +17,77 @@ jobs:

steps:
- uses: actions/checkout@v2

- name: Set permissions and run install.sh
run: |
chmod +x install.sh
./install.sh build --verbose
- name: Set up Docker Compose
run: |
# Change the exposed host port of the SmtpService from 25 to 2525 because port 25 is not allowed in GitHub Actions
sed -i 's/25\:25/2525\:25/g' docker-compose.yml
docker compose -f docker-compose.yml up -d
sed -i 's/25\:25/2525\:25/g' docker-compose.yml
docker compose -f docker-compose.yml up -d
- name: Wait for services to be up
run: |
# Wait for a few seconds
sleep 15
- name: Test if localhost:443 (WASM app) responds
- name: Test if services are responding
uses: nick-fields/retry@v3
with:
timeout_minutes: 2
max_attempts: 3
timeout_minutes: 5
max_attempts: 5
command: |
http_code=$(curl -k -s -o /dev/null -w "%{http_code}" https://localhost:443)
if [ "$http_code" -ne 200 ]; then
echo "Service did not respond with 200 OK. Check if client app and/or nginx is configured correctly."
exit 1
else
echo "Service responded with 200 OK"
fi
sleep 5
- name: Test if localhost:443/api (WebApi) responds
uses: nick-fields/retry@v3
with:
timeout_minutes: 2
max_attempts: 3
command: |
http_code=$(curl -k -s -o /dev/null -w "%{http_code}" https://localhost:443/api)
if [ "$http_code" -ne 200 ]; then
echo "Service did not respond with expected 200 OK. Check if WebApi and/or nginx is configured correctly."
exit 1
else
echo "Service responded with $http_code"
fi
# Array of endpoints to test
declare -A endpoints=(
["WASM"]="https://localhost:443"
["WebApi"]="https://localhost:443/api"
["Admin"]="https://localhost:443/admin/user/login"
)
failed=false
# Test HTTP endpoints
for name in "${!endpoints[@]}"; do
url="${endpoints[$name]}"
echo "Testing $name at $url"
# Store both response body and HTTP code
response=$(curl -k -s -w "\nHTTP_CODE=%{http_code}" "$url")
http_code=$(echo "$response" | grep "HTTP_CODE=" | cut -d= -f2)
body=$(echo "$response" | sed '$d') # Remove the last line (HTTP_CODE)
- name: Test if localhost:443/admin (Admin) responds
uses: nick-fields/retry@v3
with:
timeout_minutes: 2
max_attempts: 3
command: |
http_code=$(curl -k -s -o /dev/null -w "%{http_code}" https://localhost:443/admin/user/login)
if [ "$http_code" -ne 200 ]; then
echo "Service did not respond with expected 200 OK. Check if admin app and/or nginx is configured correctly."
exit 1
echo "❌ $name failed with HTTP $http_code at $url"
echo "Response body:"
echo "$body"
failed=true
else
echo "Service responded with $http_code"
echo "✅ $name responded with HTTP 200"
fi
done
- name: Test if localhost:2525 (SmtpService) responds
uses: nick-fields/retry@v3
with:
timeout_minutes: 2
max_attempts: 3
command: |
if ! nc -zv localhost 2525 2>&1 | grep -q 'succeeded'; then
echo "SmtpService did not respond on port 2525. Check if the SmtpService service is running."
exit 1
else
echo "SmtpService responded on port 2525"
fi
# Test SMTP
echo "Testing SmtpService at localhost:2525"
if ! nc -zv localhost 2525 2>&1 | grep -q 'succeeded'; then
echo "❌ SmtpService failed to respond on port 2525"
failed=true
else
echo "✅ SmtpService responded successfully"
fi
# Exit with error if any service failed
if [ "$failed" = true ]; then
# Get container logs
echo "Container Logs:"
docker compose logs
exit 1
fi
- name: Test install.sh reset-password output
run: |
output=$(./install.sh reset-password)
if ! echo "$output" | grep -E '.*New admin password: [A-Za-z0-9+/=]{8,}.*'; then
echo "Password reset output format is incorrect. Expected format: 'New admin password: <at least 8 base64 chars>'"
echo "Actual output: $output"
echo "Password reset output format is incorrect"
echo "Expected: 'New admin password: <at least 8 base64 chars>'"
echo "Actual: $output"
exit 1
else
echo "Password reset output format is correct"
fi
fi

0 comments on commit 88c10b5

Please sign in to comment.