Skip to content

Commit

Permalink
Implement a CI system. Initial test. (#208)
Browse files Browse the repository at this point in the history
* Implement a CI system. Initial test.

* Add a health check to the db

* Add a timeout to the whole thing so it doesn't eat up CPU forever

Fixes #126.
  • Loading branch information
adamdoupe authored Sep 2, 2023
1 parent 50cda93 commit f77cc23
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions script/container-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

5 changes: 5 additions & 0 deletions script/dojo
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f77cc23

Please sign in to comment.