ci/cd: start test containers with Docker Compose

This commit is contained in:
Elias Schneider
2025-05-22 22:23:54 +02:00
parent 966a566ade
commit ebcf861aa6
5 changed files with 81 additions and 87 deletions

View File

@@ -95,43 +95,31 @@ jobs:
if: steps.lldap-cache.outputs.cache-hit == 'true'
run: docker load < /tmp/lldap-image.tar
- name: Install frontend dependencies
working-directory: ./frontend
- name: Install test dependencies
working-directory: ./tests
run: npm ci
- name: Install Playwright Browsers
working-directory: ./frontend
working-directory: ./tests
if: steps.playwright-cache.outputs.cache-hit != 'true'
run: npx playwright install --with-deps chromium
- name: Create Docker network
run: docker network create pocket-id-network
- name: Setup and Configure LLDAP Server
run: |
chmod +x ./scripts/tests/setup-lldap.sh
./scripts/tests/setup-lldap.sh
- name: Run Docker Container with Sqlite DB and LDAP
working-directory: ./tests/setup
run: |
docker run -d --name pocket-id-sqlite \
--network pocket-id-network \
-p 1411:1411 \
-e APP_ENV=test \
pocket-id:test
docker logs -f pocket-id-sqlite &> /tmp/backend.log &
docker compose up -d
docker compose logs -f pocket-id &> /tmp/backend.log &
- name: Run Playwright tests
working-directory: ./frontend
working-directory: ./tests
run: npx playwright test
- name: Upload Frontend Test Report
- name: Upload Test Report
uses: actions/upload-artifact@v4
if: always() && github.event.pull_request.head.ref != 'i18n_crowdin'
with:
name: playwright-report-sqlite
path: frontend/tests/.report
path: tests/.report
include-hidden-files: true
retention-days: 15
@@ -211,61 +199,26 @@ jobs:
- name: Load Docker image
run: docker load -i /tmp/docker-image.tar
- name: Install frontend dependencies
working-directory: ./frontend
- name: Install test dependencies
working-directory: ./tests
run: npm ci
- name: Install Playwright Browsers
working-directory: ./frontend
working-directory: ./tests
if: steps.playwright-cache.outputs.cache-hit != 'true'
run: npx playwright install --with-deps chromium
- name: Create Docker network
run: docker network create pocket-id-network
- name: Start Postgres DB
run: |
docker run -d --name pocket-id-db \
--network pocket-id-network \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD=postgres \
-e POSTGRES_DB=pocket-id \
-p 5432:5432 \
postgres:17
- name: Setup and Configure LLDAP Server
run: |
chmod +x ./scripts/tests/setup-lldap.sh
./scripts/tests/setup-lldap.sh
- name: Wait for Postgres to start
run: |
for i in {1..5}; do
if docker exec pocket-id-db pg_isready -U postgres; then
echo "Postgres is ready"
break
fi
echo "Waiting for Postgres..."
sleep 2
done
- name: Run Docker Container with Postgres DB and LDAP
working-directory: ./tests/setup
run: |
docker run -d --name pocket-id-postgres \
--network pocket-id-network \
-p 1411:1411 \
-e APP_ENV=test \
-e DB_PROVIDER=postgres \
-e DB_CONNECTION_STRING=postgresql://postgres:postgres@pocket-id-db:5432/pocket-id \
pocket-id:test
docker logs -f pocket-id-postgres &> /tmp/backend.log &
docker compose -f docker-compose-postgres.yml up -d
docker compose -f docker-compose-postgres.yml logs -f pocket-id &> /tmp/backend.log &
- name: Run Playwright tests
working-directory: ./frontend
working-directory: ./tests
run: npx playwright test
- name: Upload Frontend Test Report
- name: Upload Test Report
uses: actions/upload-artifact@v4
if: always() && github.event.pull_request.head.ref != 'i18n_crowdin'
with:

13
tests/setup/Dockerfile Normal file
View File

@@ -0,0 +1,13 @@
# Modified version of lldap/lldap that seeds lldap with test data
FROM lldap/lldap:2025-05-19
WORKDIR /app
RUN curl -o /bin/lldap-cli https://raw.githubusercontent.com/Zepmann/lldap-cli/e383494b4dd89ae4e028958b268e200fd85a7a64/lldap-cli
COPY seed-lldap.sh .
RUN chmod +x ./seed-lldap.sh /bin/lldap-cli
RUN cp lldap_set_password /bin
ENTRYPOINT /docker-entrypoint.sh run --config-file /data/lldap_config.toml & ./seed-lldap.sh && wait

View File

@@ -0,0 +1,24 @@
# This Docker Compose file is used to set up the environment for the tests.
services:
lldap:
extends:
file: docker-compose.yml
service: lldap
postgres:
image: postgres:17
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=pocket-id
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 5s
retries: 5
pocket-id:
extends:
file: docker-compose.yml
service: pocket-id
depends_on:
postgres:
condition: service_healthy

View File

@@ -0,0 +1,21 @@
# This Docker Compose file is used to set up the environment for the tests.
services:
lldap:
build:
context: .
dockerfile: Dockerfile
environment:
- LLDAP_JWT_SECRET=secret
- LLDAP_LDAP_USER_PASS=admin_password
- LLDAP_LDAP_BASE_DN=dc=pocket-id,dc=org
pocket-id:
image: pocket-id:test
ports:
- "1411:1411"
environment:
- APP_ENV=test
build:
args:
- BUILD_TAGS=e2etest
context: ../..
dockerfile: Dockerfile

View File

@@ -1,26 +1,9 @@
#!/bin/bash
#!/bin/sh
set -e
echo 'deb http://download.opensuse.org/repositories/home:/Masgalor:/LLDAP/xUbuntu_24.04/ /' | sudo tee /etc/apt/sources.list.d/home:Masgalor:LLDAP.list
curl -fsSL https://download.opensuse.org/repositories/home:Masgalor:LLDAP/xUbuntu_24.04/Release.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/home_Masgalor_LLDAP.gpg > /dev/null
sudo apt-get update
sudo apt-get install -y lldap-cli lldap-set-password
echo "Setting up LLDAP container..."
# Run LLDAP container
docker run -d --name lldap \
--network pocket-id-network \
-p 3890:3890 \
-p 17170:17170 \
-e LLDAP_JWT_SECRET=secret \
-e LLDAP_LDAP_USER_PASS=admin_password \
-e LLDAP_LDAP_BASE_DN="dc=pocket-id,dc=org" \
nitnelave/lldap:stable
# Wait for LLDAP to start
for i in {1..15}; do
if curl -s --fail http://localhost:17170/api/healthcheck > /dev/null; then
if curl -s --fail http://localhost:17170/api/healthcheck >/dev/null; then
echo "LLDAP is ready"
break
fi
@@ -48,7 +31,7 @@ lldap-cli user add "testuser1" "testuser1@pocket-id.org" \
-d "Test User 1" \
-f "Test" \
-l "User"
lldap-cli user add "testuser2" "testuser2@pocket-id.org" \
-p "password123" \
-d "Test User 2" \
@@ -76,7 +59,7 @@ for i in {1..3}; do
echo "Failed to add testuser1 to test_group, retrying in 2 seconds..."
sleep 2
fi
if [ $i -eq 3 ]; then
echo "Warning: Could not add testuser1 to test_group after 3 attempts"
fi
@@ -91,10 +74,10 @@ for i in {1..3}; do
echo "Failed to add testuser2 to admin_group, retrying in 2 seconds..."
sleep 2
fi
if [ $i -eq 3 ]; then
echo "Warning: Could not add testuser2 to admin_group after 3 attempts"
fi
done
echo "LLDAP test data setup complete"
echo "LLDAP test data setup complete"