Luisotee/messaging #70
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 | |
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" | |
# 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 |