Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add e2e tests #3054

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 71 additions & 3 deletions .github/workflows/test-pr-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,40 @@ jobs:
DOCKER_BUILDKIT=1 docker compose \
--project-directory . \
-f tests/e2e_tests/docker-compose-e2e-${{ matrix.db_type }}.yml up -d

docker ps

- name: Wait for database to be ready
run: |
# Add commands to wait for the database to be ready
echo "Waiting for Database to be ready..."
if [ "${{ matrix.db_type }}" == "mysql" ]; then
until docker exec $(docker ps -qf "name=keep-database") mysqladmin ping -h "localhost" --silent; do
until docker exec $(docker ps -qf "name=keep-database-1") mysqladmin ping -h "localhost" --silent; do
echo "Waiting for MySQL to be ready..."
sleep 2
done
elif [ "${{ matrix.db_type }}" == "postgres" ]; then
until docker exec $(docker ps -qf "name=keep-database") pg_isready -h localhost -U keepuser; do
until docker exec $(docker ps -qf "name=keep-database-1") pg_isready -h localhost -U keepuser; do
echo "Waiting for Postgres to be ready..."
sleep 2
done
fi
echo "Database is ready!"

echo "Waiting for Database (DB AUTH) to be ready..."
if [ "${{ matrix.db_type }}" == "mysql" ]; then
until docker exec $(docker ps -qf "name=keep-database-db-auth-1") mysqladmin ping -h "localhost" --silent; do
echo "Waiting for MySQL (DB AUTH) to be ready..."
sleep 2
done
elif [ "${{ matrix.db_type }}" == "postgres" ]; then
until docker exec $(docker ps -qf "name=keep-database-db-auth-1") pg_isready -h localhost -U keepuser; do
echo "Waiting for Postgres (DB AUTH) to be ready..."
sleep 2
done
fi
echo "Database (DB AUTH) is ready!"


# wait to keep backend on port 8080
echo "Waiting for Keep backend to be ready..."
Expand All @@ -118,9 +137,24 @@ jobs:
attempt=$((attempt+1))
sleep 2
done

echo "Keep backend is ready!"

attempt=0
max_attempts=10
echo "Waiting for Keep backend (DB AUTH) to be ready..."
until $(curl --output /dev/null --silent --fail http://localhost:8081/healthcheck); do
if [ "$attempt" -ge "$max_attempts" ]; then
echo "Max attempts reached, exiting... Sometimes Keep can't start because of double-headed migrations, use: 'alembic -c keep/alembic.ini history' to investigate, or check artifacts."
exit 1
fi
echo "Waiting for Keep backend (DB AUTH) to be ready... (Attempt: $((attempt+1)))"
attempt=$((attempt+1))
sleep 2
done
echo "Keep backend (DB AUTH) is ready!"
# wait to the backend


echo "Waiting for Keep frontend to be ready..."
attempt=0
max_attempts=10
Expand All @@ -134,6 +168,36 @@ jobs:
attempt=$((attempt+1))
sleep 2
done
echo "Keep frontend is ready"

echo "Waiting for Keep frontend (DB AUTH) to be ready..."
attempt=0
max_attempts=10
until $(curl --output /dev/null --silent --fail http://localhost:3001/); do
if [ "$attempt" -ge "$max_attempts" ]; then
echo "Max attempts reached, exiting..."
exit 1
fi
echo "Waiting for Keep frontend (DB AUTH) to be ready... (Attempt: $((attempt+1)))"
attempt=$((attempt+1))
sleep 2
done
echo "Keep frontend (DB AUTH) is ready"


echo "Waiting for Grafana to be ready..."
attempt=0
max_attempts=10
until $(curl --output /dev/null --silent --fail http://localhost:3002/api/health); do
if [ "$attempt" -ge "$max_attempts" ]; then
echo "Max attempts reached, exiting... "
exit 1
fi
echo "Waiting for Grafana to be ready... (Attempt: $((attempt+1)))"
attempt=$((attempt+1))
sleep 2
done
echo "Grafana is ready..."

# create the state directory
# mkdir -p ./state && chown -R root:root ./state && chmod -R 777 ./state
Expand All @@ -157,6 +221,8 @@ jobs:
run: |
docker compose --project-directory . -f tests/e2e_tests/docker-compose-e2e-${{ matrix.db_type }}.yml logs keep-backend > backend_logs-${{ matrix.db_type }}.txt
docker compose --project-directory . -f tests/e2e_tests/docker-compose-e2e-${{ matrix.db_type }}.yml logs keep-frontend > frontend_logs-${{ matrix.db_type }}.txt
docker compose --project-directory . -f tests/e2e_tests/docker-compose-e2e-${{ matrix.db_type }}.yml logs keep-backend-db-auth > backend_logs-${{ matrix.db_type }}-db-auth.txt
docker compose --project-directory . -f tests/e2e_tests/docker-compose-e2e-${{ matrix.db_type }}.yml logs keep-frontend-db-auth > frontend_logs-${{ matrix.db_type }}-db-auth.txt
continue-on-error: true

- name: Upload test artifacts on failure
Expand All @@ -169,6 +235,8 @@ jobs:
playwright_dump_*.png
backend_logs-${{ matrix.db_type }}.txt
frontend_logs-${{ matrix.db_type }}.txt
backend_logs-${{ matrix.db_type }}-db-auth.txt
frontend_logs-${{ matrix.db_type }}-db-auth.txt
continue-on-error: true

- name: Tear down environment
Expand Down
94 changes: 94 additions & 0 deletions tests/e2e_tests/docker-compose-e2e-mysql.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
services:
## Keep Services with NO_AUTH
# Database Service
keep-database:
image: mysql:latest
environment:
Expand All @@ -14,6 +16,7 @@ services:
timeout: 5s
retries: 5

# Frontend Services
keep-frontend:
extends:
file: docker-compose.common.yml
Expand All @@ -28,6 +31,7 @@ services:
- FRIGADE_DISABLED=true
- SENTRY_DISABLED=true

# Backend Services
keep-backend:
extends:
file: docker-compose.common.yml
Expand All @@ -46,6 +50,81 @@ services:
keep-database:
condition: service_healthy


## Keep Services with DB
# Database Service (5433)
keep-database-db-auth:
image: mysql:latest
environment:
- MYSQL_ROOT_PASSWORD=keep
- MYSQL_DATABASE=keep
volumes:
- mysql-data:/var/lib/mysql-auth-db
ports:
- "3307:3306"
healthcheck:
test: ["CMD-SHELL", "mysqladmin ping -h localhost"]
interval: 10s
timeout: 5s
retries: 5

# Frontend Services (3001)
keep-frontend-db-auth:
build:
context: ./keep-ui/
dockerfile: ../docker/Dockerfile.ui
ports:
- "3001:3000"
environment:
- NEXTAUTH_SECRET=secret
- NEXTAUTH_URL=http://localhost:3001
- NEXT_PUBLIC_API_URL=http://localhost:8081
- POSTHOG_KEY=phc_muk9qE3TfZsX3SZ9XxX52kCGJBclrjhkP9JxAQcm1PZ
- POSTHOG_HOST=https://ingest.keephq.dev
- NEXT_PUBLIC_SENTRY_DSN=https://0d4d59e3105ffe8afa27dcb95a222009@o4505515398922240.ingest.us.sentry.io/4508258058764288
- PUSHER_HOST=localhost
- PUSHER_PORT=6001
- PUSHER_APP_KEY=keepappkey
- NEXT_PUBLIC_KEEP_VERSION=0.2.9
- AUTH_TYPE=DB
- API_URL=http://keep-backend-db-auth:8080
- POSTHOG_DISABLED=true
- FRIGADE_DISABLED=true
- SENTRY_DISABLED=true

# Backend Services (8081)
keep-backend-db-auth:
build:
context: .
dockerfile: docker/Dockerfile.api
ports:
- "8081:8080"
environment:
- PORT=8080
- SECRET_MANAGER_TYPE=FILE
- SECRET_MANAGER_DIRECTORY=/state
- OPENAI_API_KEY=$OPENAI_API_KEY
- PUSHER_APP_ID=1
- PUSHER_APP_KEY=keepappkey
- PUSHER_APP_SECRET=keepappsecret
- PUSHER_HOST=keep-websocket-server
- PUSHER_PORT=6001
- USE_NGROK=false
- AUTH_TYPE=DB
- DATABASE_CONNECTION_STRING=mysql+pymysql://root:keep@keep-database-db-auth:3306/keep
- POSTHOG_DISABLED=true
- FRIGADE_DISABLED=true
- SECRET_MANAGER_DIRECTORY=/app
- SQLALCHEMY_WARN_20=1
- KEEP_JWT_SECRET=verysecretkey
- KEEP_DEFAULT_USERNAME=keep
- KEEP_DEFAULT_PASSWORD=keep
depends_on:
keep-database-db-auth:
condition: service_healthy


# Other Services (Common)
keep-websocket-server:
extends:
file: docker-compose.common.yml
Expand All @@ -59,5 +138,20 @@ services:
ports:
- "9090:9090"

grafana:
image: grafana/grafana-enterprise:10.4.0
user: "472" # Grafana's default user ID
ports:
- "3002:3000"
volumes:
- ./keep/providers/grafana_provider/grafana/provisioning:/etc/grafana/provisioning:ro
- ./keep/providers/grafana_provider/grafana/grafana.ini:/etc/grafana/grafana.ini:ro
- grafana-storage:/var/lib/grafana
environment:
- GF_SECURITY_ADMIN_PASSWORD=admin
depends_on:
- prometheus-server-for-test-target

volumes:
mysql-data:
grafana-storage: {}
91 changes: 91 additions & 0 deletions tests/e2e_tests/docker-compose-e2e-postgres.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
services:
## Keep Services with NO_AUTH
# Database Service
keep-database:
image: postgres:13
environment:
Expand All @@ -12,6 +14,7 @@ services:
- ./postgres-custom.conf:/etc/postgresql/conf.d/custom.conf
- ./docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d

# Frontend Services
keep-frontend:
extends:
file: docker-compose.common.yml
Expand All @@ -26,6 +29,7 @@ services:
- FRIGADE_DISABLED=true
- SENTRY_DISABLED=true

# Backend Services
keep-backend:
extends:
file: docker-compose.common.yml
Expand All @@ -43,6 +47,78 @@ services:
depends_on:
- keep-database


## Keep Services with DB
# Database Service (5433)
keep-database-db-auth:
image: postgres:13
environment:
POSTGRES_USER: keepuser
POSTGRES_PASSWORD: keeppassword
POSTGRES_DB: keepdb
ports:
- "5433:5432"
volumes:
- postgres-data:/var/lib/postgresql-auth-db/data
- ./postgres-custom.conf:/etc/postgresql-auth-db/conf.d/custom.conf
- ./docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d

# Frontend Services (3001)
keep-frontend-db-auth:
build:
context: ./keep-ui/
dockerfile: ../docker/Dockerfile.ui
ports:
- "3001:3000"
environment:
- NEXTAUTH_SECRET=secret
- NEXTAUTH_URL=http://localhost:3001
- NEXT_PUBLIC_API_URL=http://localhost:8081
- POSTHOG_KEY=phc_muk9qE3TfZsX3SZ9XxX52kCGJBclrjhkP9JxAQcm1PZ
- POSTHOG_HOST=https://ingest.keephq.dev
- NEXT_PUBLIC_SENTRY_DSN=https://0d4d59e3105ffe8afa27dcb95a222009@o4505515398922240.ingest.us.sentry.io/4508258058764288
- PUSHER_HOST=localhost
- PUSHER_PORT=6001
- PUSHER_APP_KEY=keepappkey
- NEXT_PUBLIC_KEEP_VERSION=0.2.9
- AUTH_TYPE=DB
- API_URL=http://keep-backend-db-auth:8080
- POSTHOG_DISABLED=true
- FRIGADE_DISABLED=true
- SENTRY_DISABLED=true

# Backend Services (8081)
keep-backend-db-auth:
build:
context: .
dockerfile: docker/Dockerfile.api
ports:
- "8081:8080"
environment:
- PORT=8080
- SECRET_MANAGER_TYPE=FILE
- SECRET_MANAGER_DIRECTORY=/state
- OPENAI_API_KEY=$OPENAI_API_KEY
- PUSHER_APP_ID=1
- PUSHER_APP_KEY=keepappkey
- PUSHER_APP_SECRET=keepappsecret
- PUSHER_HOST=keep-websocket-server
- PUSHER_PORT=6001
- USE_NGROK=false
- AUTH_TYPE=DB
- DATABASE_CONNECTION_STRING=postgresql+psycopg2://keepuser:keeppassword@keep-database-db-auth:5432/keepdb
- POSTHOG_DISABLED=true
- FRIGADE_DISABLED=true
- SECRET_MANAGER_DIRECTORY=/app
- SQLALCHEMY_WARN_20=1
- KEEP_JWT_SECRET=verysecretkey
- KEEP_DEFAULT_USERNAME=keep
- KEEP_DEFAULT_PASSWORD=keep
depends_on:
- keep-database-db-auth


# Other Services (Common)
keep-websocket-server:
extends:
file: docker-compose.common.yml
Expand All @@ -56,5 +132,20 @@ services:
ports:
- "9090:9090"

grafana:
image: grafana/grafana-enterprise:10.4.0
user: "472" # Grafana's default user ID
ports:
- "3002:3000"
volumes:
- ./keep/providers/grafana_provider/grafana/provisioning:/etc/grafana/provisioning:ro
- ./keep/providers/grafana_provider/grafana/grafana.ini:/etc/grafana/grafana.ini:ro
- grafana-storage:/var/lib/grafana
environment:
- GF_SECURITY_ADMIN_PASSWORD=admin
depends_on:
- prometheus-server-for-test-target

volumes:
postgres-data:
grafana-storage: {}
Loading
Loading