Luisotee/messaging #66
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: | |
push: | |
paths: | |
- 'deploy/**' | |
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 | |
cd $GITHUB_WORKSPACE | |
fi | |
done | |
- name: Wait for services to be ready | |
run: | | |
while IFS= read -r dir; do | |
service_name=$(basename "$dir" | sed 's/-stack//') | |
echo "Waiting for $service_name..." | |
# Get port from config | |
port=$(bun run -b --bun ./tooling/scripts/get-port.ts ${service_name}) | |
if [ -z "$port" ]; then | |
echo "No port configured for $service_name, skipping..." | |
continue | |
fi | |
# Wait for container health check | |
timeout 120 bash -c "until docker ps --filter name=${service_name} --format '{{.Status}}' | grep -q 'healthy'; do | |
echo 'Waiting for ${service_name} health check...' | |
sleep 5 | |
done" || { | |
echo "Service $service_name failed to become healthy" | |
docker logs ${service_name} | |
exit 1 | |
} | |
# Wait for port to be available | |
timeout 60 bash -c "until nc -z localhost $port; do | |
echo 'Waiting for port $port...' | |
sleep 2 | |
done" || { | |
echo "Service $service_name failed to expose port $port" | |
docker logs ${service_name} | |
exit 1 | |
} | |
done < $GITHUB_WORKSPACE/deploy_dirs.txt | |
- name: Test endpoints | |
run: | | |
while IFS= read -r dir; do | |
service_name=$(basename "$dir" | sed 's/-stack//') | |
echo "Testing endpoints for service: $service_name" | |
# Skip config packages | |
if [[ "$service_name" == "config" ]]; then | |
echo "Skipping config package: $service_name" | |
continue | |
fi | |
# Get port using bun script | |
port=$(bun run -b --bun ./tooling/scripts/get-port.ts ${service_name}) | |
if [ -z "$port" ]; then | |
echo "No port found for $service_name in config, skipping..." | |
continue | |
fi | |
test_url="http://localhost:${port}/" | |
echo "Testing URL: $test_url" | |
curl --fail --retry 5 --retry-delay 10 --retry-connrefused "$test_url" || { | |
echo "Failed to reach $test_url for $service_name" | |
docker logs ${service_name} || true | |
exit 1 | |
} | |
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 |