diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 000000000..45fc0d6db --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,47 @@ +name: Test building and runnint dojo +on: push +jobs: + smoketest: + runs-on: ubuntu-latest + timeout-minutes: 23 + steps: + - uses: actions/checkout@v3 + - name: Info gathering + run: | + ls -la /tmp + df -h + + - name: Install test dependencies + run: | + python -m pip install --upgrade pip + pip install pytest + + - name: Build container + run: + docker build -t dojo-test . + + - name: Run Container + run: "docker run --privileged -d -v $PWD:/opt/pwn.college:shared -p 2222:22 -p 80:80 -p 443:443 --name dojo dojo-test" + + - name: Wait for container to be ready + run: | + until docker exec dojo dojo is-setup-finished + do + sleep 5 + docker exec dojo journalctl -u pwn.college | tail -n 5 + done + + - name: Wait for db to be ready + run: | + until docker exec dojo docker exec db mysql -h localhost -u ctfd -pctfd ctfd + do + sleep 5 + docker exec dojo docker logs db | tail -n 5 + done + + - name: Run tests against container + run: | + pytest ./test || (docker exec dojo docker compose logs && false) + + + diff --git a/docker-compose.yml b/docker-compose.yml index 5bbf08b03..43ee9130a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -91,6 +91,8 @@ services: volumes: - ./data/mysql:/var/lib/mysql command: [mysqld, --character-set-server=utf8mb4, --collation-server=utf8mb4_unicode_ci, --wait_timeout=28800, --log-warnings=0] + healthcheck: + test: "mysql -h localhost -u ctfd -pctfd ctfd" cache: container_name: cache diff --git a/script/container-setup.sh b/script/container-setup.sh index 54f8e506b..7380d4c5d 100755 --- a/script/container-setup.sh +++ b/script/container-setup.sh @@ -82,3 +82,4 @@ iptables -I DOCKER-USER -i user_firewall -j DROP for host in $(cat $DOJO_DIR/user_firewall.allowed); do iptables -I DOCKER-USER -i user_firewall -d $(host $host | awk '{print $NF; exit}') -j ACCEPT done + diff --git a/script/dojo b/script/dojo index 4aa9822f4..d7167a808 100755 --- a/script/dojo +++ b/script/dojo @@ -80,6 +80,11 @@ case "$ACTION" in journalctl -u pwn.college -f ;; + # HELP: is-setup-finished: use exit code to return if the system is done with setup + "is-setup-finished") + journalctl -u pwn.college | grep "Finished pwn.college docker compose service" + ;; + # HELP: start: start the dojo. Main entry point for the docker image. "start") dojo sync