Skip to content

Commit 0d33006

Browse files
Python 3.11 (#74)
Co-authored-by: semen603089 <semen603089@mail.ru> Co-authored-by: Grigoriev Semyon <33061489+grigoriev-semyon@users.noreply.github.com>
1 parent 90c91d4 commit 0d33006

9 files changed

Lines changed: 26 additions & 86 deletions

File tree

.github/workflows/build_and_publish.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ jobs:
7171
--network=web \
7272
--env DB_DSN=${{ secrets.DB_DSN }} \
7373
--name ${{ env.CONTAITER_NAME }}_migration \
74+
--workdir="/" \
7475
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:test \
7576
alembic upgrade head
7677
@@ -85,6 +86,7 @@ jobs:
8586
--volume com_profcomff_api_timetable_test_static:/app/static \
8687
--env DB_DSN=${{ secrets.DB_DSN }} \
8788
--env GOOGLE_CLIENT_SECRET='${{ secrets.GOOGLE_CLIENT_SECRET }}' \
89+
--env STATIC_PATH=/app/static \
8890
--name ${{ env.CONTAITER_NAME }} \
8991
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:test
9092
@@ -112,6 +114,7 @@ jobs:
112114
--network=web \
113115
--env DB_DSN=${{ secrets.DB_DSN }} \
114116
--name ${{ env.CONTAITER_NAME }}_migration \
117+
--workdir="/" \
115118
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest \
116119
alembic upgrade head
117120
@@ -128,5 +131,6 @@ jobs:
128131
--env ADMIN_SECRET='${{ secrets.ADMIN_SECRET }}' \
129132
--env REDIRECT_URL='https://www.profcomff.com/timetable/google' \
130133
--env GOOGLE_CLIENT_SECRET='${{ secrets.GOOGLE_CLIENT_SECRET }}' \
134+
--env STATIC_PATH=/app/static \
131135
--name ${{ env.CONTAITER_NAME }} \
132136
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
docker run -d -p 5432:5432 -e POSTGRES_HOST_AUTH_METHOD=trust --name db-test postgres:15-alpine
1919
- uses: actions/setup-python@v4
2020
with:
21-
python-version: '3.10'
21+
python-version: '3.11'
2222
- name: Install dependencies
2323
run: |
2424
python -m ensurepip

Dockerfile

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
FROM python:3.10
2-
WORKDIR /app
3-
RUN mkdir -p static/cache && mkdir -p static/photo/lecturer
1+
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.11
2+
ENV APP_NAME=calendar_backend
3+
ENV APP_MODULE=${APP_NAME}.routes.base:app
44

55
COPY ./requirements.txt /app/
6-
RUN pip install --no-cache-dir -r /app/requirements.txt
6+
RUN pip install -U -r /app/requirements.txt
77

8-
ADD gunicorn_conf.py alembic.ini /app/
9-
ADD migrations /app/migrations
10-
ADD calendar_backend /app/calendar_backend
8+
COPY ./static /app/static/
119

12-
VOLUME ["/app/static"]
10+
COPY ./alembic.ini /alembic.ini
11+
COPY ./migrations /migrations/
1312

14-
CMD [ "gunicorn", "-k", "uvicorn.workers.UvicornWorker", "-c", "/app/gunicorn_conf.py", "calendar_backend.routes.base:app" ]
13+
COPY ./${APP_NAME} /app/${APP_NAME}

calendar_backend/methods/list_calendar.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ async def create_user_calendar_file(user_calendar: Calendar, group: str) -> str:
5454
"""
5555
logger.debug(f"Creating .ics file from iCalendar {user_calendar.name}")
5656
try:
57-
with open(f"{settings.ICS_PATH}/{group}", "wb") as f:
57+
with open(f"{settings.STATIC_PATH}/cache/{group}", "wb") as f:
5858
f.write(user_calendar.to_ical())
59-
return f"{settings.ICS_PATH}/{group}"
59+
return f"{settings.STATIC_PATH}/cache/{group}"
6060
except OSError as e:
6161
logger.info(f"The error {e} occurred")
6262

@@ -96,9 +96,9 @@ def check_file_for_creation_date(path_file: str) -> bool:
9696

9797

9898
async def create_ics(group_id: int, start: datetime.date, end: datetime.date, session: Session):
99-
if check_file_for_creation_date(f"{settings.ICS_PATH}/{group_id}") is False:
99+
if check_file_for_creation_date(f"{settings.STATIC_PATH}/cache/{group_id}") is False:
100100
logger.debug(f"Calendar for group '{group_id}' found in cache")
101-
return FileResponse(f"{settings.ICS_PATH}/{group_id}")
101+
return FileResponse(f"{settings.STATIC_PATH}/cache/{group_id}")
102102
else:
103103
async with asyncio.Lock():
104104
logger.debug("Getting user calendar...")

calendar_backend/methods/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ async def upload_lecturer_photo(lecturer_id: int, session: Session, file: Upload
8484
lecturer = Lecturer.get(lecturer_id, session=session)
8585
random_string = ''.join(random.choice(string.ascii_letters) for _ in range(32))
8686
ext = file.filename.split('.')[-1]
87-
path = os.path.join(settings.PHOTO_LECTURER_PATH, f"{random_string}.{ext}")
87+
path = os.path.join(settings.STATIC_PATH, "photo", "lecturer", f"{random_string}.{ext}")
8888
async with aiofiles.open(path, 'wb') as out_file:
8989
content = await file.read()
9090
await out_file.write(content)

calendar_backend/routes/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ async def dispatch(self, request: Request, call_next: RequestResponseEndpoint) -
111111
)
112112
app.add_middleware(LimitUploadSize, max_upload_size=3145728) # 3MB
113113

114-
app.mount('/static', StaticFiles(directory='static'), 'static')
114+
app.mount('/static', StaticFiles(directory=settings.STATIC_PATH), 'static')
115115

116116
app.include_router(gcal)
117117
app.include_router(auth_router)

calendar_backend/settings.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@
66
class Settings(BaseSettings):
77
"""Application settings"""
88

9-
DB_DSN: PostgresDsn
9+
DB_DSN: PostgresDsn = 'postgresql://postgres@localhost:5432/postgres'
1010
REDIRECT_URL: AnyHttpUrl = "https://www.profcomff.com"
1111
SCOPES: list[str] = [
1212
"https://www.googleapis.com/auth/calendar",
1313
"https://www.googleapis.com/auth/userinfo.email",
1414
]
15-
ICS_PATH: DirectoryPath = "static/cache"
16-
PHOTO_LECTURER_PATH: DirectoryPath = 'static/photo/lecturer'
15+
STATIC_PATH: DirectoryPath | None
1716
ADMIN_SECRET: dict[str, str] = {"admin": "42"}
1817
REQUIRE_REVIEW_PHOTOS: bool = True
1918
REQUIRE_REVIEW_LECTURER_COMMENT: bool = True

gunicorn_conf.py

Lines changed: 0 additions & 67 deletions
This file was deleted.

tests/lecturer/photos.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
from fastapi.testclient import TestClient
22
from starlette import status
3+
from calendar_backend.settings import get_settings
4+
5+
6+
settings = get_settings()
7+
settings.STATIC_PATH = './static'
38

49

510
def test_read_all(client_auth: TestClient, photo_path: str):

0 commit comments

Comments
 (0)