Luisotee/messaging #72
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deployment Stacks | |
on: | |
pull_request: | |
paths: | |
- 'deploy/**' | |
jobs: | |
deploy-and-test: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup Bun | |
uses: oven-sh/setup-bun@v2 | |
with: | |
bun-version: latest | |
- name: Install UV | |
uses: astral-sh/setup-uv@v3 | |
- name: Install dependencies | |
run: | | |
bun install | |
uv venv | |
. .venv/bin/activate | |
- name: Setup config | |
run: | | |
cp config.example.yaml config.yaml | |
bun run build:config | |
- name: Create Docker network | |
run: docker network create eda-network || true | |
- name: Find and process deploy directories | |
run: | | |
# Create dirs file | |
touch $GITHUB_WORKSPACE/deploy_dirs.txt | |
for dir in deploy/*/; do | |
if [ -d "$dir" ]; then | |
echo "Processing $dir" | |
cd "$dir" | |
# Generate env from config | |
bun run export-config.ts > .env | |
# Start containers | |
docker compose up -d | |
# Store directory | |
echo "${dir%/}" >> $GITHUB_WORKSPACE/deploy_dirs.txt | |
# Wait for containers to be fully up | |
echo "Waiting for containers to initialize..." | |
sleep 15 | |
# Check if all containers are healthy | |
docker compose ps --format "{{.Name}} {{.Status}}" | while read -r line; do | |
if [[ ! $line =~ "(healthy)" ]] && [[ ! $line =~ "Up" ]]; then | |
echo "Container not healthy: $line" | |
docker compose logs | |
exit 1 | |
fi | |
done | |
cd $GITHUB_WORKSPACE | |
fi | |
done | |
- name: Test endpoints | |
run: | | |
while IFS= read -r dir; do | |
service_name=$(basename "$dir" | sed 's/-stack//') | |
echo "=== Testing endpoints for service: $service_name ===" | |
# Show container status | |
echo "Docker container status:" | |
docker ps -a | grep $service_name || true | |
# Show container logs | |
echo "Container logs:" | |
docker logs $service_name 2>&1 || true | |
# Skip config packages | |
if [[ "$service_name" == "config" ]]; then | |
echo "Skipping config package: $service_name" | |
continue | |
fi | |
# Get and verify port | |
port=$(bun run -b --bun ./tooling/scripts/get-port.ts ${service_name}) | |
echo "Retrieved port: $port" | |
if [ -z "$port" ]; then | |
echo "No port found for $service_name in config, skipping..." | |
continue | |
fi | |
# Network connectivity check | |
echo "Testing network connectivity:" | |
nc -zv localhost $port 2>&1 || true | |
test_url="http://localhost:${port}/" | |
echo "Testing URL: $test_url" | |
# More verbose curl | |
curl -v --fail --retry 5 --retry-delay 10 --retry-connrefused "$test_url" || { | |
echo "=== Error Details ===" | |
echo "Failed to reach $test_url for $service_name" | |
echo "Container status:" | |
docker ps -a | grep $service_name || true | |
echo "Latest logs:" | |
docker logs --tail 50 ${service_name} 2>&1 || true | |
echo "Network status:" | |
netstat -tulpn | grep $port || true | |
exit 1 | |
} | |
echo "=== Test completed for $service_name ===" | |
done < $GITHUB_WORKSPACE/deploy_dirs.txt | |
- name: Check service health | |
run: | | |
while IFS= read -r dir; do | |
service_name=$(basename "$dir" | sed 's/-stack//') | |
echo "Checking health for $service_name..." | |
# Get port from config | |
port=$(bun run -b --bun ./tooling/scripts/get-port.ts ${service_name}) | |
# Skip if no port found | |
if [ -z "$port" ]; then | |
echo "No port configured for $service_name, skipping..." | |
continue | |
fi | |
# Wait for port to be available | |
timeout 60 bash -c "until nc -z localhost $port; do sleep 2; done" || { | |
echo "Service $service_name not ready on port $port" | |
docker logs ${service_name} || true | |
exit 1 | |
} | |
done < $GITHUB_WORKSPACE/deploy_dirs.txt | |
- name: Cleanup | |
if: always() | |
run: | | |
if [ -f "$GITHUB_WORKSPACE/deploy_dirs.txt" ]; then | |
while IFS= read -r dir; do | |
cd "$dir" | |
docker compose down | |
cd $GITHUB_WORKSPACE | |
done < $GITHUB_WORKSPACE/deploy_dirs.txt | |
fi |