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

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

83
tests/setup/seed-lldap.sh Normal file
View File

@@ -0,0 +1,83 @@
#!/bin/sh
set -e
# Wait for LLDAP to start
for i in {1..15}; do
if curl -s --fail http://localhost:17170/api/healthcheck >/dev/null; then
echo "LLDAP is ready"
break
fi
if [ $i -eq 15 ]; then
echo "LLDAP failed to start in time"
exit 1
fi
echo "Waiting for LLDAP... ($i/15)"
sleep 3
done
echo "LLDAP container setup complete"
echo "Setting up LLDAP test data..."
# Configure LLDAP CLI connection via environment variables
export LLDAP_HTTPURL="http://localhost:17170"
export LLDAP_USERNAME="admin"
export LLDAP_PASSWORD="admin_password"
# Create test users using the user add command
echo "Creating test users..."
lldap-cli user add "testuser1" "testuser1@pocket-id.org" \
-p "password123" \
-d "Test User 1" \
-f "Test" \
-l "User"
lldap-cli user add "testuser2" "testuser2@pocket-id.org" \
-p "password123" \
-d "Test User 2" \
-f "Test2" \
-l "User2"
# Create test groups
echo "Creating test groups..."
lldap-cli group add "test_group"
sleep 1
lldap-cli group update set "test_group" "display_name" "test_group"
lldap-cli group add "admin_group"
sleep 1
lldap-cli group update set "admin_group" "display_name" "admin_group"
# Add users to groups with retry logic
echo "Adding users to groups..."
for i in {1..3}; do
echo "Attempt $i to add testuser1 to test_group"
if lldap-cli user group add "testuser1" "test_group"; then
echo "Successfully added testuser1 to test_group"
break
else
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
done
for i in {1..3}; do
echo "Attempt $i to add testuser2 to admin_group"
if lldap-cli user group add "testuser2" "admin_group"; then
echo "Successfully added testuser2 to admin_group"
break
else
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"