diff --git a/.flake8 b/.flake8 index 1273f0ea..db42e839 100644 --- a/.flake8 +++ b/.flake8 @@ -1,4 +1,4 @@ [flake8] max_line_length = 88 -exclude = .git,front,docker_config,tests +exclude = .git,front,docker_config,tests,checkers ignore = E402 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 76f065c0..7991ac17 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -27,7 +27,7 @@ jobs: with: registry: ghcr.io username: ${{ github.repository_owner }} - password: ${{ secrets.CR_PAT }} + password: ${{ secrets.GITHUB_TOKEN }} - name: Build and push id: docker_build diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 78787084..8db1fa61 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -37,7 +37,7 @@ jobs: - name: Setup python uses: actions/setup-python@v2 with: - python-version: '3.7' + python-version: '3.9' - uses: actions/cache@v2 with: path: ~/.cache/pip @@ -80,7 +80,7 @@ jobs: - name: Setup python uses: actions/setup-python@v2 with: - python-version: '3.7' + python-version: '3.9' - name: Install dependencies run: pip install flake8 - name: Run linters @@ -119,7 +119,7 @@ jobs: - name: Setup python uses: actions/setup-python@v2 with: - python-version: '3.7' + python-version: '3.9' - name: Install skaffold run: | curl -Lo skaffold https://storage.googleapis.com/skaffold/releases/v1.19.0/skaffold-linux-amd64 diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..0dc0690c --- /dev/null +++ b/Makefile @@ -0,0 +1,26 @@ +.PHONY: lint +lint: + flake8 --config .flake8 + +.PHONY: clean +clean: + ./control.py reset || : + ./control.py clean + +.PHONY: test +test: clean + ./scripts/run_tests.sh + +.PHONY: build-base +build-base: + ./scripts/release_base.sh + +.PHONY: release-base +release-base: + ./scripts/release_base.sh --push + +.PHONY: start +start: clean + ./control.py setup + ./control.py start --fast + ./control.py rd logs -f inititializer diff --git a/backend/lib/storage/game.py b/backend/lib/storage/game.py index b500e318..e3beec15 100644 --- a/backend/lib/storage/game.py +++ b/backend/lib/storage/game.py @@ -107,6 +107,14 @@ def construct_game_state_from_db(current_round: int) -> models.GameState: teamtasks = storage.tasks.get_teamtasks_from_db() teamtasks = storage.tasks.filter_teamtasks_for_participants(teamtasks) + team_ids = {team.id for team in storage.teams.get_teams()} + task_ids = {task.id for task in storage.tasks.get_tasks()} + + teamtasks = list(filter( + lambda tt: tt['team_id'] in team_ids and tt['task_id'] in task_ids, + teamtasks, + )) + round_start = get_round_start(current_round) state = models.GameState( round_start=round_start, diff --git a/backend/requirements.txt b/backend/requirements.txt index 2aceb048..4c4b11bc 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -1,19 +1,43 @@ +amqp==5.0.6 +bidict==0.21.2 +billiard==3.6.4.0 celery==5.0.5 -eventlet==0.30.1 +certifi==2020.12.5 +click==7.1.2 +click-didyoumean==0.0.3 +click-plugins==1.1.1 +click-repl==0.1.6 +dnspython==1.16.0 +eventlet==0.30.2 Flask==1.1.2 Flask-Cors==3.0.10 Flask-SocketIO==5.0.1 --e git://github.com/avikam/flower@9aade51671a2c1f0c1d0c1c81c7ca9bb49837f83#egg=flower +flower @ https://github.com/mher/flower/zipball/master gevent==21.1.2 -gunicorn==20.0.4 -hiredis==1.1.0 -librabbitmq==2.0.0 +greenlet==1.1.0 +gunicorn==20.1.0 +hiredis==2.0.0 +humanize==3.5.0 +itsdangerous==1.1.0 +Jinja2==2.11.3 kombu==5.0.2 +librabbitmq==2.0.0 +MarkupSafe==1.1.1 prometheus-client==0.8.0 -pydantic==1.7.3 +prompt-toolkit==3.0.18 +psycopg2==2.8.6 +pydantic==1.8.1 python-dateutil==2.8.1 -python-socketio==5.0.4 +python-engineio==4.1.0 +python-socketio==5.2.1 pytz==2021.1 PyYAML==5.4.1 -psycopg2==2.8.6 redis==3.5.3 +six==1.16.0 +tornado==6.1 +typing-extensions==3.10.0.0 +vine==5.0.0 +wcwidth==0.2.5 +Werkzeug==1.0.1 +zope.event==4.5.0 +zope.interface==5.4.0 diff --git a/backend/services/admin/viewsets/teamtasks.py b/backend/services/admin/viewsets/teamtasks.py index 772f6427..12e92f07 100644 --- a/backend/services/admin/viewsets/teamtasks.py +++ b/backend/services/admin/viewsets/teamtasks.py @@ -11,8 +11,8 @@ class TeamTaskApi(ApiSet): @staticmethod def list(): try: - team_id = int(request.args['team_id'][0]) - task_id = int(request.args['task_id'][0]) + team_id = int(request.args['team_id']) + task_id = int(request.args['task_id']) except (KeyError, ValueError): return make_err_response( 'Provide team_id and task_id as get params', diff --git a/cli/base/reset.py b/cli/base/reset.py index 5ed64bec..b7e3e0ef 100644 --- a/cli/base/reset.py +++ b/cli/base/reset.py @@ -3,12 +3,10 @@ import click from cli import constants, utils -from cli.base.clean import clean @click.command(help='Reset the game & clean up') -@click.pass_context -def reset(ctx: click.Context): +def reset(): utils.print_bold('Trying to wipe the database') command = [ 'docker-compose', @@ -31,8 +29,4 @@ def reset(ctx: click.Context): '--remove-orphans', ] utils.run_command(command, cwd=constants.BASE_DIR) - - utils.print_bold('Running clean') - ctx.invoke(clean) - utils.print_success('Done!') diff --git a/cli/base/setup.py b/cli/base/setup.py index 55b2bd16..020963e2 100644 --- a/cli/base/setup.py +++ b/cli/base/setup.py @@ -34,6 +34,7 @@ def setup_db(config: models.DatabaseConfig): f'POSTGRES_DB={config.dbname}', ] + utils.print_bold(f'Writing database env to {constants.POSTGRES_ENV_PATH}') constants.POSTGRES_ENV_PATH.write_text('\n'.join(postgres_config)) @@ -45,6 +46,7 @@ def setup_redis(config: models.RedisConfig): f'REDIS_PASSWORD={config.password}', ] + utils.print_bold(f'Writing redis env to {constants.REDIS_ENV_PATH}') constants.REDIS_ENV_PATH.write_text('\n'.join(redis_config)) @@ -58,6 +60,7 @@ def setup_rabbitmq(config: models.RabbitMQConfig): f'RABBITMQ_DEFAULT_VHOST={config.vhost}', ] + utils.print_bold(f'Writing broker env to {constants.RABBITMQ_ENV_PATH}') constants.RABBITMQ_ENV_PATH.write_text('\n'.join(rabbitmq_config)) @@ -68,6 +71,7 @@ def setup_admin_api(config: models.AdminConfig): f'ADMIN_PASSWORD={config.password}', ] + utils.print_bold(f'Writing admin env to {constants.ADMIN_ENV_PATH}') constants.ADMIN_ENV_PATH.write_text('\n'.join(admin_config)) @@ -85,5 +89,6 @@ def prepare_compose(redis: str = None, database: str = None, rabbitmq: str = Non del base_conf['services']['rabbitmq'] res_path = constants.BASE_DIR / constants.BASE_COMPOSE_FILE + utils.print_bold(f'Writing generated compose base to {res_path}') with res_path.open(mode='w') as f: yaml.dump(base_conf, f) diff --git a/cli/kube/__init__.py b/cli/kube/__init__.py index b48bf5fc..72d3149e 100644 --- a/cli/kube/__init__.py +++ b/cli/kube/__init__.py @@ -16,7 +16,7 @@ def cli(): pass -cli: click.Group +cli: click.Group # noqa cli.add_command(build) cli.add_command(clean) cli.add_command(create) diff --git a/docker_config/base_images/backend.Dockerfile b/docker_config/base_images/backend.Dockerfile index 44f15d0c..aa7ded25 100644 --- a/docker_config/base_images/backend.Dockerfile +++ b/docker_config/base_images/backend.Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.7 +FROM python:3.9 ENV PYTHONUNBUFFERED=1 ENV PYTHONPATH=${PYTHONPATH}:/app diff --git a/docker_config/celery/Dockerfile b/docker_config/celery/Dockerfile index d218f25e..8d50def8 100644 --- a/docker_config/celery/Dockerfile +++ b/docker_config/celery/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.7 +FROM python:3.9 ENV PYTHONUNBUFFERED=1 ENV PYTHONPATH=${PYTHONPATH}:/app diff --git a/docker_config/initializer/Dockerfile b/docker_config/initializer/Dockerfile index e09e74e5..839678e5 100644 --- a/docker_config/initializer/Dockerfile +++ b/docker_config/initializer/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.7 +FROM python:3.9 ENV PYTHONUNBUFFERED=1 ENV PYTHONPATH=${PYTHONPATH}:/app diff --git a/docker_config/services/Dockerfile b/docker_config/services/Dockerfile index 2db0582b..95653190 100644 --- a/docker_config/services/Dockerfile +++ b/docker_config/services/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.7 +FROM python:3.9 ENV PYTHONUNBUFFERED=1 ENV PYTHONPATH=${PYTHONPATH}:/app diff --git a/scripts/run_tests.sh b/scripts/run_tests.sh index c43e3b9e..2e4aa74a 100755 --- a/scripts/run_tests.sh +++ b/scripts/run_tests.sh @@ -4,6 +4,7 @@ export TEST=1 python tests/setup_forcad.py ./control.py setup +# shellcheck disable=SC2038,SC2046 export $(find ./docker_config -name "*.env" -exec egrep -v '^#' {} \; | xargs) ./control.py reset ./control.py build diff --git a/tests/service/Dockerfile b/tests/service/Dockerfile index 8c922bd5..8f4fa81b 100644 --- a/tests/service/Dockerfile +++ b/tests/service/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.7 +FROM python:3.9 ENV PYTHONUNBUFFERED=1