Skip to content

Commit

Permalink
Merge pull request #2 from The-Galley/feature/workflows
Browse files Browse the repository at this point in the history
Feature/workflows
  • Loading branch information
andy-takker authored Mar 2, 2024
2 parents 2e88b45 + 0b575e5 commit 2abed99
Show file tree
Hide file tree
Showing 27 changed files with 467 additions and 91 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Make release

on:
workflow_dispatch:
push:
branches:
- master

jobs:
checking:
name: Check repository
uses: ./.github/workflows/check.yml

build_and_push_docker:
name: Build and push AMD64 and ARM64 images
needs: checking
runs-on: ubuntu-latest
steps:

- name: Set up tag
id: vars
run: echo "sha_short=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_OUTPUT

- name: Checkout
uses: actions/checkout@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push backend image
uses: docker/build-push-action@v5
with:
push: true
platforms: linux/amd64,linux/arm64
context: ./
file: ./docker/rest.dockerfile
tags: |
andytakker/industry-game-rest:latest
andytakker/vk-parser:${{ steps.vars.outputs.sha_short }}
- name: Build and push frontend image
uses: docker/build-push-action@v5
with:
push: true
platforms: linux/amd64,linux/arm64
context: ./
file: ./docker/frontend.dockerfile
tags: |
andytakker/industry-game-frontend:latest
andytakker/vk-parser:${{ steps.vars.outputs.sha_short }}
130 changes: 130 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,133 @@ cython_debug/
.DS_Store
ssl_keys/
*.pem
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ lint-ci: lint-py lint-js ##@Linting Run all linters in CI
lint-py: flake ruff bandit mypy ##@Linting Run all python linters in CI

lint-js: ##@Linting Run JS linter in CI
cd ./industry_game/static && yarn lint --no-fix
cd ./frontend && yarn lint --no-fix

flake: ##@Linting Run flake8
.venv/bin/flake8 --max-line-length 88 --format=default $(PROJECT_PATH) 2>&1 | tee flake8.txt
Expand Down
20 changes: 10 additions & 10 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ services:

rest:
restart: on-failure
# image: andytakker/industry-game-rest:latest
build:
dockerfile: ./docker/rest.dockerfile
context: .
image: andytakker/industry-game-rest:latest
# build:
# dockerfile: ./docker/rest.dockerfile
# context: .
entrypoint: python -m industry_game
environment:
APP_API_ADDRESS: 0.0.0.0
Expand All @@ -34,12 +34,12 @@ services:

frontend:
restart: on-failure
# image: andytakker/industry-game-frontend:latest
build:
dockerfile: ./docker/frontend.dockerfile
context: .
args:
BASE_URL: https://vk.com
image: andytakker/industry-game-frontend:latest
# build:
# dockerfile: ./docker/frontend.dockerfile
# context: .
# args:
# BASE_URL: https://vk.com
ports:
- 80:80
- 443:443
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
from aiohttp.web_exceptions import HTTPNotFound
from aiohttp.web_response import Response

from industry_game.utils.http.auth.base import require_authorization
from industry_game.utils.http.auth.base import AuthMixin, require_authorization
from industry_game.utils.http.deps import DependenciesMixin
from industry_game.utils.http.params import parse_path_param
from industry_game.utils.http.response import msgspec_json_response


class ReadByIdGameHandler(View, DependenciesMixin):
class GameDetailsHandler(View, DependenciesMixin, AuthMixin):
@require_authorization
async def get(self) -> Response:
game_id = parse_path_param(self.request, "game_id", int)
Expand Down
File renamed without changes.
File renamed without changes.
7 changes: 5 additions & 2 deletions industry_game/handlers/games/lobby/list_lobby.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from aiohttp.web import HTTPNotFound, Response, View

from industry_game.utils.http.auth.base import AuthMixin, require_authorization
from industry_game.utils.http.auth.base import (
AuthMixin,
require_admin_authorization,
)
from industry_game.utils.http.deps import DependenciesMixin
from industry_game.utils.http.params import (
PaginationParamsModel,
Expand All @@ -11,7 +14,7 @@


class ListGameLobbyHandler(View, DependenciesMixin, AuthMixin):
@require_authorization
@require_admin_authorization
async def get(self) -> Response:
game_id = parse_path_param(self.request, "game_id", int)
game = await self.game_storage.read_by_id(game_id=game_id)
Expand Down
3 changes: 1 addition & 2 deletions industry_game/handlers/ping.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import asyncio
import logging
from http import HTTPStatus

Expand All @@ -17,7 +16,7 @@ class PingHandler(View, DependenciesMixin):
async def get(self) -> Response:
try:
db = await self._ping()
except asyncio.TimeoutError:
except TimeoutError:
db = False
deps = {
"db": db,
Expand Down
2 changes: 1 addition & 1 deletion industry_game/handlers/players/login_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ async def parse_player_model(self) -> AuthUserModel:
try:
return AuthUserModel.model_validate_json(body)
except ValidationError:
raise HTTPBadRequest
raise HTTPBadRequest(reason="Incorrect user auth data")
8 changes: 4 additions & 4 deletions industry_game/services/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
from yarl import URL

from industry_game.handlers.games.create_game import CreateGameHandler
from industry_game.handlers.games.list_game import ListGameHandler
from industry_game.handlers.games.game_details import GameDetailsHandler
from industry_game.handlers.games.game_list import ListGameHandler
from industry_game.handlers.games.game_update import UpdateGameHandler
from industry_game.handlers.games.lobby.add_user_to_lobby import (
AddUserToGameLobbyHandler,
)
Expand All @@ -22,8 +24,6 @@
from industry_game.handlers.games.lobby.read_lobby import (
ReadGameUserLobbyHandler,
)
from industry_game.handlers.games.read_by_id_game import ReadByIdGameHandler
from industry_game.handlers.games.update_game import UpdateGameHandler
from industry_game.handlers.ping import PingHandler
from industry_game.handlers.players.list_player import ListPlayerHandler
from industry_game.handlers.players.login_player import LoginPlayerHandler
Expand Down Expand Up @@ -83,7 +83,7 @@ class REST(AIOHTTPService):
# game handlers
(hdrs.METH_GET, "/api/v1/games/", ListGameHandler),
(hdrs.METH_POST, "/api/v1/games/", CreateGameHandler),
(hdrs.METH_GET, "/api/v1/games/{game_id}/", ReadByIdGameHandler),
(hdrs.METH_GET, "/api/v1/games/{game_id}/", GameDetailsHandler),
(hdrs.METH_POST, "/api/v1/games/{game_id}/", UpdateGameHandler),
# lobby handlers
(hdrs.METH_GET, "/api/v1/games/{game_id}/lobby/", ListGameLobbyHandler),
Expand Down
3 changes: 2 additions & 1 deletion industry_game/utils/lobby/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from industry_game.db.models import UserGameLobby as UserGameLobbyDb
from industry_game.utils.pagination import MetaPagination
from industry_game.utils.users.models import ShortUser


class Lobby(msgspec.Struct, frozen=True):
Expand All @@ -18,4 +19,4 @@ def from_model(cls, obj: UserGameLobbyDb) -> "Lobby":

class LobbyPagination(msgspec.Struct, frozen=True):
meta: MetaPagination
items: list[Lobby]
items: list[ShortUser]
11 changes: 7 additions & 4 deletions industry_game/utils/lobby/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
from sqlalchemy import delete, func, insert, select
from sqlalchemy.ext.asyncio import AsyncSession

from industry_game.db.models import User as UserDb
from industry_game.db.models import UserGameLobby as UserGameLobbyDb
from industry_game.utils.db import AbstractStorage, inject_session
from industry_game.utils.lobby.models import Lobby, LobbyPagination
from industry_game.utils.pagination import MetaPagination
from industry_game.utils.users.models import ShortUser


class LobbyStorage(AbstractStorage):
Expand Down Expand Up @@ -80,16 +82,17 @@ async def count(self, session: AsyncSession) -> int:
@inject_session
async def get_items(
self, session: AsyncSession, game_id: int, page: int, page_size: int
) -> list[Lobby]:
) -> list[ShortUser]:
query = (
select(UserGameLobbyDb)
select(UserDb)
.join(UserGameLobbyDb, UserDb.id == UserGameLobbyDb.user_id)
.where(UserGameLobbyDb.game_id == game_id)
.limit(page_size)
.offset((page - 1) * page_size)
)

games = await session.scalars(query)
items: list[Lobby] = []
items: list[ShortUser] = []
for game in games:
items.append(Lobby.from_model(game))
items.append(ShortUser.from_model(game))
return items
7 changes: 6 additions & 1 deletion industry_game/utils/timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ class Timer:
_end_time: float | None
_task: asyncio.Task | None

def __init__(self, coroutine: Awaitable, seconds: float, speed: float = 1) -> None:
def __init__(
self,
coroutine: Awaitable,
seconds: float,
speed: float = 1,
) -> None:
self._coroutine = coroutine
self._seconds = seconds
self._re_seconds = seconds
Expand Down
Loading

0 comments on commit 2abed99

Please sign in to comment.