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

Enhancement (ci): Add test for awards and heatmaps #21

Merged
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/ci-master-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
84 changes: 66 additions & 18 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -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: |
Expand All @@ -23,29 +56,16 @@ services:
http://web/trend_graph.php 200
networks:
- default
depends_on:
test-ready:
condition: service_completed_successfully
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

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"
Expand All @@ -56,6 +76,8 @@ services:
done

test-endpoints:
profiles:
- prod
build:
dockerfile_inline: |
FROM alpine:latest
Expand All @@ -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:
Expand All @@ -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"
Expand All @@ -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: