Skip to content

Commit 7244dc4

Browse files
authored
Better docs: version, root_path
1 parent 81b5a74 commit 7244dc4

File tree

5 files changed

+48
-24
lines changed

5 files changed

+48
-24
lines changed

.github/workflows/build_and_publish.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,16 @@ jobs:
4747
push: true
4848
tags: ${{ steps.meta.outputs.tags }}
4949
labels: ${{ steps.meta.outputs.labels }}
50+
build-args: |
51+
APP_VERSION=${{ github.ref_name }}
5052
5153
deploy-testing:
5254
name: Deploy Testing
5355
needs: build-and-push-image
5456
runs-on: [self-hosted, Linux]
5557
environment:
5658
name: Testing
57-
url: https://timetable.api.test.profcomff.com/
59+
url: https://api.test.profcomff.com/timetable
5860
env:
5961
CONTAITER_NAME: com_profcomff_api_timetable_test
6062
permissions:
@@ -85,6 +87,7 @@ jobs:
8587
--network=web \
8688
--volume com_profcomff_api_timetable_test_static:/app/static \
8789
--env DB_DSN=${{ secrets.DB_DSN }} \
90+
--env ROOT_PATH='/timetable' \
8891
--env GUNICORN_CMD_ARGS='--log-config logging_test.conf' \
8992
--env GOOGLE_CLIENT_SECRET='${{ secrets.GOOGLE_CLIENT_SECRET }}' \
9093
--env STATIC_PATH=static \
@@ -98,7 +101,7 @@ jobs:
98101
runs-on: [self-hosted, Linux]
99102
environment:
100103
name: Production
101-
url: https://timetable.api.profcomff.com/
104+
url: https://api.profcomff.com/timetable
102105
env:
103106
CONTAITER_NAME: com_profcomff_api_timetable
104107
permissions:
@@ -129,6 +132,7 @@ jobs:
129132
--network=web \
130133
--volume com_profcomff_api_timetable_static:/app/static \
131134
--env DB_DSN='${{ secrets.DB_DSN }}' \
135+
--env ROOT_PATH='/timetable' \
132136
--env ADMIN_SECRET='${{ secrets.ADMIN_SECRET }}' \
133137
--env REDIRECT_URL='https://www.profcomff.com/timetable/google' \
134138
--env GOOGLE_CLIENT_SECRET='${{ secrets.GOOGLE_CLIENT_SECRET }}' \

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.11
2+
ARG APP_VERSION=dev
3+
ENV APP_VERSION=${APP_VERSION}
24
ENV APP_NAME=calendar_backend
35
ENV APP_MODULE=${APP_NAME}.routes.base:app
46

calendar_backend/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import os
2+
3+
4+
__version__ = os.getenv('APP_VERSION', 'dev')

calendar_backend/routes/base.py

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
import logging
2+
from textwrap import dedent
23

34
import starlette.requests
45
from fastapi import FastAPI
56
from fastapi.middleware.cors import CORSMiddleware
67
from fastapi.responses import JSONResponse
78
from fastapi_sqlalchemy import DBSessionMiddleware
9+
from fastapi.staticfiles import StaticFiles
810
from starlette import status
911
from starlette.middleware.base import BaseHTTPMiddleware, RequestResponseEndpoint
1012
from starlette.requests import Request
1113
from starlette.responses import Response
12-
from fastapi.staticfiles import StaticFiles
1314
from starlette.types import ASGIApp
1415

16+
from calendar_backend import __version__
1517
from calendar_backend.exceptions import ObjectNotFound, ForbiddenAction, NotEnoughCriteria
1618
from calendar_backend.settings import get_settings
19+
1720
from .auth import auth_router
1821
from .gcal import gcal
1922
from .lecturer import (
@@ -27,30 +30,38 @@
2730
from .room import room_router
2831
from .event import event_router, event_comment_router, event_comment_review_router
2932

33+
3034
settings = get_settings()
3135
logger = logging.getLogger(__name__)
3236
app = FastAPI(
33-
description="""API для работы с календарем физфака.
34-
Пример работы на питоне(Создание Room):
35-
```python
36-
import reqests, json
37-
url=f"https://timetable.api.test.profcomff.com"
38-
39-
# Авторизация
40-
beaver = requests.post(f"{url}/token", {"username": "...", "password": "..."})
41-
42-
# Парсинг ответа
43-
auth_data=json.loads(beaver.content)
44-
45-
# Создание
46-
create_room = requests.post(
47-
f"{url}/timetable/room",
48-
json={"name": "test", "direction": "South"},
49-
headers={"Authorization": f"Bearer {auth_data.get('access_token')}"}
50-
)
51-
52-
```
53-
"""
37+
title='Сервис мониторинга активности',
38+
description=dedent("""
39+
API для работы с календарем физфака.
40+
Пример работы на питоне(Создание Room):
41+
```python
42+
import reqests, json
43+
url=f"https://timetable.api.test.profcomff.com"
44+
45+
# Авторизация
46+
beaver = requests.post(f"{url}/token", {"username": "...", "password": "..."})
47+
48+
# Парсинг ответа
49+
auth_data=json.loads(beaver.content)
50+
51+
# Создание
52+
create_room = requests.post(
53+
f"{url}/timetable/room",
54+
json={"name": "test", "direction": "South"},
55+
headers={"Authorization": f"Bearer {auth_data.get('access_token')}"}
56+
)
57+
```
58+
"""),
59+
version=__version__,
60+
61+
# Настраиваем интернет документацию
62+
root_path=settings.ROOT_PATH if __version__ != 'dev' else '/',
63+
docs_url=None if __version__ != 'dev' else '/docs',
64+
redoc_url=None,
5465
)
5566

5667

calendar_backend/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from functools import lru_cache
23

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

910
DB_DSN: PostgresDsn = 'postgresql://postgres@localhost:5432/postgres'
11+
ROOT_PATH: str = '/' + os.getenv('APP_NAME', '')
12+
1013
REDIRECT_URL: AnyHttpUrl = "https://www.profcomff.com"
1114
SCOPES: list[str] = [
1215
"https://www.googleapis.com/auth/calendar",

0 commit comments

Comments
 (0)