diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..965ff51 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +**/** +!requirements.txt diff --git a/.editorconfig b/.editorconfig index 8ab64ef..e49e180 100644 --- a/.editorconfig +++ b/.editorconfig @@ -9,3 +9,6 @@ end_of_line = lf indent_style = space insert_final_newline = true indent_size = 2 + +[*.py] +indent_size = 4 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..a071712 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,26 @@ +name: test + +on: + push: + pull_request: + +permissions: + contents: read + +jobs: + test-schemas: + runs-on: ubuntu-latest + name: Test if schemas were generated + steps: + - uses: actions/checkout@v4 + + - uses: isbang/compose-action@v1.5.1 + with: + up-flags: "--build" + down-flags: "--volumes" + + - name: Generate images + run: docker exec -i ship-it-boardgame-renderer-1 python render.py + + - name: Verify diff + run: git diff --exit-code diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..83d9c8a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM python:3.12-alpine + +WORKDIR /app + +COPY . . + +RUN pip install --no-cache-dir -r requirements.txt + +CMD [ "sleep", "infinity" ] diff --git a/README.md b/README.md index e80ed6e..2ea16a8 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,20 @@ Thanks a lot to my friends, who helped me with ideas, testing, and rules. Please, add yourself to `AUTHORS` if you contributed in anyway :) +## Render Schemas Locally + +To render the schemas locally you just need a working [Docker](https://www.docker.com) installation: +```shell +# Run required services to render +docker compose up -d + +# Tells our renderer service to render everything +docker exec -it ship-it-boardgame-renderer-1 python render.py + +# Teardown the renderer environment +docker compose down --remove-orphans +``` + ## LICENSE [CC BY-NC-SA 4.0](https://github.com/sobolevn/ship-it-boardgame/blob/master/LICENSE) diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..17be78f --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,20 @@ +version: '3' +services: + renderer: + build: + dockerfile: Dockerfile + depends_on: + image-export: + condition: service_healthy + volumes: + - "./render.py:/app/render.py" + - "./ru:/app/ru" + image-export: + image: jgraph/export-server + healthcheck: + test: [ "CMD-SHELL", "if [ $(curl -o /dev/null -s -w '%{http_code}\n' http://localhost:8000) -ne '400' ]; then exit 1; fi;" ] + interval: 2s + timeout: 5s + retries: 5 + ports: + - "8000:8000" diff --git a/render.py b/render.py new file mode 100644 index 0000000..9f5c20b --- /dev/null +++ b/render.py @@ -0,0 +1,52 @@ +import shutil +import logging +from typing import Final + +import yaml +import requests +from jinja2 import Environment, FileSystemLoader, select_autoescape + +logging.basicConfig( + format='%(asctime)s %(message)s', + datefmt='%Y-%m-%d %H:%M:%S', + level=logging.INFO, +) +logger = logging.getLogger(__name__) + +# Add your language folder below when it's ready to be rendered +LANGUAGE_FOLDERS: Final = {'ru'} + + +def render_schemas(language: str) -> None: + logger.info('[%s] rendering language', language) + + with open(f'{language}/schemas-info.yml') as f: + info = yaml.safe_load(f) + + for template_name in env.list_templates(): + logger.info('[%s] rendering template "%s"', language, template_name) + + rendered = env.get_template(template_name).render(**info) + + logger.info('[%s] generating schema image from template', language) + response = requests.post( + 'http://image-export:8000/', + json={'format': 'jpg', 'xml': rendered}, + stream=True, + ) + assert response.status_code == 200, response.text + + image_name, *_ = template_name.split('.') + logger.info('[%s] saving image %s.jpg', language, image_name) + with open(f'{language}/schemas/{image_name}.jpg', 'wb') as f: + shutil.copyfileobj(response.raw, f) + + +if __name__ == '__main__': + env = Environment( + loader=FileSystemLoader('ru/schema-sources'), + autoescape=select_autoescape(), + ) + + for language in LANGUAGE_FOLDERS: + render_schemas(language) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..d1cc6f0 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,8 @@ +certifi==2024.2.2 +charset-normalizer==3.3.2 +idna==3.6 +Jinja2==3.1.3 +MarkupSafe==2.1.5 +PyYAML==6.0.1 +requests==2.31.0 +urllib3==2.2.1 diff --git a/ru/schema-sources/atack1-1.drawio b/ru/schema-sources/atack1-1.drawio index e72d1cf..9d68f5a 100644 --- a/ru/schema-sources/atack1-1.drawio +++ b/ru/schema-sources/atack1-1.drawio @@ -4,43 +4,43 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -49,10 +49,10 @@ - + - + diff --git a/ru/schema-sources/atack1-2.drawio b/ru/schema-sources/atack1-2.drawio index 8cf26bd..b286541 100644 --- a/ru/schema-sources/atack1-2.drawio +++ b/ru/schema-sources/atack1-2.drawio @@ -4,46 +4,46 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + diff --git a/ru/schema-sources/atack1.drawio b/ru/schema-sources/atack1.drawio index 7de7cc9..a56a50e 100644 --- a/ru/schema-sources/atack1.drawio +++ b/ru/schema-sources/atack1.drawio @@ -4,43 +4,43 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + diff --git a/ru/schema-sources/card.drawio b/ru/schema-sources/card.drawio index 80bbe37..f7d23d1 100644 --- a/ru/schema-sources/card.drawio +++ b/ru/schema-sources/card.drawio @@ -21,7 +21,7 @@ - + @@ -38,7 +38,7 @@ - + @@ -46,13 +46,13 @@ - + - + - + @@ -64,7 +64,7 @@ - + @@ -76,10 +76,10 @@ - + - + diff --git a/ru/schema-sources/game-process.drawio b/ru/schema-sources/game-process.drawio index 7e666f6..637bdfb 100644 --- a/ru/schema-sources/game-process.drawio +++ b/ru/schema-sources/game-process.drawio @@ -4,40 +4,40 @@ - + - + - + - + - + - + - + - + - + - + @@ -46,19 +46,19 @@ - + - + - + - + - + @@ -67,49 +67,49 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + diff --git a/ru/schemas-info.yml b/ru/schemas-info.yml new file mode 100644 index 0000000..9799ad0 --- /dev/null +++ b/ru/schemas-info.yml @@ -0,0 +1,62 @@ +card: + architecture: + name: Архитектура + attack: + name: Атака + types: + error: Ошибка + component: + name: Компонент + types: + backend: Бекенд + frontend: Фронтенд + monitoring: Мониторинг + cloud: Облако + defense: + name: Защита + types: + certificate: Сертификат + escape: Отговорка + +attack: + first_player_hand: Рука Алисы + first_player_table: Стол Алисы + second_player_hand: Рука Бориса + face_down_card: Закрытая карта + discard: Сброс + +card_info: + card_type: + description: Тип карты + example: Защита + special_attribute: + description: Можно использовать с картой "sudo" + example: $ + card_name: + description: Название карты + example: Отговорка + card_bonus: + description: Разыгрывается как реакция + example: TODO + card_description: + description: Описание карты + example: Реакцией защититесь от ошибки + card_interaction: + description: Социальное взаимодействие + example: TODO + card_counter: + description: Количество карт в колоде + example: 3 карты + card_joke: + description: Шутка + +game_process: + first_player_hand: Рука Алисы + first_player_table: Стол Алисы + second_player_hand: Рука Бориса + second_player_table: Стол Бориса + face_down_card: Закрытая карта + face_down_cards: Закрытые карты + discard: Сброс + deck: Колода + diff --git a/ru/schemas/atack1-1.jpg b/ru/schemas/atack1-1.jpg index ae6f41f..1e10dfe 100644 Binary files a/ru/schemas/atack1-1.jpg and b/ru/schemas/atack1-1.jpg differ diff --git a/ru/schemas/atack1-2.jpg b/ru/schemas/atack1-2.jpg index 00c2d4e..5fed701 100644 Binary files a/ru/schemas/atack1-2.jpg and b/ru/schemas/atack1-2.jpg differ diff --git a/ru/schemas/atack1.jpg b/ru/schemas/atack1.jpg index 7f25952..a72f2b9 100644 Binary files a/ru/schemas/atack1.jpg and b/ru/schemas/atack1.jpg differ diff --git a/ru/schemas/card.jpg b/ru/schemas/card.jpg index f089ff6..4cbb712 100644 Binary files a/ru/schemas/card.jpg and b/ru/schemas/card.jpg differ diff --git a/ru/schemas/game-process.jpg b/ru/schemas/game-process.jpg index a8f5856..e7e0e72 100644 Binary files a/ru/schemas/game-process.jpg and b/ru/schemas/game-process.jpg differ