From e05f74bd82409834e81760b535ff6be65435302a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20M=C3=B6rling?= Date: Wed, 13 May 2026 19:17:55 +0200 Subject: [PATCH] chore: add Docker CI compose, Gradle E2E task, and .dockerignore Add infrastructure for running Playwright E2E tests in Docker and fix Gradle lock conflicts between host and container builds. Changes: - Add docker-compose.ci.yml that starts postgres, backend, frontend, and a Playwright service for CI pipelines. Uses official mcr.microsoft.com/playwright:v1.60.0-noble image. - Add backend-gradle-project named volume to docker-compose.yml so the container's .gradle/ directory is isolated from the host's. This prevents stale lock files from host Gradle builds (e.g. ./gradlew :backend:test) crashing the container's bootRun. - Add .dockerignore excluding .gradle, .env, .git, frontend/node_modules, and backend/build from the Docker build context. - Add frontendE2E Gradle task that runs npm run test:e2e:ci. --- .dockerignore | 5 ++++ build.gradle | 6 +++++ docker-compose.ci.yml | 63 +++++++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 2 ++ 4 files changed, 76 insertions(+) create mode 100644 .dockerignore create mode 100644 docker-compose.ci.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..237714d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +.gradle +.env +.git +frontend/node_modules +backend/build diff --git a/build.gradle b/build.gradle index 49d979f..f49651b 100644 --- a/build.gradle +++ b/build.gradle @@ -15,6 +15,12 @@ tasks.register('frontendTest', Exec) { commandLine 'npm', 'run', 'test' } +tasks.register('frontendE2E', Exec) { + description = 'Run Playwright E2E tests in Docker (CI mode)' + workingDir = file("${rootProject.projectDir}/frontend") + commandLine 'npm', 'run', 'test:e2e:ci' +} + tasks.named('check').configure { dependsOn frontendLint, frontendTest } diff --git a/docker-compose.ci.yml b/docker-compose.ci.yml new file mode 100644 index 0000000..52d6f2d --- /dev/null +++ b/docker-compose.ci.yml @@ -0,0 +1,63 @@ +services: + postgres: + image: postgres:16 + container_name: bilhej-postgres-ci + environment: + POSTGRES_DB: ${POSTGRES_DB} + POSTGRES_USER: ${POSTGRES_USER} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} + healthcheck: + test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"] + interval: 5s + timeout: 5s + retries: 5 + + backend: + build: + dockerfile: docker/backend.Dockerfile + context: . + container_name: bilhej-backend-ci + environment: + SPRING_PROFILES_ACTIVE: docker + POSTGRES_DB: ${POSTGRES_DB} + POSTGRES_USER: ${POSTGRES_USER} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} + JWT_SECRET: ${JWT_SECRET} + STRIPE_SECRET_KEY: ${STRIPE_SECRET_KEY} + STRIPE_WEBHOOK_SECRET: ${STRIPE_WEBHOOK_SECRET} + STRIPE_PRICE_ID: ${STRIPE_PRICE_ID} + depends_on: + postgres: + condition: service_healthy + volumes: + - .:/app + - gradle-cache:/root/.gradle + + frontend: + build: + dockerfile: docker/frontend.Dockerfile + context: . + container_name: bilhej-frontend-ci + depends_on: + - backend + + playwright: + image: mcr.microsoft.com/playwright:v1.60.0-noble + container_name: bilhej-playwright + ipc: host + working_dir: /app + environment: + PLAYWRIGHT_BASE_URL: http://frontend:3000 + volumes: + - ./frontend/package.json:/app/package.json + - ./frontend/package-lock.json:/app/package-lock.json + - ./frontend/playwright.config.ts:/app/playwright.config.ts + - ./frontend/e2e:/app/e2e + - ./frontend/node_modules:/app/node_modules + depends_on: + - frontend + command: > + sh -c "npm ci --ignore-scripts && npx playwright test --reporter=list" + +volumes: + gradle-cache: diff --git a/docker-compose.yml b/docker-compose.yml index e8b081b..f03e50a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -37,6 +37,7 @@ services: condition: service_healthy volumes: - .:/app + - backend-gradle-project:/app/.gradle - gradle-cache:/root/.gradle frontend: @@ -56,3 +57,4 @@ services: volumes: pgdata: gradle-cache: + backend-gradle-project: