refactor: update docker-compose and CI workflow for improved E2E testing
- Removed fixed container names in docker-compose.dev-env.yml to prevent conflicts during redeploys. - Enhanced playwright.config.js comments for clarity on base URL usage in different environments. - Updated .gitea/workflows/test.yml to streamline E2E testing setup, including conditional logic for local and production environments, and improved health check handling after deployment.
This commit is contained in:
parent
50b8ff12cd
commit
f4a86f9726
|
|
@ -57,6 +57,9 @@ jobs:
|
|||
playwright-tests:
|
||||
if: ${{ github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success' }}
|
||||
runs-on: ubuntu-latest
|
||||
# Lokal: docker-compose.dev-env + COMPOSE_PROJECT_NAME. Nach „Deploy Production“: HTTPS-Prod (kein Docker).
|
||||
env:
|
||||
COMPOSE_PROJECT_NAME: shinkan-e2e-${{ github.run_id }}
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
|
@ -66,7 +69,23 @@ jobs:
|
|||
with:
|
||||
node-version: '20'
|
||||
|
||||
- name: Start dev stack for E2E
|
||||
- name: E2E-Ziel wählen (lokal vs. Production)
|
||||
id: e2e
|
||||
run: |
|
||||
EVENT="${{ github.event_name }}"
|
||||
WF_NAME="${{ github.event.workflow_run.name }}"
|
||||
if [ "$EVENT" = "workflow_run" ] && [ "$WF_NAME" = "Deploy Production" ]; then
|
||||
echo "mode=prod" >> $GITHUB_OUTPUT
|
||||
echo "base_url=https://shinkan.jinkendo.de" >> $GITHUB_OUTPUT
|
||||
echo "→ Playwright gegen Production. Login: Secrets E2E_PROD_TEST_EMAIL / E2E_PROD_TEST_PASSWORD."
|
||||
else
|
||||
echo "mode=local" >> $GITHUB_OUTPUT
|
||||
echo "base_url=http://127.0.0.1:3098" >> $GITHUB_OUTPUT
|
||||
echo "→ Playwright gegen lokalen Stack (docker-compose.dev-env.yml)."
|
||||
fi
|
||||
|
||||
- name: Start dev stack for E2E (nur lokal)
|
||||
if: ${{ steps.e2e.outputs.mode == 'local' }}
|
||||
env:
|
||||
DEV_ALLOWED_ORIGINS: http://127.0.0.1:3098,http://localhost:3098,http://host.docker.internal:3098,https://dev.shinkan.jinkendo.de
|
||||
run: |
|
||||
|
|
@ -84,7 +103,24 @@ jobs:
|
|||
docker compose -f docker-compose.dev-env.yml logs --tail=120
|
||||
exit 1
|
||||
|
||||
- name: Seed E2E test user (erste Registrierung in frischer DB)
|
||||
- name: Prod /health abwarten (nach Deploy)
|
||||
if: ${{ steps.e2e.outputs.mode == 'prod' }}
|
||||
run: |
|
||||
BASE="${{ steps.e2e.outputs.base_url }}"
|
||||
echo "Warte auf $BASE/health …"
|
||||
for i in $(seq 1 60); do
|
||||
if curl -sf "$BASE/health" >/dev/null 2>&1; then
|
||||
echo "Health OK (Versuch $i)"
|
||||
exit 0
|
||||
fi
|
||||
sleep 5
|
||||
done
|
||||
echo "Timeout: Prod /health nicht erreichbar"
|
||||
curl -v "$BASE/health" || true
|
||||
exit 1
|
||||
|
||||
- name: Seed E2E-User (nur lokaler Stack, frische DB)
|
||||
if: ${{ steps.e2e.outputs.mode == 'local' }}
|
||||
env:
|
||||
TEST_EMAIL: lars@stommer.com
|
||||
TEST_PASSWORD: 12345678
|
||||
|
|
@ -100,18 +136,32 @@ jobs:
|
|||
npx playwright install --with-deps chromium
|
||||
|
||||
- name: Run Playwright tests
|
||||
env:
|
||||
PLAYWRIGHT_BASE_URL: http://127.0.0.1:3098
|
||||
TEST_EMAIL: lars@stommer.com
|
||||
TEST_PASSWORD: 12345678
|
||||
run: |
|
||||
set -e
|
||||
MODE="${{ steps.e2e.outputs.mode }}"
|
||||
BASE_URL="${{ steps.e2e.outputs.base_url }}"
|
||||
if [ "$MODE" = "prod" ]; then
|
||||
export PLAYWRIGHT_BASE_URL="$BASE_URL"
|
||||
export TEST_EMAIL="${{ secrets.E2E_PROD_TEST_EMAIL }}"
|
||||
export TEST_PASSWORD="${{ secrets.E2E_PROD_TEST_PASSWORD }}"
|
||||
if [ -z "$TEST_EMAIL" ] || [ -z "$TEST_PASSWORD" ]; then
|
||||
echo "Fehler: Für Prod-E2E Repository-Secrets E2E_PROD_TEST_EMAIL und E2E_PROD_TEST_PASSWORD setzen (Testnutzer mit Login auf Prod)."
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
export PLAYWRIGHT_BASE_URL="$BASE_URL"
|
||||
export TEST_EMAIL="lars@stommer.com"
|
||||
export TEST_PASSWORD="12345678"
|
||||
fi
|
||||
mkdir -p screenshots
|
||||
npx playwright test
|
||||
echo "✓ Playwright tests passed"
|
||||
|
||||
- name: Stop dev stack
|
||||
if: always()
|
||||
run: docker compose -f docker-compose.dev-env.yml down
|
||||
if: ${{ always() && steps.e2e.outputs.mode == 'local' }}
|
||||
run: |
|
||||
docker compose -f docker-compose.dev-env.yml down --remove-orphans
|
||||
echo "Gestoppt unter Projekt: ${COMPOSE_PROJECT_NAME}"
|
||||
|
||||
- name: Upload test screenshots
|
||||
if: failure()
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
version: '3.8'
|
||||
|
||||
# Keine festen container_name: Namen sind hostweit eindeutig und kollidieren bei
|
||||
# erneuten Deploys / anderem Compose-Projektprefix. Compose vergibt z. B. <projekt>-postgres-1.
|
||||
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:16-alpine
|
||||
container_name: dev-shinkan-postgres
|
||||
environment:
|
||||
POSTGRES_DB: shinkan_dev
|
||||
POSTGRES_USER: shinkan_dev
|
||||
|
|
@ -20,7 +22,6 @@ services:
|
|||
build:
|
||||
context: ./backend
|
||||
dockerfile: Dockerfile
|
||||
container_name: dev-shinkan-api
|
||||
environment:
|
||||
DB_HOST: postgres
|
||||
DB_PORT: 5432
|
||||
|
|
@ -63,7 +64,6 @@ services:
|
|||
# Leer = relative /api/*-URLs → gleicher Host wie die SPA (vermeidet Mixed Content HTTPS→HTTP)
|
||||
args:
|
||||
VITE_API_URL: ""
|
||||
container_name: dev-shinkan-ui
|
||||
ports:
|
||||
- "3098:80"
|
||||
depends_on:
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// CI: PLAYWRIGHT_BASE_URL=http://127.0.0.1:3098 nach docker compose dev-env
|
||||
// Lokal gegen LAN/Dev: export PLAYWRIGHT_BASE_URL=http://192.168.x.x:3098
|
||||
// CI: PLAYWRIGHT_BASE_URL — lokal docker dev-env (:3098); nach „Deploy Production“ https://shinkan.jinkendo.de
|
||||
// Lokal: export PLAYWRIGHT_BASE_URL=http://192.168.x.x:3098
|
||||
|
||||
const rawBase =
|
||||
process.env.PLAYWRIGHT_BASE_URL ||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user