From ad2ae89f0d3b7a3520775891e2b96d76614c1624 Mon Sep 17 00:00:00 2001 From: Leonard Jonathan Oh Date: Tue, 31 Oct 2023 15:59:04 +0000 Subject: [PATCH] Enhancement (ci): Add test for `awards` and `heatmaps` --- .github/workflows/ci-master-pr.yml | 4 +- README.md | 9 ++-- docker-compose.test.yml | 84 +++++++++++++++++++++++------- 3 files changed, 74 insertions(+), 23 deletions(-) diff --git a/.github/workflows/ci-master-pr.yml b/.github/workflows/ci-master-pr.yml index af4570ed..bdceed36 100644 --- a/.github/workflows/ci-master-pr.yml +++ b/.github/workflows/ci-master-pr.yml @@ -53,14 +53,14 @@ jobs: run: | set -eux docker compose up --build -d - docker compose -f docker-compose.test.yml up test-routes + docker compose -f docker-compose.test.yml --profile dev up - name: Integration test (prod) if: matrix.testenv == 'prod' run: | set -eux docker compose -f docker-compose.example.yml -f docker-compose.example.build.yml up --build -d - docker compose -f docker-compose.test.yml up + docker compose -f docker-compose.test.yml --profile prod up build: strategy: diff --git a/README.md b/README.md index 8fb6a1fc..8a61c32c 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,9 @@ echo '127.0.0.1 phpmyadmin.example.com' | sudo tee -a /etc/hosts ## Development ```sh +# Setup docker buildx builder +docker buildx create --name mybuilder --driver docker-container --use + # 1. Start Counter-strike 1.6 server, source-udp-forwarder, HLStatsX:CE stack docker compose up --build # HLStatsX:CE web frontend available at http://localhost:8081/. Admin Panel username: admin, password 123456 @@ -132,12 +135,12 @@ docker exec -it $( docker compose ps -q heatmaps) php /heatmaps/generate.php #-- # db - Exec into container docker exec -it $( docker compose ps -q db ) sh -# Test routes -docker compose -f docker-compose.test.yml up test-routes +# Test +docker compose -f docker-compose.test.yml --profile dev up # Test production builds locally docker compose -f docker-compose.example.yml -f docker-compose.example.build.yml up --build -docker compose -f docker-compose.test.yml up +docker compose -f docker-compose.test.yml --profile prod up # Dump the DB docker exec $( docker compose ps -q db ) mysqldump -uroot -proot hlstatsxce | gzip > hlstatsxce.sql.gz diff --git a/docker-compose.test.yml b/docker-compose.test.yml index fa8518af..a975b7c8 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -1,6 +1,39 @@ version: '2.2' services: + test-ready: + profiles: + - dev + - prod + image: alpine:latest + networks: + - default + stop_signal: SIGKILL + entrypoint: + - /bin/sh + command: + - -c + - | + set -eu + + echo "Waiting for stack to be ready" + s=0 + while true; do + nc -vz -w 1 web 80 \ + && nc -vz -w 1 web 9000 \ + && nc -vz -w 1 db 3306 \ + && break || true + s=$$(( $$s + 1 )) + if [ "$$s" -eq 600 ]; then + exit 1 + fi + echo "Retrying in 3 seconds" + sleep 3 + done + test-routes: + profiles: + - dev + - prod image: alpine:latest environment: URLS: | @@ -23,6 +56,9 @@ services: http://web/trend_graph.php 200 networks: - default + depends_on: + test-ready: + condition: service_completed_successfully stop_signal: SIGKILL entrypoint: - /bin/sh @@ -30,22 +66,6 @@ services: - -c - | set -eu - - echo "Waiting for stack to be ready" - s=0 - while true; do - nc -vz -w 1 web 80 \ - && nc -vz -w 1 web 9000 \ - && nc -vz -w 1 db 3306 \ - && break || true - s=$$(( $$s + 1 )) - if [ "$$s" -eq 600 ]; then - exit 1 - fi - echo "Retrying in 3 seconds" - sleep 3 - done - echo "$$URLS" | awk NF | while read -r i j; do if wget -q -SO- "$$i" 2>&1 | grep "HTTP/1.1 $$j " > /dev/null; then echo "PASS: $$i" @@ -56,6 +76,8 @@ services: done test-endpoints: + profiles: + - prod build: dockerfile_inline: | FROM alpine:latest @@ -66,7 +88,7 @@ services: phpmyadmin.example.com 200 network_mode: host depends_on: - test-routes: + test-ready: condition: service_completed_successfully stop_signal: SIGKILL entrypoint: @@ -75,7 +97,6 @@ services: - -c - | set -eu - echo "$$ENDPOINTS" | awk NF | while read -r i j; do if curl --head -kL http://$$i --resolve $$i:80:127.0.0.1 --resolve $$i:443:127.0.0.1 2>&1 | grep "^HTTP/2 $$j " > /dev/null; then echo "PASS: $$i" @@ -85,5 +106,32 @@ services: fi done + test-awards: &test-docker + profiles: + - dev + - prod + image: docker:cli + volumes: + - /var/run/docker.sock:/var/run/docker.sock:ro + - ./:/src:ro + networks: + - default + depends_on: + test-ready: + condition: service_completed_successfully + working_dir: /src + stop_signal: SIGKILL + entrypoint: + - /bin/sh + command: + - -c + - docker exec -i $( docker compose ps -q awards) sh -c /awards.sh + + test-heatmaps: + <<: *test-docker + command: + - -c + - docker exec -i $( docker compose ps -q heatmaps) php /heatmaps/generate.php + networks: default: