Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependencies update #335

Merged
merged 8 commits into from
Jan 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -5,23 +5,26 @@

The platform for conducting, tracking and checking students' sports activity at Innopolis University.

## Requirements:

* Python 3.7
* Docker and Docker Compose

## How to start coding

1. Install dependencies: `pip3 install -r ./adminpage/requirements.txt`
2. Copy environment variables: `cp deploy/.env.example deploy/.env`
3. Start services: `docker compose -f ./deploy/docker-compose.yaml up`
4. Make migrations and create superuser:
## Development

### Set up for development

1. Install [Python 3.12](https://www.python.org/downloads/), [Poetry](https://python-poetry.org/docs/),
[Docker](https://docs.docker.com/engine/install/)
2. Install project dependencies with [Poetry](https://python-poetry.org/docs/cli/#options-2).
```bash
cd adminpage
poetry install
```
3. Copy environment variables: `cp deploy/.env.example deploy/.env`
4. Start services: `docker compose -f ./deploy/docker-compose.yaml up`
5. Make migrations and create superuser:
- Enter shell: `docker compose -f ./deploy/docker-compose.yaml exec -it adminpanel bash`
- Autocreate migration files: `python manage.py makemigrations`
- Apply migrations to db: `python manage.py migrate`
> If there are problems with migrations applying, try to run the same migrate command with `--fake` option.
- Create a new superuser: `python manage.py createsuperuser`
5. View admin panel at `http://localhost/admin`
6. View admin panel at `http://localhost/admin`

> [!NOTE]
> Server supports auto-reload on code change in debug mode
@@ -30,7 +33,7 @@ API documentation:
* Swagger is at http://localhost/api/swagger
* Redoc is at http://localhost/api/redoc

## Environment Variables
### Environment Variables

See `deploy/.env.example` for reference.

@@ -59,7 +62,7 @@ The project requires a file `deploy/.env` with the following environment variabl

You can leave the default values for development.

## Project structure
### Project structure

```
.
74 changes: 65 additions & 9 deletions adminpage/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,69 @@
# Based on https://github.com/svx/poetry-fastapi-docker/blob/main/Dockerfile

ARG PYTHON_VERSION

FROM python:${PYTHON_VERSION}-slim
ENV PYTHONUNBUFFERED 1
RUN mkdir /src
WORKDIR /src
COPY ./requirements.txt /src/
###########################################################
# Base Python image. Set shared environment variables.
FROM python:${PYTHON_VERSION}-slim-bullseye AS base
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100 \
POETRY_HOME="/opt/poetry" \
POETRY_VIRTUALENVS_IN_PROJECT=true \
POETRY_NO_INTERACTION=1 \
POETRY_INSTALLER_MAX_WORKERS=10 \
PYSETUP_PATH="/opt/pysetup" \
VENV_PATH="/opt/pysetup/.venv"

ENV PATH="$POETRY_HOME/bin:$VENV_PATH/bin:$PATH"

RUN apt-get update \
&& apt-get install --no-install-recommends -y \
gcc \
git \
python3-dev \
libjpeg62-turbo-dev \
zlib1g-dev \
&& rm -rf /var/lib/apt/lists/*


###########################################################
# Builder stage. Build dependencies.
FROM base AS builder
RUN apt-get update \
&& apt-get install -y --no-install-recommends git \
&& apt-get purge -y --auto-remove \
&& apt-get install --no-install-recommends -y \
build-essential \
curl \
netcat \
vim \
&& rm -rf /var/lib/apt/lists/*
RUN pip install -r /src/requirements.txt
COPY . /src

# Install Poetry. Respects $POETRY_VERSION and $POETRY_HOME
ENV POETRY_VERSION=1.8.5
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN curl -sS https://install.python-poetry.org | POETRY_HOME=${POETRY_HOME} python3 - --version ${POETRY_VERSION} && \
chmod a+x /opt/poetry/bin/poetry

# We copy our Python requirements here to cache them
# and install only runtime deps using poetry
WORKDIR $PYSETUP_PATH
COPY ./poetry.lock ./pyproject.toml ./
RUN poetry install --no-interaction


###########################################################
# Production stage. Copy only runtime deps that were installed in the Builder stage.
FROM base AS production

COPY --from=builder $VENV_PATH $VENV_PATH

COPY --chmod=755 ./docker-entrypoint.sh /

COPY --chmod=644 . /code
WORKDIR /code

EXPOSE 8000
ENTRYPOINT [ "/docker-entrypoint.sh" ]
CMD [ "uvicorn", "adminpage.asgi:application", "--host", "0.0.0.0", "--port", "8000", "--workers", "4", "--lifespan", "off", "--proxy-headers", "--forwarded-allow-ips=*" ]
2 changes: 1 addition & 1 deletion adminpage/accounts/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.contrib.auth.models import AbstractUser, BaseUserManager
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _


class UserManager(BaseUserManager):
2 changes: 1 addition & 1 deletion adminpage/adminpage/settings.py
Original file line number Diff line number Diff line change
@@ -93,7 +93,7 @@ def compose_base_url(schema, hostname, port) -> str:

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = getenv_boolean("DEBUG")
PROJECT_ROOT = "/src/"
PROJECT_ROOT = "/code/"
ALLOWED_HOSTS = [HOSTNAME, 'adminpanel']

if DEBUG:
2 changes: 1 addition & 1 deletion adminpage/api/crud/crud_attendance.py
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
from django.db.models import F, Value, BooleanField, Case, When, CharField, Sum, IntegerField, OuterRef
from django.db.models.functions import Concat, Coalesce
from django.db.models.expressions import Value, Case, When, Subquery, OuterRef, ExpressionWrapper
from typing_extensions import TypedDict
from typing import TypedDict

from django.db import connection

3 changes: 1 addition & 2 deletions adminpage/api/tests/api/test_attendance.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import unittest
from datetime import date, datetime, timedelta
from datetime import date, datetime, timedelta, timezone
from typing import Tuple

import pytest
from django.conf import settings
from django.contrib.auth import get_user_model
from django.utils import timezone
from rest_framework import status
from rest_framework.test import APIClient

12 changes: 12 additions & 0 deletions adminpage/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

set -e

# Activate our virtual environment here
. /opt/pysetup/.venv/bin/activate

# You can put other setup logic here
# ...

# Evaluating passed command:
exec "$@"
Loading