Skip to content

Commit

Permalink
Python 3.11 (#74)
Browse files Browse the repository at this point in the history
Co-authored-by: semen603089 <[email protected]>
Co-authored-by: Grigoriev Semyon <[email protected]>
  • Loading branch information
3 people committed Dec 4, 2022
1 parent 90c91d4 commit 0d33006
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 86 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build_and_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ jobs:
--network=web \
--env DB_DSN=${{ secrets.DB_DSN }} \
--name ${{ env.CONTAITER_NAME }}_migration \
--workdir="/" \
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:test \
alembic upgrade head
Expand All @@ -85,6 +86,7 @@ jobs:
--volume com_profcomff_api_timetable_test_static:/app/static \
--env DB_DSN=${{ secrets.DB_DSN }} \
--env GOOGLE_CLIENT_SECRET='${{ secrets.GOOGLE_CLIENT_SECRET }}' \
--env STATIC_PATH=/app/static \
--name ${{ env.CONTAITER_NAME }} \
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:test
Expand Down Expand Up @@ -112,6 +114,7 @@ jobs:
--network=web \
--env DB_DSN=${{ secrets.DB_DSN }} \
--name ${{ env.CONTAITER_NAME }}_migration \
--workdir="/" \
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest \
alembic upgrade head
Expand All @@ -128,5 +131,6 @@ jobs:
--env ADMIN_SECRET='${{ secrets.ADMIN_SECRET }}' \
--env REDIRECT_URL='https://www.profcomff.com/timetable/google' \
--env GOOGLE_CLIENT_SECRET='${{ secrets.GOOGLE_CLIENT_SECRET }}' \
--env STATIC_PATH=/app/static \
--name ${{ env.CONTAITER_NAME }} \
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
docker run -d -p 5432:5432 -e POSTGRES_HOST_AUTH_METHOD=trust --name db-test postgres:15-alpine
- uses: actions/setup-python@v4
with:
python-version: '3.10'
python-version: '3.11'
- name: Install dependencies
run: |
python -m ensurepip
Expand Down
17 changes: 8 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
FROM python:3.10
WORKDIR /app
RUN mkdir -p static/cache && mkdir -p static/photo/lecturer
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.11
ENV APP_NAME=calendar_backend
ENV APP_MODULE=${APP_NAME}.routes.base:app

COPY ./requirements.txt /app/
RUN pip install --no-cache-dir -r /app/requirements.txt
RUN pip install -U -r /app/requirements.txt

ADD gunicorn_conf.py alembic.ini /app/
ADD migrations /app/migrations
ADD calendar_backend /app/calendar_backend
COPY ./static /app/static/

VOLUME ["/app/static"]
COPY ./alembic.ini /alembic.ini
COPY ./migrations /migrations/

CMD [ "gunicorn", "-k", "uvicorn.workers.UvicornWorker", "-c", "/app/gunicorn_conf.py", "calendar_backend.routes.base:app" ]
COPY ./${APP_NAME} /app/${APP_NAME}
8 changes: 4 additions & 4 deletions calendar_backend/methods/list_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ async def create_user_calendar_file(user_calendar: Calendar, group: str) -> str:
"""
logger.debug(f"Creating .ics file from iCalendar {user_calendar.name}")
try:
with open(f"{settings.ICS_PATH}/{group}", "wb") as f:
with open(f"{settings.STATIC_PATH}/cache/{group}", "wb") as f:
f.write(user_calendar.to_ical())
return f"{settings.ICS_PATH}/{group}"
return f"{settings.STATIC_PATH}/cache/{group}"
except OSError as e:
logger.info(f"The error {e} occurred")

Expand Down Expand Up @@ -96,9 +96,9 @@ def check_file_for_creation_date(path_file: str) -> bool:


async def create_ics(group_id: int, start: datetime.date, end: datetime.date, session: Session):
if check_file_for_creation_date(f"{settings.ICS_PATH}/{group_id}") is False:
if check_file_for_creation_date(f"{settings.STATIC_PATH}/cache/{group_id}") is False:
logger.debug(f"Calendar for group '{group_id}' found in cache")
return FileResponse(f"{settings.ICS_PATH}/{group_id}")
return FileResponse(f"{settings.STATIC_PATH}/cache/{group_id}")
else:
async with asyncio.Lock():
logger.debug("Getting user calendar...")
Expand Down
2 changes: 1 addition & 1 deletion calendar_backend/methods/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ async def upload_lecturer_photo(lecturer_id: int, session: Session, file: Upload
lecturer = Lecturer.get(lecturer_id, session=session)
random_string = ''.join(random.choice(string.ascii_letters) for _ in range(32))
ext = file.filename.split('.')[-1]
path = os.path.join(settings.PHOTO_LECTURER_PATH, f"{random_string}.{ext}")
path = os.path.join(settings.STATIC_PATH, "photo", "lecturer", f"{random_string}.{ext}")
async with aiofiles.open(path, 'wb') as out_file:
content = await file.read()
await out_file.write(content)
Expand Down
2 changes: 1 addition & 1 deletion calendar_backend/routes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ async def dispatch(self, request: Request, call_next: RequestResponseEndpoint) -
)
app.add_middleware(LimitUploadSize, max_upload_size=3145728) # 3MB

app.mount('/static', StaticFiles(directory='static'), 'static')
app.mount('/static', StaticFiles(directory=settings.STATIC_PATH), 'static')

app.include_router(gcal)
app.include_router(auth_router)
Expand Down
5 changes: 2 additions & 3 deletions calendar_backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
class Settings(BaseSettings):
"""Application settings"""

DB_DSN: PostgresDsn
DB_DSN: PostgresDsn = 'postgresql://postgres@localhost:5432/postgres'
REDIRECT_URL: AnyHttpUrl = "https://www.profcomff.com"
SCOPES: list[str] = [
"https://www.googleapis.com/auth/calendar",
"https://www.googleapis.com/auth/userinfo.email",
]
ICS_PATH: DirectoryPath = "static/cache"
PHOTO_LECTURER_PATH: DirectoryPath = 'static/photo/lecturer'
STATIC_PATH: DirectoryPath | None
ADMIN_SECRET: dict[str, str] = {"admin": "42"}
REQUIRE_REVIEW_PHOTOS: bool = True
REQUIRE_REVIEW_LECTURER_COMMENT: bool = True
Expand Down
67 changes: 0 additions & 67 deletions gunicorn_conf.py

This file was deleted.

5 changes: 5 additions & 0 deletions tests/lecturer/photos.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
from fastapi.testclient import TestClient
from starlette import status
from calendar_backend.settings import get_settings


settings = get_settings()
settings.STATIC_PATH = './static'


def test_read_all(client_auth: TestClient, photo_path: str):
Expand Down

0 comments on commit 0d33006

Please sign in to comment.