generated from OXID-eSales/module-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Daniil Tkachev
committed
Jan 14, 2025
1 parent
64f42c0
commit bfda36c
Showing
1 changed file
with
27 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,113 +1,29 @@ | ||
#!/bin/bash | ||
|
||
# Colors for output | ||
RED='\033[0;31m' | ||
GREEN='\033[0;32m' | ||
NC='\033[0m' # No Color | ||
|
||
function start_services() { | ||
echo "Starting application services with Docker Compose..." | ||
docker compose up -d | ||
|
||
echo "Waiting for application services to initialize..." | ||
docker compose ps | ||
|
||
echo "Verifying application network..." | ||
network_name=$(docker inspect $(docker compose ps -q) --format '{{range .NetworkSettings.Networks}}{{.NetworkID}}{{end}}' | head -n 1) | ||
if [ -z "$network_name" ]; then | ||
echo -e "${RED}Could not find the application network. Ensure Docker Compose is configured correctly.${NC}" | ||
exit 1 | ||
fi | ||
echo "Application network: $network_name" | ||
} | ||
|
||
function wait_for_application() { | ||
echo "Waiting for application to be ready at http://telecash-module-apache ..." | ||
for i in {1..60}; do | ||
response=$(curl -s -o /dev/null -w "%{http_code}" http://telecash-module-apache ) | ||
if [ "$response" == "200" ]; then | ||
echo -e "${GREEN}Application is ready!${NC}" | ||
return 0 | ||
fi | ||
echo "Waiting for application... (Attempt $i)" | ||
sleep 5 | ||
done | ||
|
||
echo -e "${RED}Application did not become ready within the expected time.${NC}" | ||
debug_application | ||
exit 1 | ||
} | ||
|
||
function setup_cypress() { | ||
echo "Setting up Cypress container..." | ||
docker run -d --name cypress-container \ | ||
--network "$network_name" \ | ||
-v $(pwd)/source:/var/www \ | ||
-e CYPRESS_baseUrl=http://oxideshop.local \ | ||
-e CYPRESS_WORKDIR=/var/www \ | ||
-e CYPRESS_CONFIG=/var/www/cypress.config.js \ | ||
cypress/included:latest | ||
|
||
# Verify if the container is running | ||
if ! docker ps | grep -q cypress-container; then | ||
echo -e "${RED}Cypress container failed to start.${NC}" | ||
debug_application | ||
exit 1 | ||
fi | ||
|
||
echo "Ensuring Cypress container is connected to the application network..." | ||
docker network connect "$network_name" cypress-container || echo "Already connected to the network." | ||
} | ||
|
||
function run_cypress_tests_and_stream_logs() { | ||
echo "Running Cypress tests and streaming logs to GitHub Actions console..." | ||
|
||
docker exec cypress-container npx cypress run --browser chrome --headless --config-file /var/www/cypress.config.js 2>&1 | tee cypress-test-output.log | ||
|
||
if ! grep -q "All specs passed!" cypress-test-output.log; then | ||
echo -e "${RED}Cypress tests failed. Debugging details below:${NC}" | ||
debug_application | ||
exit 1 | ||
fi | ||
|
||
echo -e "${GREEN}All Cypress tests passed successfully!${NC}" | ||
} | ||
|
||
function debug_application() { | ||
echo -e "${RED}Debugging application services and containers:${NC}" | ||
|
||
echo "Docker Compose services status:" | ||
docker compose ps | ||
|
||
echo "Docker Compose logs:" | ||
docker compose logs | ||
|
||
echo "Inspecting network and connectivity:" | ||
echo "Application network: $network_name" | ||
docker inspect "$network_name" | ||
|
||
echo "Testing connectivity from Cypress container to the application:" | ||
if docker ps | grep -q cypress-container; then | ||
docker exec cypress-container curl -I http://oxideshop.local || echo "Cypress container cannot reach http://oxideshop.local." | ||
else | ||
echo "Cypress container is not running." | ||
fi | ||
|
||
echo "Ensuring containers are connected to the application network..." | ||
docker network connect "$network_name" cypress-container || echo "Cypress already connected." | ||
} | ||
|
||
function cleanup() { | ||
echo "Stopping and removing Cypress container..." | ||
docker rm -f cypress-container || echo "Cypress container already removed." | ||
|
||
echo "Stopping Docker Compose services..." | ||
docker compose down || echo "Docker Compose services already stopped." | ||
} | ||
|
||
# Main script execution | ||
start_services | ||
wait_for_application | ||
setup_cypress | ||
run_cypress_tests_and_stream_logs | ||
cleanup | ||
# Update Selenium service ports in docker-compose.yml | ||
sed -i '/selenium:/,/ports:/ {/5900:5900/s/5900:5900/5980:5900/}' docker-compose.yml | ||
|
||
# Add Cypress service under 'services:' in docker-compose.yml | ||
cat <<EOF >> docker-compose.yml | ||
cypress: | ||
image: cypress/included:latest | ||
working_dir: /var/www/extensions/telecash/tests/e2e | ||
volumes: | ||
- ./source/extensions/telecash:/var/www/extensions/telecash:cached | ||
- /tmp/.X11-unix:/tmp/.X11-unix | ||
environment: | ||
- CYPRESS_baseUrl=https://daniil.oxiddev.de | ||
ports: | ||
- "5900:5900" # VNC port | ||
command: cypress open | ||
depends_on: | ||
- apache | ||
entrypoint: [ "npx", "cypress", "run", "--config-file", "/var/www/extensions/telecash/tests/e2e/cypress.config.js" ] | ||
EOF | ||
|
||
# Start Docker containers | ||
docker compose up -d | ||
|
||
# Capture and display Cypress service logs | ||
docker compose logs cypress |