Skip to content

Commit

Permalink
Better docs: version, root_path
Browse files Browse the repository at this point in the history
  • Loading branch information
dyakovri authored Mar 12, 2023
1 parent 81b5a74 commit 7244dc4
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 24 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/build_and_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,16 @@ jobs:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
APP_VERSION=${{ github.ref_name }}
deploy-testing:
name: Deploy Testing
needs: build-and-push-image
runs-on: [self-hosted, Linux]
environment:
name: Testing
url: https://timetable.api.test.profcomff.com/
url: https://api.test.profcomff.com/timetable
env:
CONTAITER_NAME: com_profcomff_api_timetable_test
permissions:
Expand Down Expand Up @@ -85,6 +87,7 @@ jobs:
--network=web \
--volume com_profcomff_api_timetable_test_static:/app/static \
--env DB_DSN=${{ secrets.DB_DSN }} \
--env ROOT_PATH='/timetable' \
--env GUNICORN_CMD_ARGS='--log-config logging_test.conf' \
--env GOOGLE_CLIENT_SECRET='${{ secrets.GOOGLE_CLIENT_SECRET }}' \
--env STATIC_PATH=static \
Expand All @@ -98,7 +101,7 @@ jobs:
runs-on: [self-hosted, Linux]
environment:
name: Production
url: https://timetable.api.profcomff.com/
url: https://api.profcomff.com/timetable
env:
CONTAITER_NAME: com_profcomff_api_timetable
permissions:
Expand Down Expand Up @@ -129,6 +132,7 @@ jobs:
--network=web \
--volume com_profcomff_api_timetable_static:/app/static \
--env DB_DSN='${{ secrets.DB_DSN }}' \
--env ROOT_PATH='/timetable' \
--env ADMIN_SECRET='${{ secrets.ADMIN_SECRET }}' \
--env REDIRECT_URL='https://www.profcomff.com/timetable/google' \
--env GOOGLE_CLIENT_SECRET='${{ secrets.GOOGLE_CLIENT_SECRET }}' \
Expand Down
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.11
ARG APP_VERSION=dev
ENV APP_VERSION=${APP_VERSION}
ENV APP_NAME=calendar_backend
ENV APP_MODULE=${APP_NAME}.routes.base:app

Expand Down
4 changes: 4 additions & 0 deletions calendar_backend/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import os


__version__ = os.getenv('APP_VERSION', 'dev')
55 changes: 33 additions & 22 deletions calendar_backend/routes/base.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import logging
from textwrap import dedent

import starlette.requests
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse
from fastapi_sqlalchemy import DBSessionMiddleware
from fastapi.staticfiles import StaticFiles
from starlette import status
from starlette.middleware.base import BaseHTTPMiddleware, RequestResponseEndpoint
from starlette.requests import Request
from starlette.responses import Response
from fastapi.staticfiles import StaticFiles
from starlette.types import ASGIApp

from calendar_backend import __version__
from calendar_backend.exceptions import ObjectNotFound, ForbiddenAction, NotEnoughCriteria
from calendar_backend.settings import get_settings

from .auth import auth_router
from .gcal import gcal
from .lecturer import (
Expand All @@ -27,30 +30,38 @@
from .room import room_router
from .event import event_router, event_comment_router, event_comment_review_router


settings = get_settings()
logger = logging.getLogger(__name__)
app = FastAPI(
description="""API для работы с календарем физфака.
Пример работы на питоне(Создание Room):
```python
import reqests, json
url=f"https://timetable.api.test.profcomff.com"
# Авторизация
beaver = requests.post(f"{url}/token", {"username": "...", "password": "..."})
# Парсинг ответа
auth_data=json.loads(beaver.content)
# Создание
create_room = requests.post(
f"{url}/timetable/room",
json={"name": "test", "direction": "South"},
headers={"Authorization": f"Bearer {auth_data.get('access_token')}"}
)
```
"""
title='Сервис мониторинга активности',
description=dedent("""
API для работы с календарем физфака.
Пример работы на питоне(Создание Room):
```python
import reqests, json
url=f"https://timetable.api.test.profcomff.com"
# Авторизация
beaver = requests.post(f"{url}/token", {"username": "...", "password": "..."})
# Парсинг ответа
auth_data=json.loads(beaver.content)
# Создание
create_room = requests.post(
f"{url}/timetable/room",
json={"name": "test", "direction": "South"},
headers={"Authorization": f"Bearer {auth_data.get('access_token')}"}
)
```
"""),
version=__version__,

# Настраиваем интернет документацию
root_path=settings.ROOT_PATH if __version__ != 'dev' else '/',
docs_url=None if __version__ != 'dev' else '/docs',
redoc_url=None,
)


Expand Down
3 changes: 3 additions & 0 deletions calendar_backend/settings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from functools import lru_cache

from pydantic import BaseSettings, PostgresDsn, AnyHttpUrl, DirectoryPath, Json
Expand All @@ -7,6 +8,8 @@ class Settings(BaseSettings):
"""Application settings"""

DB_DSN: PostgresDsn = 'postgresql://postgres@localhost:5432/postgres'
ROOT_PATH: str = '/' + os.getenv('APP_NAME', '')

REDIRECT_URL: AnyHttpUrl = "https://www.profcomff.com"
SCOPES: list[str] = [
"https://www.googleapis.com/auth/calendar",
Expand Down

0 comments on commit 7244dc4

Please sign in to comment.