Skip to content

Commit 31d43ce

Browse files
Merge pull request #71 from pomo-mondreganto/fixes
Fix some stuff, upgrade deps
2 parents b1fc9e6 + a7b4f1d commit 31d43ce

File tree

93 files changed

+2949
-3994
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+2949
-3994
lines changed

.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
with:
2828
registry: ghcr.io
2929
username: ${{ github.repository_owner }}
30-
password: ${{ secrets.GITHUB_TOKEN }}
30+
password: ${{ github.token }}
3131

3232
- name: Build and push
3333
id: docker_build

.github/workflows/tests.yml

+2-5
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,11 @@ jobs:
1717
tests:
1818
strategy:
1919
matrix:
20-
os:
21-
- ubuntu-20.04
22-
- ubuntu-18.04
2320
test_type:
2421
- BLITZ
2522
- CLASSIC
2623

27-
runs-on: ${{ matrix.os }}
24+
runs-on: "ubuntu-20.04"
2825
timeout-minutes: 15
2926
env:
3027
TEST: 1
@@ -41,7 +38,7 @@ jobs:
4138
- uses: actions/cache@v2
4239
with:
4340
path: ~/.cache/pip
44-
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
41+
key: ${{ runner.os }}-pip-${{ hashFiles('backend/requirements.txt') }}-${{ hashFiles('cli/requirements.txt') }}-${{ hashFiles('tests/requirements.txt') }}
4542
restore-keys: |
4643
${{ runner.os }}-pip-
4744
- name: Setup tests

Makefile

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
.PHONY: lint
2-
lint:
1+
.PHONY: lint-backend
2+
lint-backend:
33
flake8 --config .flake8
44

5+
.PHONY: lint-frontend
6+
lint-frontend:
7+
cd front && npx eslint .
8+
9+
.PHONY: lint
10+
lint: lint-backend lint-frontend
11+
512
.PHONY: clean
613
clean:
714
./control.py reset || :
@@ -23,4 +30,4 @@ release-base:
2330
start: clean
2431
./control.py setup
2532
./control.py start --fast
26-
./control.py rd logs -f inititializer
33+
./control.py rd logs -f initializer

README.md

+12-15
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ statistics, services description, writing a checker, modifying the rating system
5454
images or backend requirements, omit this option to run the full build.
5555

5656
That's all! Now you should be able to access the scoreboard at `http://127.0.0.1:8080/`. Admin panel is accessible at
57-
`http://127.0.0.1:8080/admin`. Celery visualization (flower) is at `http://127.0.0.1:8080/flower`.
57+
`http://127.0.0.1:8080/admin/`. Celery visualization (flower) is at `http://127.0.0.1:8080/flower/`.
5858

5959
> Before each new game run `./control.py reset` to delete old database and temporary files (and docker networks)
6060
@@ -92,7 +92,7 @@ Config file (`config.yml`) is split into five main parts:
9292

9393
* `default_score` (optional, default `2500`): default score for tasks.
9494

95-
* `env_path` (optional, default `/checkers/bin/`): string to append to checkers' `$PATH` environment variable
95+
* `env_path` (optional): string to append to checkers' `$PATH` environment variable
9696
(see [checkers](#checkers) section). Example: `/checkers/bin/`.
9797

9898
* `game_hardness` (optional, default `10`): game hardness parameter
@@ -109,6 +109,8 @@ Config file (`config.yml`) is split into five main parts:
109109
* `username: forcad`
110110
* `password: **change_me**`
111111

112+
It will be auto-generated if missing. Usernames & passwords to all storages will be the same as to the admin panel.
113+
112114
* **teams** contains playing teams. Example contents:
113115

114116
```yaml
@@ -128,7 +130,7 @@ Highlighted teams will be marked on the scoreboard with a rainbow border.
128130
```yaml
129131
tasks:
130132
- checker: collacode/checker.py
131-
checker_type: gevent_pfr
133+
checker_type: pfr
132134
checker_timeout: 30
133135
default_score: 1500
134136
gets: 3
@@ -145,7 +147,7 @@ tasks:
145147
puts: 2
146148
```
147149
148-
* **storages** is an **auto-generated section**, which will be overridden by `control.py setup/kube setup` and describes
150+
* **storages** is an **auto-generated section**, which will be overridden by `control.py <setup>/<kube setup>` and describes
149151
settings used to connect to PostgreSQL, Redis and RabbitMQ:
150152

151153
* `db`: PostgreSQL settings:
@@ -206,7 +208,7 @@ The following options are supported:
206208

207209
* `checker_type` (optional, default `hackerdom`): an option containing underscore-separated tags,
208210
(missing tags are ignored). Examples: `hackerdom` (hackerdom tag ignored, so no modifier tags are applied),
209-
`gevent_pfr` (gevent checker with public flag data returned). Currently, supported tags are:
211+
`pfr` (checker with public flag data returned). Currently, supported tags are:
210212

211213
* `pfr`: checker returns public flag data (e.g. username of flag user) from `PUT` action as a **public message**,
212214
private flag data (`flag_id`) as a **private message**, and **public message** is shown
@@ -217,16 +219,11 @@ The following options are supported:
217219
random generator in checkers so it would return the same values for `GET` and `PUT`. Checkers supporting this
218220
options are quite rare (and old), so **don't use it** unless you're sure.
219221

220-
* `gevent`: an experimental checker type to make checkers faster. **Don't use it** if you're not absolutely sure you
221-
know how it works. **Don't use it** on long and (or) large competitions! Example checker
222-
is [here](tests/service/checker/gevent_checker.py).
223-
224222
More detailed explanation of checker tags can be
225223
found [in this issue](https://github.com/pomo-mondreganto/ForcAD/issues/18#issuecomment-618072993).
226224

227-
* `env_path` (optional, default `/checkers/bin`): path or a combination of paths to be prepended to `PATH` env
228-
variable (e.g. path to chromedriver). By default, `/checkers/bin` is used, so all auxiliary executables can be but
229-
in `checkers/bin`.
225+
* `env_path` (optional): path or a combination of paths to be prepended to `PATH` env
226+
variable (e.g. path to chromedriver).
230227

231228
See more in [checker writing](#writing-a-checker) section.
232229

@@ -236,11 +233,11 @@ See more in [checker writing](#writing-a-checker) section.
236233

237234
```yaml
238235
checkers:
239-
- requirements.txt <-- automatically installed (with pip) combined requirements of all checkers
236+
- requirements.txt <-- automatically installed (with pip) combined requirements of all checkers (must be present)
240237
- task1:
241-
- checker.py <-- executable
238+
- checker.py <-- executable (o+rx)
242239
- task2:
243-
- checker.py <-- executable
240+
- checker.py <-- executable (o+rx)
244241
```
245242

246243
### Writing a checker

backend/lib/config/models.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ class Celery(BaseModel):
3939

4040
worker_prefetch_multiplier: int = 1
4141

42+
result_expires = 15 * 60
4243
redis_socket_timeout: int = 10
4344
redis_socket_keepalive: bool = True
4445
redis_retry_on_timeout: bool = True
4546

46-
accept_content: List[str] = ['pickle']
47+
accept_content: List[str] = ['pickle', 'json']
4748
result_serializer: str = 'pickle'
4849
task_serializer: str = 'pickle'

backend/lib/helpers/__init__.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from . import (
22
cache, checkers, commands,
33
events, exceptions, jobs,
4-
thread_actions, singleton,
4+
singleton,
55
)
66

77
__all__ = (
@@ -11,6 +11,5 @@
1111
'events',
1212
'exceptions',
1313
'jobs',
14-
'thread_actions',
1514
'singleton',
1615
)

backend/lib/helpers/checkers.py

+2-69
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,9 @@
11
from logging import Logger
2-
from typing import Optional, List
2+
from typing import Optional
33

44
from lib import models
55
from lib.helpers.commands import run_generic_command
6-
from lib.helpers.thread_actions import run_generic_action_in_thread
7-
from lib.models import TaskStatus, Action
8-
9-
10-
def first_error_or_first_verdict(
11-
verdicts: List[models.CheckerVerdict],
12-
) -> models.CheckerVerdict:
13-
for verdict in verdicts:
14-
if verdict.status != TaskStatus.UP:
15-
return verdict
16-
17-
return verdicts[0]
6+
from lib.models import Action
187

198

209
class CheckerRunner:
@@ -37,18 +26,12 @@ def __init__(
3726
self.flag = flag
3827

3928
def check(self) -> models.CheckerVerdict:
40-
if self.task.is_checker_gevent_optimized:
41-
return self._check_in_thread()
4229
return self._check_as_process()
4330

4431
def put(self) -> models.CheckerVerdict:
45-
if self.task.is_checker_gevent_optimized:
46-
return self._put_in_thread()
4732
return self._put_as_process()
4833

4934
def get(self) -> models.CheckerVerdict:
50-
if self.task.is_checker_gevent_optimized:
51-
return self._get_in_thread()
5235
return self._get_as_process()
5336

5437
def _check_as_process(self) -> models.CheckerVerdict:
@@ -108,53 +91,3 @@ def _get_as_process(self) -> models.CheckerVerdict:
10891
team=self.team,
10992
logger=self.logger,
11093
)
111-
112-
def _check_in_thread(self) -> models.CheckerVerdict:
113-
"""Check implementation, gevent-compatible"""
114-
115-
return run_generic_action_in_thread(
116-
action=Action.CHECK,
117-
task=self.task,
118-
team=self.team,
119-
logger=self.logger,
120-
action_args=(),
121-
action_kwargs={},
122-
)
123-
124-
def _put_in_thread(self) -> models.CheckerVerdict:
125-
"""Check implementation, gevent-compatible"""
126-
assert self.flag is not None, 'Can only be called when flag is passed'
127-
128-
kwargs = {
129-
'flag_id': self.flag.private_flag_data,
130-
'flag': self.flag.flag,
131-
'vuln': str(self.flag.vuln_number),
132-
}
133-
134-
return run_generic_action_in_thread(
135-
action=Action.PUT,
136-
task=self.task,
137-
team=self.team,
138-
logger=self.logger,
139-
action_args=(),
140-
action_kwargs=kwargs,
141-
)
142-
143-
def _get_in_thread(self) -> models.CheckerVerdict:
144-
"""Check implementation, gevent-compatible"""
145-
assert self.flag is not None, 'Can only be called when flag is passed'
146-
147-
kwargs = {
148-
'flag_id': self.flag.private_flag_data,
149-
'flag': self.flag.flag,
150-
'vuln': str(self.flag.vuln_number),
151-
}
152-
153-
return run_generic_action_in_thread(
154-
action=Action.GET,
155-
task=self.task,
156-
team=self.team,
157-
logger=self.logger,
158-
action_args=(),
159-
action_kwargs=kwargs,
160-
)

backend/lib/helpers/exceptions.py

-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ class FlagSubmitException(Exception):
22
"""Exception for flag validation."""
33

44

5-
class CheckerTimeoutException(BaseException):
6-
"""Exception raised by gevent-optimized checkers."""
7-
8-
95
class FlagExceptionEnum:
106
GAME_NOT_AVAILABLE = FlagSubmitException('Game is not available.')
117
FLAG_INVALID = FlagSubmitException('Flag is invalid or too old.')

backend/lib/helpers/thread_actions.py

-100
This file was deleted.

0 commit comments

Comments
 (0)