Skip to content

Commit

Permalink
chore(action): prepare middleware containers before e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcfps committed Feb 5, 2025
1 parent 8e4761b commit dc8fcc0
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 4 deletions.
18 changes: 17 additions & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
types: [opened, synchronize]

jobs:
build:
e2e:
runs-on: ubuntu-latest
strategy:
fail-fast: false # https://github.com/cypress-io/github-action/issues/48
Expand All @@ -27,6 +27,22 @@ jobs:
node-version: 20
cache: 'pnpm'

- name: Start Middleware Containers
run: |
docker compose -f deploy/docker/docker-compose.middleware.yml up -d
docker ps
- name: Install yq
run: |
wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/local/bin/yq
chmod +x /usr/local/bin/yq
- name: Wait for Middleware Containers to be Healthy
run: |
CONTAINERS=$(yq e '.services | map(.container_name) | join(" ")' deploy/docker/docker-compose.middleware.yml)
bash scripts/wait-for-container-health.sh $CONTAINERS
docker ps
- name: E2E Tests
uses: cypress-io/github-action@v6
with:
Expand Down
2 changes: 1 addition & 1 deletion apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"sync-db-schema": "prisma format && prisma generate && node -r ts-node/register --env-file=.env src/scripts/sync-db-schema.ts",
"dev": "nodemon",
"dev:debug": "nodemon --inspect",
"start": "node dist/main.js",
"start": "node --env-file=.env dist/scripts/sync-db-schema.js && node --env-file=.env dist/main.js",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
Expand Down
36 changes: 36 additions & 0 deletions scripts/wait-for-container-health.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash
set -e

function wait_for_health {
local container="$1"
local max_attempts=30
local count=0

while [ "$count" -lt "$max_attempts" ]; do
health_status=$(docker inspect --format '{{.State.Health.Status}}' "$container")
if [ "$health_status" == "healthy" ]; then
echo "$container is healthy."
return 0
fi
echo "Waiting for $container to be healthy..."
sleep 5
count=$((count + 1))
done

echo "$container did not become healthy in time."
return 1
}

# Check if any arguments were provided
if [ $# -eq 0 ]; then
echo "Error: No container names provided"
echo "Usage: $0 container1 container2 ..."
exit 1
fi

# Process each container name provided as an argument
for container in "$@"; do
wait_for_health "$container" || exit 1
done

echo "All containers are healthy!"
3 changes: 1 addition & 2 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
},
"start": {
"cache": false,
"persistent": false,
"dependsOn": ["sync-db-schema"]
"persistent": false
},
"sync-db-schema": {
"cache": false,
Expand Down

0 comments on commit dc8fcc0

Please sign in to comment.