-
Notifications
You must be signed in to change notification settings - Fork 100
140 lines (128 loc) · 4.17 KB
/
test.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
name: Integration Test
on:
pull_request:
push:
branches:
- master
schedule:
- cron: '42 06 * * *'
jobs:
test:
name: Integration Test
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Host information
run: |
echo "::group::Host information"
echo "Hostname: $(hostname)"
echo "IP: $(hostname -I)"
echo "::endgroup::"
echo "::group::Filesystem"
df -h
echo "::endgroup::"
echo "::group::Memory"
free -h
echo "::endgroup::"
echo "::group::CPU"
lscpu
echo "::endgroup::"
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
cache: 'pip'
- name: Setup firefox
uses: browser-actions/setup-firefox@latest
- name: Install test dependencies
run: |
pip install \
pytest \
pytest-dependency \
pytest-github-actions-annotate-failures \
requests \
selenium
- name: Make docker cache dir owned by our user
run: |
sudo chown $USER:$USER /mnt
- name: Restore docker data cache
if: github.event_name != 'schedule'
uses: actions/cache/restore@v4
with:
path: |
/mnt/data-docker.tar.gz
key: docker-data-${{ runner.os }}-${{ github.run_id }}
restore-keys: |
docker-data-${{ runner.os }}-
# TEMP: Disable for now, cache holds bad docker network state
# - name: Unpack docker data cache
# if: github.event_name != 'schedule'
# run: |
# if [ -f /mnt/data-docker.tar.gz ]; then
# mkdir -p /mnt/dojo-test-data
# sudo tar --use-compress-program=pigz -xf /mnt/data-docker.tar.gz -C /mnt/dojo-test-data
# fi
- name: Build docker image
if: github.event_name != 'schedule'
uses: docker/build-push-action@v5
with:
context: .
tags: pwncollege/dojo:test
load: true
cache-from: type=gha
- name: Build and cache docker image
if: github.event_name == 'schedule'
uses: docker/build-push-action@v5
with:
context: .
tags: pwncollege/dojo:test
load: true
cache-to: type=gha
- name: Run dojo
run: |
docker run \
--name dojo-test \
--privileged \
--detach \
--rm \
-v "/mnt/dojo-test-data:/data:shared" \
-p 2222:22 -p 80:80 -p 443:443 \
pwncollege/dojo:test
- name: Build and start services
run: |
docker exec dojo-test dojo wait || (docker exec dojo-test dojo compose logs && false)
docker exec dojo-test docker tag pwncollege-challenge pwncollege/challenge-legacy:latest
docker exec dojo-test docker image ls
- name: Wait for services to start
timeout-minutes: 3
run: |
docker exec dojo-test dojo compose logs -f &
log_pid=$!
until [[ "$(docker exec dojo-test docker inspect --format='{{.State.Health.Status}}' ctfd)" == "healthy" ]]; do
sleep 1
done
kill $log_pid
exit 0
- name: Run tests
timeout-minutes: 4
run: |
export MOZ_HEADLESS=1
timeout 3m pytest -vrpP --durations=0 ./test || (docker exec dojo-test dojo compose logs && false)
- name: Pack docker data cache
if: github.event_name == 'schedule'
run: |
docker exec dojo-test dojo compose down
sudo tar --use-compress-program=pigz -cf /mnt/data-docker.tar.gz -C /mnt/dojo-test-data ./docker
- name: Save docker data cache
if: github.event_name == 'schedule'
uses: actions/cache/save@v4
with:
path: |
/mnt/data-docker.tar.gz
key: docker-data-${{ runner.os }}-${{ github.run_id }}
- name: Final filesystem information
run: |
echo "::group::Filesystem"
df -h
echo "::endgroup::"