From ed199e1f23f24805940601f23399351fda740fcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Data?= <miki3867@gmail.com> Date: Sat, 2 Dec 2023 10:59:03 +0100 Subject: [PATCH 1/8] Clone boilerplate --- api/.dockerignore | 2 + api/.gitignore | 143 ++++++++++++++++++++++++ api/.pre-commit-config.yaml | 15 +++ api/Dockerfile | 15 +++ api/Makefile | 42 +++++++ api/README.md | 40 +++++++ api/docker-compose.yml | 24 ++++ api/drfboilerplate/__init__.py | 0 api/drfboilerplate/settings/__init__.py | 0 api/drfboilerplate/settings/ci-tests.py | 16 +++ api/drfboilerplate/settings/dev.py | 4 + api/drfboilerplate/settings/local.py | 4 + api/drfboilerplate/settings/prod.py | 137 +++++++++++++++++++++++ api/drfboilerplate/urls.py | 35 ++++++ api/drfboilerplate/wsgi.py | 17 +++ api/manage.py | 22 ++++ api/pyproject.toml | 2 + api/requirements.txt | 47 ++++++++ api/setup.cfg | 2 + api/tests/__init__.py | 0 20 files changed, 567 insertions(+) create mode 100644 api/.dockerignore create mode 100644 api/.gitignore create mode 100644 api/.pre-commit-config.yaml create mode 100644 api/Dockerfile create mode 100644 api/Makefile create mode 100644 api/README.md create mode 100644 api/docker-compose.yml create mode 100644 api/drfboilerplate/__init__.py create mode 100644 api/drfboilerplate/settings/__init__.py create mode 100644 api/drfboilerplate/settings/ci-tests.py create mode 100644 api/drfboilerplate/settings/dev.py create mode 100644 api/drfboilerplate/settings/local.py create mode 100644 api/drfboilerplate/settings/prod.py create mode 100644 api/drfboilerplate/urls.py create mode 100644 api/drfboilerplate/wsgi.py create mode 100755 api/manage.py create mode 100644 api/pyproject.toml create mode 100644 api/requirements.txt create mode 100644 api/setup.cfg create mode 100644 api/tests/__init__.py diff --git a/api/.dockerignore b/api/.dockerignore new file mode 100644 index 0000000..b454aef --- /dev/null +++ b/api/.dockerignore @@ -0,0 +1,2 @@ +venv +db \ No newline at end of file diff --git a/api/.gitignore b/api/.gitignore new file mode 100644 index 0000000..faf86bb --- /dev/null +++ b/api/.gitignore @@ -0,0 +1,143 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +.idea/ +static/ + +db/ diff --git a/api/.pre-commit-config.yaml b/api/.pre-commit-config.yaml new file mode 100644 index 0000000..eadaf80 --- /dev/null +++ b/api/.pre-commit-config.yaml @@ -0,0 +1,15 @@ +repos: + - repo: https://github.com/PyCQA/isort + rev: '5.10.1' + hooks: + - id: isort + args: ['--profile=black'] + - repo: https://github.com/psf/black + rev: '22.3.0' + hooks: + - id: black + language_version: python3 + - repo: https://github.com/pycqa/flake8 + rev: '4.0.1' + hooks: + - id: flake8 diff --git a/api/Dockerfile b/api/Dockerfile new file mode 100644 index 0000000..3571f65 --- /dev/null +++ b/api/Dockerfile @@ -0,0 +1,15 @@ +FROM python:3.9 + +ARG APPENV=prod + +ENV DJANGO_SETTINGS_MODULE=drfboilerplate.settings.${APPENV} + +WORKDIR /code +COPY requirements.txt /code/requirements.txt +RUN pip install -r requirements.txt +RUN mkdir static +COPY . /code/ + +EXPOSE 8001 + +CMD gunicorn --bind=0.0.0.0:8001 --timeout=10 drfboilerplate.wsgi:application -k gevent --log-level=debug diff --git a/api/Makefile b/api/Makefile new file mode 100644 index 0000000..954f10e --- /dev/null +++ b/api/Makefile @@ -0,0 +1,42 @@ +DC_FILE ?= docker-compose.yml + +build: + $(info ===> Building Docker image) + @docker-compose -f $(DC_FILE) build + +local: + $(info ===> Starting Docker containers) + @docker-compose -f $(DC_FILE) up + +shell: + @docker-compose -f $(DC_FILE) run --rm web python manage.py shell + +tests: + $(info ==> Running tests) + @docker-compose -f $(DC_FILE) run --rm web python manage.py test + +makemigrations: + $(info ==> Making migrations) + @docker-compose -f $(DC_FILE) run --rm web python manage.py makemigrations + +migrate: + $(info ==> Migrating) + @docker-compose -f $(DC_FILE) run --rm web python manage.py migrate + +collectstatic: + $(info ==> Collecting statics) + @docker-compose -f $(DC_FILE) run --rm web python manage.py collectstatic --noinput + +superuser: + @docker-compose -f $(DC_FILE) run --rm web python manage.py createsuperuser + +bash: + @docker-compose -f $(DC_FILE) run --rm web bash + +drop_db: + @docker-compose -f $(DC_FILE) rm -s -v db + rm -r db + +stop: + $(info ==> Stoping all containers) + @docker-compose -f $(DC_FILE) stop \ No newline at end of file diff --git a/api/README.md b/api/README.md new file mode 100644 index 0000000..f2a94da --- /dev/null +++ b/api/README.md @@ -0,0 +1,40 @@ +# Copbackend + +## Setup guide +1. Install docker and docker-compose. Look [here](https://docs.docker.com/desktop/) for docs +2. We're currently using `make` to build our app. It's installed by default in most of linux distros. For Windows users +it's more complicated. Look [here](https://stackoverflow.com/questions/32127524/how-to-install-and-use-make-in-windows) for more info. +In case you'll have a problem with `make` you can use commands defined in `makefile` directly. +3. Install pre-commit: +```shell +pre-commit install +``` +4. Now you're ready to build our app!!! Let's hop in: +```shell +make build +``` +5. Our App serves static files (css stylesheets, fonts, images and so on) we need to collect 'em. +This command would create a `static` directory. Look there if you're interested, what's inside ;) +```shell +make collectstatic +``` +6. It's time to create tables in database (docker container with database)! +```shell +make migrate +``` +7. Create superuser. +```shell +make superuser +``` +8. Start the app! +```shell +make local +``` +9. Open app on web browser `http://0.0.0.0:8001/admin/`. You can log in with superuser credentials. +## Start your adventure here! +Soon we'll give ya your first tasks, but now feel free to look around the project. We recommend to look on [swagger endpoint](http://0.0.0.0:8001/swagger/) as well as [admin page](http://0.0.0.0:8001/admin/). + +## Tips & tricks +1. Don't be afraid to ask questions. We're here to help ya! +2. Debug app with [Postman](https://www.postman.com/) or [Insomnia](https://insomnia.rest/) +3. If you're a student, you can use Pycharm Pro for free (and other amazing staff). Just enroll for [Github Student Pack](https://education.github.com/pack). diff --git a/api/docker-compose.yml b/api/docker-compose.yml new file mode 100644 index 0000000..176d62f --- /dev/null +++ b/api/docker-compose.yml @@ -0,0 +1,24 @@ +version: "3.9" + +services: + db: + image: postgres + volumes: + - ./db:/var/lib/postgresql/data + env_file: + - .env + + web: + build: + context: . + args: + APPENV: "local" + command: gunicorn --bind=0.0.0.0:8001 --timeout=10 drfboilerplate.wsgi:application --log-level debug -k gevent --reload + env_file: + - .env + volumes: + - .:/code + ports: + - "8001:8001" + depends_on: + - db diff --git a/api/drfboilerplate/__init__.py b/api/drfboilerplate/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/api/drfboilerplate/settings/__init__.py b/api/drfboilerplate/settings/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/api/drfboilerplate/settings/ci-tests.py b/api/drfboilerplate/settings/ci-tests.py new file mode 100644 index 0000000..26a90d3 --- /dev/null +++ b/api/drfboilerplate/settings/ci-tests.py @@ -0,0 +1,16 @@ +""" +Django settings for copywriter project. + +Generated by 'django-admin startproject' using Django 3.2.7. + +For more information on this file, see +https://docs.djangoproject.com/en/3.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/3.2/ref/settings/ +""" +from drfboilerplate.settings.prod import * # noqa: F403, F401 + +DEBUG = True + +DATABASES = {"default": {"ENGINE": "django.db.backends.sqlite3"}} diff --git a/api/drfboilerplate/settings/dev.py b/api/drfboilerplate/settings/dev.py new file mode 100644 index 0000000..3488cbd --- /dev/null +++ b/api/drfboilerplate/settings/dev.py @@ -0,0 +1,4 @@ +from drfboilerplate.settings.prod import * # noqa: F403, F401 + +DEBUG = True +CORS_ALLOWED_ORIGINS = [] diff --git a/api/drfboilerplate/settings/local.py b/api/drfboilerplate/settings/local.py new file mode 100644 index 0000000..716f7db --- /dev/null +++ b/api/drfboilerplate/settings/local.py @@ -0,0 +1,4 @@ +from drfboilerplate.settings.prod import * # noqa: F403, F401 + +DEBUG = True +CORS_ALLOW_ALL_ORIGINS = True diff --git a/api/drfboilerplate/settings/prod.py b/api/drfboilerplate/settings/prod.py new file mode 100644 index 0000000..770c7cd --- /dev/null +++ b/api/drfboilerplate/settings/prod.py @@ -0,0 +1,137 @@ +from datetime import timedelta +from pathlib import Path + +import environ + +env = environ.Env() + +DATABASES = { + "default": { + "ENGINE": "django.db.backends.postgresql", + "NAME": env("POSTGRES_DB", default="copbackend"), + "USER": env("POSTGRES_USER", default="copbackend"), + "PASSWORD": env("POSTGRES_PASSWORD", default=None), + "HOST": env("POSTGRES_HOST", default="localhost"), + "PORT": 5432, + } +} + +DEBUG = False + +BASE_DIR = Path(__file__).resolve().parent.parent.parent + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = env("SECRET_KEY", default="DEFAULT_SECRET_KEY_CHANGE_ME") + +ALLOWED_HOSTS = ["*"] + +# Application definition + +INSTALLED_APPS = [ + "django.contrib.admin", + "django.contrib.auth", + "django.contrib.contenttypes", + "django.contrib.sessions", + "django.contrib.messages", + "django.contrib.staticfiles", + "corsheaders", + "drf_spectacular", + "rest_framework", + "rest_framework_simplejwt", + "django_filters", +] + +REST_FRAMEWORK = { + "DEFAULT_PERMISSION_CLASSES": ("rest_framework.permissions.IsAuthenticated",), + "DEFAULT_AUTHENTICATION_CLASSES": ( + "rest_framework_simplejwt.authentication.JWTAuthentication", + ), + "DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema", +} + +SPECTACULAR_SETTINGS = { + "TITLE": "Change Here!!", + "DESCRIPTION": "Change Here!!", + "VERSION": "1.0.0", + "SERVERS": [ + {"url": "/", "description": "Local"}, + ], +} + +SIMPLE_JWT = { + "ACCESS_TOKEN_LIFETIME": timedelta(hours=24), + "REFRESH_TOKEN_LIFETIME": timedelta(days=7), +} +MIDDLEWARE = [ + "corsheaders.middleware.CorsMiddleware", + "django.middleware.security.SecurityMiddleware", + "django.contrib.sessions.middleware.SessionMiddleware", + "django.middleware.common.CommonMiddleware", + "django.middleware.csrf.CsrfViewMiddleware", + "django.contrib.auth.middleware.AuthenticationMiddleware", + "django.contrib.messages.middleware.MessageMiddleware", + "django.middleware.clickjacking.XFrameOptionsMiddleware", +] + +ROOT_URLCONF = "drfboilerplate.urls" + +TEMPLATES = [ + { + "BACKEND": "django.template.backends.django.DjangoTemplates", + "DIRS": [BASE_DIR / "templates"], + "APP_DIRS": True, + "OPTIONS": { + "context_processors": [ + "django.template.context_processors.debug", + "django.template.context_processors.request", + "django.contrib.auth.context_processors.auth", + "django.contrib.messages.context_processors.messages", + ], + }, + }, +] + +WSGI_APPLICATION = "drfboilerplate.wsgi.application" + +# Password validation +# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators +AUTH_PASSWORD_VALIDATORS = [ + { + "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", + }, +] + +# Internationalization +# https://docs.djangoproject.com/en/3.2/topics/i18n/ + +LANGUAGE_CODE = "pl" + +TIME_ZONE = "Europe/Warsaw" + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + +CORS_ALLOWED_ORIGINS = ["http://localhost"] + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/3.2/howto/static-files/ + +STATIC_URL = "/static/" +STATIC_ROOT = BASE_DIR / "static" + +# Default primary key field type +# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" diff --git a/api/drfboilerplate/urls.py b/api/drfboilerplate/urls.py new file mode 100644 index 0000000..d60c17b --- /dev/null +++ b/api/drfboilerplate/urls.py @@ -0,0 +1,35 @@ +"""copywriter URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/3.2/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import include, path +from drf_spectacular.views import ( + SpectacularAPIView, + SpectacularRedocView, + SpectacularSwaggerView, +) + +urlpatterns = [ + path("admin/", admin.site.urls), + path("api-schema/", SpectacularAPIView.as_view(), name="api-schema"), + path( + "swagger/", + SpectacularSwaggerView.as_view(url_name="api-schema"), + name="swagger-ui", + ), + path( + "redoc/", SpectacularRedocView.as_view(url_name="api-schema"), name="redoc-ui" + ), +] diff --git a/api/drfboilerplate/wsgi.py b/api/drfboilerplate/wsgi.py new file mode 100644 index 0000000..4f65a13 --- /dev/null +++ b/api/drfboilerplate/wsgi.py @@ -0,0 +1,17 @@ +""" +WSGI config for copywriter project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/ +""" + +import os + +from django.contrib.staticfiles.handlers import StaticFilesHandler +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "drfboilerplate.settings") + +application = StaticFilesHandler(get_wsgi_application()) diff --git a/api/manage.py b/api/manage.py new file mode 100755 index 0000000..791fc32 --- /dev/null +++ b/api/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "copywriter.settings") + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == "__main__": + main() diff --git a/api/pyproject.toml b/api/pyproject.toml new file mode 100644 index 0000000..55ec8d7 --- /dev/null +++ b/api/pyproject.toml @@ -0,0 +1,2 @@ +[tool.black] +line-length = 120 diff --git a/api/requirements.txt b/api/requirements.txt new file mode 100644 index 0000000..02c7fa2 --- /dev/null +++ b/api/requirements.txt @@ -0,0 +1,47 @@ +asgiref==3.4.1 +backports.entry-points-selectable==1.1.0 +certifi==2021.10.8 +cfgv==3.3.1 +charset-normalizer==2.0.7 +coreapi==2.3.3 +coreschema==0.0.4 +distlib==0.3.3 +Django==3.2.7 +django-environ==0.7.0 +djangorestframework==3.12.4 +djangorestframework-simplejwt==5.0.0 +filelock==3.3.2 +future==0.18.2 +gunicorn[gevent] == 20.1.0 +identify==2.3.1 +idna==3.3 +inflection==0.5.1 +itypes==1.2.0 +Jinja2==3.0.2 +MarkupSafe==2.0.1 +nodeenv==1.6.0 +packaging==21.2 +platformdirs==2.4.0 +pre-commit==2.15.0 +psycopg2-binary==2.9.1 +PyJWT==2.3.0 +pyparsing==2.4.7 +pytz==2021.1 +PyYAML==6.0 +requests==2.26.0 +ruamel.yaml==0.17.16 +ruamel.yaml.clib==0.2.6 +six==1.16.0 +sqlparse==0.4.2 +toml==0.10.2 +uritemplate==4.1.1 +urllib3==1.26.7 +virtualenv==20.9.0 +django-cors-headers==3.11.0 +django-filter~=21.1 +drf-extra-fields==3.2.1 +django-ordered-model==3.5 +drf-extensions==0.7.1 +drf-spectacular==0.21.2 +python-dateutil==2.8.2 +parameterized==0.8.1 \ No newline at end of file diff --git a/api/setup.cfg b/api/setup.cfg new file mode 100644 index 0000000..6deafc2 --- /dev/null +++ b/api/setup.cfg @@ -0,0 +1,2 @@ +[flake8] +max-line-length = 120 diff --git a/api/tests/__init__.py b/api/tests/__init__.py new file mode 100644 index 0000000..e69de29 From 1d190d068f4771fab4e1a37b6e733ab10efd0f3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Data?= <miki3867@gmail.com> Date: Sat, 2 Dec 2023 11:53:13 +0100 Subject: [PATCH 2/8] Setup django --- api/.dockerignore | 2 - api/.gitignore | 143 ------------------------ api/.pre-commit-config.yaml | 15 --- api/Dockerfile | 15 --- api/Makefile | 42 ------- api/README.md | 40 ------- api/{drfboilerplate => api}/__init__.py | 0 api/api/asgi.py | 16 +++ api/api/settings.py | 123 ++++++++++++++++++++ api/{drfboilerplate => api}/urls.py | 23 +--- api/api/wsgi.py | 16 +++ api/docker-compose.yml | 24 ---- api/drfboilerplate/settings/__init__.py | 0 api/drfboilerplate/settings/ci-tests.py | 16 --- api/drfboilerplate/settings/dev.py | 4 - api/drfboilerplate/settings/local.py | 4 - api/drfboilerplate/settings/prod.py | 137 ----------------------- api/drfboilerplate/wsgi.py | 17 --- api/manage.py | 4 +- api/poetry.lock | 67 +++++++++++ api/pyproject.toml | 17 ++- api/requirements.txt | 47 -------- api/setup.cfg | 2 - api/tests/__init__.py | 0 24 files changed, 244 insertions(+), 530 deletions(-) delete mode 100644 api/.dockerignore delete mode 100644 api/.gitignore delete mode 100644 api/.pre-commit-config.yaml delete mode 100644 api/Dockerfile delete mode 100644 api/Makefile delete mode 100644 api/README.md rename api/{drfboilerplate => api}/__init__.py (100%) create mode 100644 api/api/asgi.py create mode 100644 api/api/settings.py rename api/{drfboilerplate => api}/urls.py (50%) create mode 100644 api/api/wsgi.py delete mode 100644 api/docker-compose.yml delete mode 100644 api/drfboilerplate/settings/__init__.py delete mode 100644 api/drfboilerplate/settings/ci-tests.py delete mode 100644 api/drfboilerplate/settings/dev.py delete mode 100644 api/drfboilerplate/settings/local.py delete mode 100644 api/drfboilerplate/settings/prod.py delete mode 100644 api/drfboilerplate/wsgi.py create mode 100644 api/poetry.lock delete mode 100644 api/requirements.txt delete mode 100644 api/setup.cfg delete mode 100644 api/tests/__init__.py diff --git a/api/.dockerignore b/api/.dockerignore deleted file mode 100644 index b454aef..0000000 --- a/api/.dockerignore +++ /dev/null @@ -1,2 +0,0 @@ -venv -db \ No newline at end of file diff --git a/api/.gitignore b/api/.gitignore deleted file mode 100644 index faf86bb..0000000 --- a/api/.gitignore +++ /dev/null @@ -1,143 +0,0 @@ -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -share/python-wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.nox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -*.py,cover -.hypothesis/ -.pytest_cache/ -cover/ - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py -db.sqlite3 -db.sqlite3-journal - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ - -# PyBuilder -.pybuilder/ -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# IPython -profile_default/ -ipython_config.py - -# pyenv -# For a library or package, you might want to ignore these files since the code is -# intended to run in multiple environments; otherwise, check them in: -# .python-version - -# pipenv -# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. -# However, in case of collaboration, if having platform-specific dependencies or dependencies -# having no cross-platform support, pipenv may install dependencies that don't work, or not -# install all needed dependencies. -#Pipfile.lock - -# PEP 582; used by e.g. github.com/David-OConnor/pyflow -__pypackages__/ - -# Celery stuff -celerybeat-schedule -celerybeat.pid - -# SageMath parsed files -*.sage.py - -# Environments -.env -.venv -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json - -# Pyre type checker -.pyre/ - -# pytype static type analyzer -.pytype/ - -# Cython debug symbols -cython_debug/ - -.idea/ -static/ - -db/ diff --git a/api/.pre-commit-config.yaml b/api/.pre-commit-config.yaml deleted file mode 100644 index eadaf80..0000000 --- a/api/.pre-commit-config.yaml +++ /dev/null @@ -1,15 +0,0 @@ -repos: - - repo: https://github.com/PyCQA/isort - rev: '5.10.1' - hooks: - - id: isort - args: ['--profile=black'] - - repo: https://github.com/psf/black - rev: '22.3.0' - hooks: - - id: black - language_version: python3 - - repo: https://github.com/pycqa/flake8 - rev: '4.0.1' - hooks: - - id: flake8 diff --git a/api/Dockerfile b/api/Dockerfile deleted file mode 100644 index 3571f65..0000000 --- a/api/Dockerfile +++ /dev/null @@ -1,15 +0,0 @@ -FROM python:3.9 - -ARG APPENV=prod - -ENV DJANGO_SETTINGS_MODULE=drfboilerplate.settings.${APPENV} - -WORKDIR /code -COPY requirements.txt /code/requirements.txt -RUN pip install -r requirements.txt -RUN mkdir static -COPY . /code/ - -EXPOSE 8001 - -CMD gunicorn --bind=0.0.0.0:8001 --timeout=10 drfboilerplate.wsgi:application -k gevent --log-level=debug diff --git a/api/Makefile b/api/Makefile deleted file mode 100644 index 954f10e..0000000 --- a/api/Makefile +++ /dev/null @@ -1,42 +0,0 @@ -DC_FILE ?= docker-compose.yml - -build: - $(info ===> Building Docker image) - @docker-compose -f $(DC_FILE) build - -local: - $(info ===> Starting Docker containers) - @docker-compose -f $(DC_FILE) up - -shell: - @docker-compose -f $(DC_FILE) run --rm web python manage.py shell - -tests: - $(info ==> Running tests) - @docker-compose -f $(DC_FILE) run --rm web python manage.py test - -makemigrations: - $(info ==> Making migrations) - @docker-compose -f $(DC_FILE) run --rm web python manage.py makemigrations - -migrate: - $(info ==> Migrating) - @docker-compose -f $(DC_FILE) run --rm web python manage.py migrate - -collectstatic: - $(info ==> Collecting statics) - @docker-compose -f $(DC_FILE) run --rm web python manage.py collectstatic --noinput - -superuser: - @docker-compose -f $(DC_FILE) run --rm web python manage.py createsuperuser - -bash: - @docker-compose -f $(DC_FILE) run --rm web bash - -drop_db: - @docker-compose -f $(DC_FILE) rm -s -v db - rm -r db - -stop: - $(info ==> Stoping all containers) - @docker-compose -f $(DC_FILE) stop \ No newline at end of file diff --git a/api/README.md b/api/README.md deleted file mode 100644 index f2a94da..0000000 --- a/api/README.md +++ /dev/null @@ -1,40 +0,0 @@ -# Copbackend - -## Setup guide -1. Install docker and docker-compose. Look [here](https://docs.docker.com/desktop/) for docs -2. We're currently using `make` to build our app. It's installed by default in most of linux distros. For Windows users -it's more complicated. Look [here](https://stackoverflow.com/questions/32127524/how-to-install-and-use-make-in-windows) for more info. -In case you'll have a problem with `make` you can use commands defined in `makefile` directly. -3. Install pre-commit: -```shell -pre-commit install -``` -4. Now you're ready to build our app!!! Let's hop in: -```shell -make build -``` -5. Our App serves static files (css stylesheets, fonts, images and so on) we need to collect 'em. -This command would create a `static` directory. Look there if you're interested, what's inside ;) -```shell -make collectstatic -``` -6. It's time to create tables in database (docker container with database)! -```shell -make migrate -``` -7. Create superuser. -```shell -make superuser -``` -8. Start the app! -```shell -make local -``` -9. Open app on web browser `http://0.0.0.0:8001/admin/`. You can log in with superuser credentials. -## Start your adventure here! -Soon we'll give ya your first tasks, but now feel free to look around the project. We recommend to look on [swagger endpoint](http://0.0.0.0:8001/swagger/) as well as [admin page](http://0.0.0.0:8001/admin/). - -## Tips & tricks -1. Don't be afraid to ask questions. We're here to help ya! -2. Debug app with [Postman](https://www.postman.com/) or [Insomnia](https://insomnia.rest/) -3. If you're a student, you can use Pycharm Pro for free (and other amazing staff). Just enroll for [Github Student Pack](https://education.github.com/pack). diff --git a/api/drfboilerplate/__init__.py b/api/api/__init__.py similarity index 100% rename from api/drfboilerplate/__init__.py rename to api/api/__init__.py diff --git a/api/api/asgi.py b/api/api/asgi.py new file mode 100644 index 0000000..07b7545 --- /dev/null +++ b/api/api/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for api project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'api.settings') + +application = get_asgi_application() diff --git a/api/api/settings.py b/api/api/settings.py new file mode 100644 index 0000000..d6082e3 --- /dev/null +++ b/api/api/settings.py @@ -0,0 +1,123 @@ +""" +Django settings for api project. + +Generated by 'django-admin startproject' using Django 4.2.7. + +For more information on this file, see +https://docs.djangoproject.com/en/4.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/4.2/ref/settings/ +""" + +from pathlib import Path + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'django-insecure-#+s6&fgndq2-z2ou1rm@y32fj*0nw)-$_h7xxuc_bkemmdi+a@' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'api.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'api.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/4.2/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/4.2/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/4.2/howto/static-files/ + +STATIC_URL = 'static/' + +# Default primary key field type +# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/api/drfboilerplate/urls.py b/api/api/urls.py similarity index 50% rename from api/drfboilerplate/urls.py rename to api/api/urls.py index d60c17b..0f99e61 100644 --- a/api/drfboilerplate/urls.py +++ b/api/api/urls.py @@ -1,7 +1,8 @@ -"""copywriter URL Configuration +""" +URL configuration for api project. The `urlpatterns` list routes URLs to views. For more information please see: - https://docs.djangoproject.com/en/3.2/topics/http/urls/ + https://docs.djangoproject.com/en/4.2/topics/http/urls/ Examples: Function views 1. Add an import: from my_app import views @@ -14,22 +15,8 @@ 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin -from django.urls import include, path -from drf_spectacular.views import ( - SpectacularAPIView, - SpectacularRedocView, - SpectacularSwaggerView, -) +from django.urls import path urlpatterns = [ - path("admin/", admin.site.urls), - path("api-schema/", SpectacularAPIView.as_view(), name="api-schema"), - path( - "swagger/", - SpectacularSwaggerView.as_view(url_name="api-schema"), - name="swagger-ui", - ), - path( - "redoc/", SpectacularRedocView.as_view(url_name="api-schema"), name="redoc-ui" - ), + path('admin/', admin.site.urls), ] diff --git a/api/api/wsgi.py b/api/api/wsgi.py new file mode 100644 index 0000000..fba7ca8 --- /dev/null +++ b/api/api/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for api project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'api.settings') + +application = get_wsgi_application() diff --git a/api/docker-compose.yml b/api/docker-compose.yml deleted file mode 100644 index 176d62f..0000000 --- a/api/docker-compose.yml +++ /dev/null @@ -1,24 +0,0 @@ -version: "3.9" - -services: - db: - image: postgres - volumes: - - ./db:/var/lib/postgresql/data - env_file: - - .env - - web: - build: - context: . - args: - APPENV: "local" - command: gunicorn --bind=0.0.0.0:8001 --timeout=10 drfboilerplate.wsgi:application --log-level debug -k gevent --reload - env_file: - - .env - volumes: - - .:/code - ports: - - "8001:8001" - depends_on: - - db diff --git a/api/drfboilerplate/settings/__init__.py b/api/drfboilerplate/settings/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/api/drfboilerplate/settings/ci-tests.py b/api/drfboilerplate/settings/ci-tests.py deleted file mode 100644 index 26a90d3..0000000 --- a/api/drfboilerplate/settings/ci-tests.py +++ /dev/null @@ -1,16 +0,0 @@ -""" -Django settings for copywriter project. - -Generated by 'django-admin startproject' using Django 3.2.7. - -For more information on this file, see -https://docs.djangoproject.com/en/3.2/topics/settings/ - -For the full list of settings and their values, see -https://docs.djangoproject.com/en/3.2/ref/settings/ -""" -from drfboilerplate.settings.prod import * # noqa: F403, F401 - -DEBUG = True - -DATABASES = {"default": {"ENGINE": "django.db.backends.sqlite3"}} diff --git a/api/drfboilerplate/settings/dev.py b/api/drfboilerplate/settings/dev.py deleted file mode 100644 index 3488cbd..0000000 --- a/api/drfboilerplate/settings/dev.py +++ /dev/null @@ -1,4 +0,0 @@ -from drfboilerplate.settings.prod import * # noqa: F403, F401 - -DEBUG = True -CORS_ALLOWED_ORIGINS = [] diff --git a/api/drfboilerplate/settings/local.py b/api/drfboilerplate/settings/local.py deleted file mode 100644 index 716f7db..0000000 --- a/api/drfboilerplate/settings/local.py +++ /dev/null @@ -1,4 +0,0 @@ -from drfboilerplate.settings.prod import * # noqa: F403, F401 - -DEBUG = True -CORS_ALLOW_ALL_ORIGINS = True diff --git a/api/drfboilerplate/settings/prod.py b/api/drfboilerplate/settings/prod.py deleted file mode 100644 index 770c7cd..0000000 --- a/api/drfboilerplate/settings/prod.py +++ /dev/null @@ -1,137 +0,0 @@ -from datetime import timedelta -from pathlib import Path - -import environ - -env = environ.Env() - -DATABASES = { - "default": { - "ENGINE": "django.db.backends.postgresql", - "NAME": env("POSTGRES_DB", default="copbackend"), - "USER": env("POSTGRES_USER", default="copbackend"), - "PASSWORD": env("POSTGRES_PASSWORD", default=None), - "HOST": env("POSTGRES_HOST", default="localhost"), - "PORT": 5432, - } -} - -DEBUG = False - -BASE_DIR = Path(__file__).resolve().parent.parent.parent - -# SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = env("SECRET_KEY", default="DEFAULT_SECRET_KEY_CHANGE_ME") - -ALLOWED_HOSTS = ["*"] - -# Application definition - -INSTALLED_APPS = [ - "django.contrib.admin", - "django.contrib.auth", - "django.contrib.contenttypes", - "django.contrib.sessions", - "django.contrib.messages", - "django.contrib.staticfiles", - "corsheaders", - "drf_spectacular", - "rest_framework", - "rest_framework_simplejwt", - "django_filters", -] - -REST_FRAMEWORK = { - "DEFAULT_PERMISSION_CLASSES": ("rest_framework.permissions.IsAuthenticated",), - "DEFAULT_AUTHENTICATION_CLASSES": ( - "rest_framework_simplejwt.authentication.JWTAuthentication", - ), - "DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema", -} - -SPECTACULAR_SETTINGS = { - "TITLE": "Change Here!!", - "DESCRIPTION": "Change Here!!", - "VERSION": "1.0.0", - "SERVERS": [ - {"url": "/", "description": "Local"}, - ], -} - -SIMPLE_JWT = { - "ACCESS_TOKEN_LIFETIME": timedelta(hours=24), - "REFRESH_TOKEN_LIFETIME": timedelta(days=7), -} -MIDDLEWARE = [ - "corsheaders.middleware.CorsMiddleware", - "django.middleware.security.SecurityMiddleware", - "django.contrib.sessions.middleware.SessionMiddleware", - "django.middleware.common.CommonMiddleware", - "django.middleware.csrf.CsrfViewMiddleware", - "django.contrib.auth.middleware.AuthenticationMiddleware", - "django.contrib.messages.middleware.MessageMiddleware", - "django.middleware.clickjacking.XFrameOptionsMiddleware", -] - -ROOT_URLCONF = "drfboilerplate.urls" - -TEMPLATES = [ - { - "BACKEND": "django.template.backends.django.DjangoTemplates", - "DIRS": [BASE_DIR / "templates"], - "APP_DIRS": True, - "OPTIONS": { - "context_processors": [ - "django.template.context_processors.debug", - "django.template.context_processors.request", - "django.contrib.auth.context_processors.auth", - "django.contrib.messages.context_processors.messages", - ], - }, - }, -] - -WSGI_APPLICATION = "drfboilerplate.wsgi.application" - -# Password validation -# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators -AUTH_PASSWORD_VALIDATORS = [ - { - "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", - }, - { - "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", - }, - { - "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", - }, - { - "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", - }, -] - -# Internationalization -# https://docs.djangoproject.com/en/3.2/topics/i18n/ - -LANGUAGE_CODE = "pl" - -TIME_ZONE = "Europe/Warsaw" - -USE_I18N = True - -USE_L10N = True - -USE_TZ = True - -CORS_ALLOWED_ORIGINS = ["http://localhost"] - -# Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/3.2/howto/static-files/ - -STATIC_URL = "/static/" -STATIC_ROOT = BASE_DIR / "static" - -# Default primary key field type -# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field - -DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" diff --git a/api/drfboilerplate/wsgi.py b/api/drfboilerplate/wsgi.py deleted file mode 100644 index 4f65a13..0000000 --- a/api/drfboilerplate/wsgi.py +++ /dev/null @@ -1,17 +0,0 @@ -""" -WSGI config for copywriter project. - -It exposes the WSGI callable as a module-level variable named ``application``. - -For more information on this file, see -https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/ -""" - -import os - -from django.contrib.staticfiles.handlers import StaticFilesHandler -from django.core.wsgi import get_wsgi_application - -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "drfboilerplate.settings") - -application = StaticFilesHandler(get_wsgi_application()) diff --git a/api/manage.py b/api/manage.py index 791fc32..8c45ccf 100755 --- a/api/manage.py +++ b/api/manage.py @@ -6,7 +6,7 @@ def main(): """Run administrative tasks.""" - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "copywriter.settings") + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'api.settings') try: from django.core.management import execute_from_command_line except ImportError as exc: @@ -18,5 +18,5 @@ def main(): execute_from_command_line(sys.argv) -if __name__ == "__main__": +if __name__ == '__main__': main() diff --git a/api/poetry.lock b/api/poetry.lock new file mode 100644 index 0000000..4b847d9 --- /dev/null +++ b/api/poetry.lock @@ -0,0 +1,67 @@ +# This file is automatically @generated by Poetry 1.6.1 and should not be changed by hand. + +[[package]] +name = "asgiref" +version = "3.7.2" +description = "ASGI specs, helper code, and adapters" +optional = false +python-versions = ">=3.7" +files = [ + {file = "asgiref-3.7.2-py3-none-any.whl", hash = "sha256:89b2ef2247e3b562a16eef663bc0e2e703ec6468e2fa8a5cd61cd449786d4f6e"}, + {file = "asgiref-3.7.2.tar.gz", hash = "sha256:9e0ce3aa93a819ba5b45120216b23878cf6e8525eb3848653452b4192b92afed"}, +] + +[package.extras] +tests = ["mypy (>=0.800)", "pytest", "pytest-asyncio"] + +[[package]] +name = "django" +version = "4.2.7" +description = "A high-level Python web framework that encourages rapid development and clean, pragmatic design." +optional = false +python-versions = ">=3.8" +files = [ + {file = "Django-4.2.7-py3-none-any.whl", hash = "sha256:e1d37c51ad26186de355cbcec16613ebdabfa9689bbade9c538835205a8abbe9"}, + {file = "Django-4.2.7.tar.gz", hash = "sha256:8e0f1c2c2786b5c0e39fe1afce24c926040fad47c8ea8ad30aaf1188df29fc41"}, +] + +[package.dependencies] +asgiref = ">=3.6.0,<4" +sqlparse = ">=0.3.1" +tzdata = {version = "*", markers = "sys_platform == \"win32\""} + +[package.extras] +argon2 = ["argon2-cffi (>=19.1.0)"] +bcrypt = ["bcrypt"] + +[[package]] +name = "sqlparse" +version = "0.4.4" +description = "A non-validating SQL parser." +optional = false +python-versions = ">=3.5" +files = [ + {file = "sqlparse-0.4.4-py3-none-any.whl", hash = "sha256:5430a4fe2ac7d0f93e66f1efc6e1338a41884b7ddf2a350cedd20ccc4d9d28f3"}, + {file = "sqlparse-0.4.4.tar.gz", hash = "sha256:d446183e84b8349fa3061f0fe7f06ca94ba65b426946ffebe6e3e8295332420c"}, +] + +[package.extras] +dev = ["build", "flake8"] +doc = ["sphinx"] +test = ["pytest", "pytest-cov"] + +[[package]] +name = "tzdata" +version = "2023.3" +description = "Provider of IANA time zone data" +optional = false +python-versions = ">=2" +files = [ + {file = "tzdata-2023.3-py2.py3-none-any.whl", hash = "sha256:7e65763eef3120314099b6939b5546db7adce1e7d6f2e179e3df563c70511eda"}, + {file = "tzdata-2023.3.tar.gz", hash = "sha256:11ef1e08e54acb0d4f95bdb1be05da659673de4acbd21bf9c69e94cc5e907a3a"}, +] + +[metadata] +lock-version = "2.0" +python-versions = "^3.11" +content-hash = "0c7456b1da4abfc30e2a13ef3e09075af3fdff7fcbaeb51ca3177b4349d7ac99" diff --git a/api/pyproject.toml b/api/pyproject.toml index 55ec8d7..1a2c26f 100644 --- a/api/pyproject.toml +++ b/api/pyproject.toml @@ -1,2 +1,15 @@ -[tool.black] -line-length = 120 +[tool.poetry] +name = "api" +version = "0.1.0" +description = "" +authors = ["MikoĊaj Data <miki3867@gmail.com>"] +readme = "README.md" + +[tool.poetry.dependencies] +python = "^3.11" +django = "^4.2.7" + + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" diff --git a/api/requirements.txt b/api/requirements.txt deleted file mode 100644 index 02c7fa2..0000000 --- a/api/requirements.txt +++ /dev/null @@ -1,47 +0,0 @@ -asgiref==3.4.1 -backports.entry-points-selectable==1.1.0 -certifi==2021.10.8 -cfgv==3.3.1 -charset-normalizer==2.0.7 -coreapi==2.3.3 -coreschema==0.0.4 -distlib==0.3.3 -Django==3.2.7 -django-environ==0.7.0 -djangorestframework==3.12.4 -djangorestframework-simplejwt==5.0.0 -filelock==3.3.2 -future==0.18.2 -gunicorn[gevent] == 20.1.0 -identify==2.3.1 -idna==3.3 -inflection==0.5.1 -itypes==1.2.0 -Jinja2==3.0.2 -MarkupSafe==2.0.1 -nodeenv==1.6.0 -packaging==21.2 -platformdirs==2.4.0 -pre-commit==2.15.0 -psycopg2-binary==2.9.1 -PyJWT==2.3.0 -pyparsing==2.4.7 -pytz==2021.1 -PyYAML==6.0 -requests==2.26.0 -ruamel.yaml==0.17.16 -ruamel.yaml.clib==0.2.6 -six==1.16.0 -sqlparse==0.4.2 -toml==0.10.2 -uritemplate==4.1.1 -urllib3==1.26.7 -virtualenv==20.9.0 -django-cors-headers==3.11.0 -django-filter~=21.1 -drf-extra-fields==3.2.1 -django-ordered-model==3.5 -drf-extensions==0.7.1 -drf-spectacular==0.21.2 -python-dateutil==2.8.2 -parameterized==0.8.1 \ No newline at end of file diff --git a/api/setup.cfg b/api/setup.cfg deleted file mode 100644 index 6deafc2..0000000 --- a/api/setup.cfg +++ /dev/null @@ -1,2 +0,0 @@ -[flake8] -max-line-length = 120 diff --git a/api/tests/__init__.py b/api/tests/__init__.py deleted file mode 100644 index e69de29..0000000 From 41caec18590dc9b68cb46b17ee80176e8f2fb7cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Data?= <miki3867@gmail.com> Date: Sat, 2 Dec 2023 13:35:10 +0100 Subject: [PATCH 3/8] Make django working --- api/.gitignore | 1 + api/Dockerfile | 26 ++++++++ api/api/asgi.py | 19 ++---- api/api/settings.py | 90 ++++++++++++------------- api/poetry.lock | 156 +++++++++++++++++++++++++++++++++++++++++++- api/pyproject.toml | 3 + docker-compose.yml | 43 ++++++++---- 7 files changed, 264 insertions(+), 74 deletions(-) create mode 100644 api/.gitignore create mode 100644 api/Dockerfile diff --git a/api/.gitignore b/api/.gitignore new file mode 100644 index 0000000..c18dd8d --- /dev/null +++ b/api/.gitignore @@ -0,0 +1 @@ +__pycache__/ diff --git a/api/Dockerfile b/api/Dockerfile new file mode 100644 index 0000000..d2901ae --- /dev/null +++ b/api/Dockerfile @@ -0,0 +1,26 @@ +FROM python:3.11-buster as builder + +RUN pip install poetry==1.6.1 + +ENV POETRY_NO_INTERACTION=1 \ + POETRY_VIRTUALENVS_IN_PROJECT=1 \ + POETRY_VIRTUALENVS_CREATE=1 \ + POETRY_CACHE_DIR=/tmp/poetry_cache + +WORKDIR /app + +COPY pyproject.toml poetry.lock ./ +RUN touch README.md + +RUN --mount=type=cache,target=$POETRY_CACHE_DIR poetry install --no-root + +FROM python:3.11-slim-buster as runtime + +ENV VIRTUAL_ENV=/app/.venv \ + PATH="/app/.venv/bin:$PATH" + +COPY --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV} + +COPY . ./ + +ENTRYPOINT ["uvicorn", "api.asgi:application", "--host", "0.0.0.0"] diff --git a/api/api/asgi.py b/api/api/asgi.py index 07b7545..66c43c3 100644 --- a/api/api/asgi.py +++ b/api/api/asgi.py @@ -1,16 +1,11 @@ -""" -ASGI config for api project. - -It exposes the ASGI callable as a module-level variable named ``application``. - -For more information on this file, see -https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/ -""" - import os - from django.core.asgi import get_asgi_application +from channels.routing import ProtocolTypeRouter, URLRouter -os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'api.settings') +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "api.settings") -application = get_asgi_application() +application = ProtocolTypeRouter( + { + "http": get_asgi_application(), + } +) diff --git a/api/api/settings.py b/api/api/settings.py index d6082e3..8e5b9f6 100644 --- a/api/api/settings.py +++ b/api/api/settings.py @@ -1,15 +1,3 @@ -""" -Django settings for api project. - -Generated by 'django-admin startproject' using Django 4.2.7. - -For more information on this file, see -https://docs.djangoproject.com/en/4.2/topics/settings/ - -For the full list of settings and their values, see -https://docs.djangoproject.com/en/4.2/ref/settings/ -""" - from pathlib import Path # Build paths inside the project like this: BASE_DIR / 'subdir'. @@ -20,63 +8,67 @@ # See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = 'django-insecure-#+s6&fgndq2-z2ou1rm@y32fj*0nw)-$_h7xxuc_bkemmdi+a@' +SECRET_KEY = "django-insecure-#+s6&fgndq2-z2ou1rm@y32fj*0nw)-$_h7xxuc_bkemmdi+a@" # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = ["0.0.0.0"] # Application definition INSTALLED_APPS = [ - 'django.contrib.admin', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.messages', - 'django.contrib.staticfiles', + "django.contrib.admin", + "django.contrib.auth", + "django.contrib.contenttypes", + "django.contrib.sessions", + "django.contrib.messages", + "django.contrib.staticfiles", ] MIDDLEWARE = [ - 'django.middleware.security.SecurityMiddleware', - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.middleware.common.CommonMiddleware', - 'django.middleware.csrf.CsrfViewMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.messages.middleware.MessageMiddleware', - 'django.middleware.clickjacking.XFrameOptionsMiddleware', + "django.middleware.security.SecurityMiddleware", + "django.contrib.sessions.middleware.SessionMiddleware", + "django.middleware.common.CommonMiddleware", + "django.middleware.csrf.CsrfViewMiddleware", + "django.contrib.auth.middleware.AuthenticationMiddleware", + "django.contrib.messages.middleware.MessageMiddleware", + "django.middleware.clickjacking.XFrameOptionsMiddleware", ] -ROOT_URLCONF = 'api.urls' +ROOT_URLCONF = "api.urls" TEMPLATES = [ { - 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [], - 'APP_DIRS': True, - 'OPTIONS': { - 'context_processors': [ - 'django.template.context_processors.debug', - 'django.template.context_processors.request', - 'django.contrib.auth.context_processors.auth', - 'django.contrib.messages.context_processors.messages', + "BACKEND": "django.template.backends.django.DjangoTemplates", + "DIRS": [], + "APP_DIRS": True, + "OPTIONS": { + "context_processors": [ + "django.template.context_processors.debug", + "django.template.context_processors.request", + "django.contrib.auth.context_processors.auth", + "django.contrib.messages.context_processors.messages", ], }, }, ] -WSGI_APPLICATION = 'api.wsgi.application' +WSGI_APPLICATION = "api.wsgi.application" # Database # https://docs.djangoproject.com/en/4.2/ref/settings/#databases DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': BASE_DIR / 'db.sqlite3', + "default": { + "ENGINE": "django.db.backends.postgresql", + "NAME": "db_name", + "USER": "db_user", + "PASSWORD": "db_user_password", + "HOST": "", + "PORT": "111", } } @@ -86,16 +78,16 @@ AUTH_PASSWORD_VALIDATORS = [ { - 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", }, { - 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", }, { - 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", }, { - 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", }, ] @@ -103,9 +95,9 @@ # Internationalization # https://docs.djangoproject.com/en/4.2/topics/i18n/ -LANGUAGE_CODE = 'en-us' +LANGUAGE_CODE = "en-us" -TIME_ZONE = 'UTC' +TIME_ZONE = "UTC" USE_I18N = True @@ -115,9 +107,9 @@ # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/4.2/howto/static-files/ -STATIC_URL = 'static/' +STATIC_URL = "static/" # Default primary key field type # https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field -DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' +DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" diff --git a/api/poetry.lock b/api/poetry.lock index 4b847d9..f95ab80 100644 --- a/api/poetry.lock +++ b/api/poetry.lock @@ -14,6 +14,50 @@ files = [ [package.extras] tests = ["mypy (>=0.800)", "pytest", "pytest-asyncio"] +[[package]] +name = "channels" +version = "4.0.0" +description = "Brings async, event-driven capabilities to Django 3.2 and up." +optional = false +python-versions = ">=3.7" +files = [ + {file = "channels-4.0.0-py3-none-any.whl", hash = "sha256:2253334ac76f67cba68c2072273f7e0e67dbdac77eeb7e318f511d2f9a53c5e4"}, + {file = "channels-4.0.0.tar.gz", hash = "sha256:0ce53507a7da7b148eaa454526e0e05f7da5e5d1c23440e4886cf146981d8420"}, +] + +[package.dependencies] +asgiref = ">=3.5.0,<4" +Django = ">=3.2" + +[package.extras] +daphne = ["daphne (>=4.0.0)"] +tests = ["async-timeout", "coverage (>=4.5,<5.0)", "pytest", "pytest-asyncio", "pytest-django"] + +[[package]] +name = "click" +version = "8.1.7" +description = "Composable command line interface toolkit" +optional = false +python-versions = ">=3.7" +files = [ + {file = "click-8.1.7-py3-none-any.whl", hash = "sha256:ae74fb96c20a0277a1d615f1e4d73c8414f5a98db8b799a7931d1582f3390c28"}, + {file = "click-8.1.7.tar.gz", hash = "sha256:ca9853ad459e787e2192211578cc907e7594e294c7ccc834310722b41b9ca6de"}, +] + +[package.dependencies] +colorama = {version = "*", markers = "platform_system == \"Windows\""} + +[[package]] +name = "colorama" +version = "0.4.6" +description = "Cross-platform colored terminal text." +optional = false +python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" +files = [ + {file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"}, + {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, +] + [[package]] name = "django" version = "4.2.7" @@ -34,6 +78,98 @@ tzdata = {version = "*", markers = "sys_platform == \"win32\""} argon2 = ["argon2-cffi (>=19.1.0)"] bcrypt = ["bcrypt"] +[[package]] +name = "h11" +version = "0.14.0" +description = "A pure-Python, bring-your-own-I/O implementation of HTTP/1.1" +optional = false +python-versions = ">=3.7" +files = [ + {file = "h11-0.14.0-py3-none-any.whl", hash = "sha256:e3fe4ac4b851c468cc8363d500db52c2ead036020723024a109d37346efaa761"}, + {file = "h11-0.14.0.tar.gz", hash = "sha256:8f19fbbe99e72420ff35c00b27a34cb9937e902a8b810e2c88300c6f0a3b699d"}, +] + +[[package]] +name = "psycopg2-binary" +version = "2.9.9" +description = "psycopg2 - Python-PostgreSQL Database Adapter" +optional = false +python-versions = ">=3.7" +files = [ + {file = "psycopg2-binary-2.9.9.tar.gz", hash = "sha256:7f01846810177d829c7692f1f5ada8096762d9172af1b1a28d4ab5b77c923c1c"}, + {file = "psycopg2_binary-2.9.9-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:c2470da5418b76232f02a2fcd2229537bb2d5a7096674ce61859c3229f2eb202"}, + {file = "psycopg2_binary-2.9.9-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:c6af2a6d4b7ee9615cbb162b0738f6e1fd1f5c3eda7e5da17861eacf4c717ea7"}, + {file = "psycopg2_binary-2.9.9-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:75723c3c0fbbf34350b46a3199eb50638ab22a0228f93fb472ef4d9becc2382b"}, + {file = "psycopg2_binary-2.9.9-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:83791a65b51ad6ee6cf0845634859d69a038ea9b03d7b26e703f94c7e93dbcf9"}, + {file = "psycopg2_binary-2.9.9-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:0ef4854e82c09e84cc63084a9e4ccd6d9b154f1dbdd283efb92ecd0b5e2b8c84"}, + {file = "psycopg2_binary-2.9.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ed1184ab8f113e8d660ce49a56390ca181f2981066acc27cf637d5c1e10ce46e"}, + {file = "psycopg2_binary-2.9.9-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:d2997c458c690ec2bc6b0b7ecbafd02b029b7b4283078d3b32a852a7ce3ddd98"}, + {file = "psycopg2_binary-2.9.9-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:b58b4710c7f4161b5e9dcbe73bb7c62d65670a87df7bcce9e1faaad43e715245"}, + {file = "psycopg2_binary-2.9.9-cp310-cp310-musllinux_1_1_ppc64le.whl", hash = "sha256:0c009475ee389757e6e34611d75f6e4f05f0cf5ebb76c6037508318e1a1e0d7e"}, + {file = "psycopg2_binary-2.9.9-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:8dbf6d1bc73f1d04ec1734bae3b4fb0ee3cb2a493d35ede9badbeb901fb40f6f"}, + {file = "psycopg2_binary-2.9.9-cp310-cp310-win32.whl", hash = "sha256:3f78fd71c4f43a13d342be74ebbc0666fe1f555b8837eb113cb7416856c79682"}, + {file = "psycopg2_binary-2.9.9-cp310-cp310-win_amd64.whl", hash = "sha256:876801744b0dee379e4e3c38b76fc89f88834bb15bf92ee07d94acd06ec890a0"}, + {file = "psycopg2_binary-2.9.9-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:ee825e70b1a209475622f7f7b776785bd68f34af6e7a46e2e42f27b659b5bc26"}, + {file = "psycopg2_binary-2.9.9-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:1ea665f8ce695bcc37a90ee52de7a7980be5161375d42a0b6c6abedbf0d81f0f"}, + {file = "psycopg2_binary-2.9.9-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:143072318f793f53819048fdfe30c321890af0c3ec7cb1dfc9cc87aa88241de2"}, + {file = "psycopg2_binary-2.9.9-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:c332c8d69fb64979ebf76613c66b985414927a40f8defa16cf1bc028b7b0a7b0"}, + {file = "psycopg2_binary-2.9.9-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:f7fc5a5acafb7d6ccca13bfa8c90f8c51f13d8fb87d95656d3950f0158d3ce53"}, + {file = "psycopg2_binary-2.9.9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:977646e05232579d2e7b9c59e21dbe5261f403a88417f6a6512e70d3f8a046be"}, + {file = "psycopg2_binary-2.9.9-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:b6356793b84728d9d50ead16ab43c187673831e9d4019013f1402c41b1db9b27"}, + {file = "psycopg2_binary-2.9.9-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:bc7bb56d04601d443f24094e9e31ae6deec9ccb23581f75343feebaf30423359"}, + {file = "psycopg2_binary-2.9.9-cp311-cp311-musllinux_1_1_ppc64le.whl", hash = "sha256:77853062a2c45be16fd6b8d6de2a99278ee1d985a7bd8b103e97e41c034006d2"}, + {file = "psycopg2_binary-2.9.9-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:78151aa3ec21dccd5cdef6c74c3e73386dcdfaf19bced944169697d7ac7482fc"}, + {file = "psycopg2_binary-2.9.9-cp311-cp311-win32.whl", hash = "sha256:dc4926288b2a3e9fd7b50dc6a1909a13bbdadfc67d93f3374d984e56f885579d"}, + {file = "psycopg2_binary-2.9.9-cp311-cp311-win_amd64.whl", hash = "sha256:b76bedd166805480ab069612119ea636f5ab8f8771e640ae103e05a4aae3e417"}, + {file = "psycopg2_binary-2.9.9-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:8532fd6e6e2dc57bcb3bc90b079c60de896d2128c5d9d6f24a63875a95a088cf"}, + {file = "psycopg2_binary-2.9.9-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:b0605eaed3eb239e87df0d5e3c6489daae3f7388d455d0c0b4df899519c6a38d"}, + {file = "psycopg2_binary-2.9.9-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:8f8544b092a29a6ddd72f3556a9fcf249ec412e10ad28be6a0c0d948924f2212"}, + {file = "psycopg2_binary-2.9.9-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:2d423c8d8a3c82d08fe8af900ad5b613ce3632a1249fd6a223941d0735fce493"}, + {file = "psycopg2_binary-2.9.9-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:2e5afae772c00980525f6d6ecf7cbca55676296b580c0e6abb407f15f3706996"}, + {file = "psycopg2_binary-2.9.9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6e6f98446430fdf41bd36d4faa6cb409f5140c1c2cf58ce0bbdaf16af7d3f119"}, + {file = "psycopg2_binary-2.9.9-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:c77e3d1862452565875eb31bdb45ac62502feabbd53429fdc39a1cc341d681ba"}, + {file = "psycopg2_binary-2.9.9-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:cb16c65dcb648d0a43a2521f2f0a2300f40639f6f8c1ecbc662141e4e3e1ee07"}, + {file = "psycopg2_binary-2.9.9-cp312-cp312-musllinux_1_1_ppc64le.whl", hash = "sha256:911dda9c487075abd54e644ccdf5e5c16773470a6a5d3826fda76699410066fb"}, + {file = "psycopg2_binary-2.9.9-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:57fede879f08d23c85140a360c6a77709113efd1c993923c59fde17aa27599fe"}, + {file = "psycopg2_binary-2.9.9-cp312-cp312-win32.whl", hash = "sha256:64cf30263844fa208851ebb13b0732ce674d8ec6a0c86a4e160495d299ba3c93"}, + {file = "psycopg2_binary-2.9.9-cp312-cp312-win_amd64.whl", hash = "sha256:81ff62668af011f9a48787564ab7eded4e9fb17a4a6a74af5ffa6a457400d2ab"}, + {file = "psycopg2_binary-2.9.9-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:2293b001e319ab0d869d660a704942c9e2cce19745262a8aba2115ef41a0a42a"}, + {file = "psycopg2_binary-2.9.9-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:03ef7df18daf2c4c07e2695e8cfd5ee7f748a1d54d802330985a78d2a5a6dca9"}, + {file = "psycopg2_binary-2.9.9-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:0a602ea5aff39bb9fac6308e9c9d82b9a35c2bf288e184a816002c9fae930b77"}, + {file = "psycopg2_binary-2.9.9-cp37-cp37m-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:8359bf4791968c5a78c56103702000105501adb557f3cf772b2c207284273984"}, + {file = "psycopg2_binary-2.9.9-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:275ff571376626195ab95a746e6a04c7df8ea34638b99fc11160de91f2fef503"}, + {file = "psycopg2_binary-2.9.9-cp37-cp37m-musllinux_1_1_aarch64.whl", hash = "sha256:f9b5571d33660d5009a8b3c25dc1db560206e2d2f89d3df1cb32d72c0d117d52"}, + {file = "psycopg2_binary-2.9.9-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:420f9bbf47a02616e8554e825208cb947969451978dceb77f95ad09c37791dae"}, + {file = "psycopg2_binary-2.9.9-cp37-cp37m-musllinux_1_1_ppc64le.whl", hash = "sha256:4154ad09dac630a0f13f37b583eae260c6aa885d67dfbccb5b02c33f31a6d420"}, + {file = "psycopg2_binary-2.9.9-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:a148c5d507bb9b4f2030a2025c545fccb0e1ef317393eaba42e7eabd28eb6041"}, + {file = "psycopg2_binary-2.9.9-cp37-cp37m-win32.whl", hash = "sha256:68fc1f1ba168724771e38bee37d940d2865cb0f562380a1fb1ffb428b75cb692"}, + {file = "psycopg2_binary-2.9.9-cp37-cp37m-win_amd64.whl", hash = "sha256:281309265596e388ef483250db3640e5f414168c5a67e9c665cafce9492eda2f"}, + {file = "psycopg2_binary-2.9.9-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:60989127da422b74a04345096c10d416c2b41bd7bf2a380eb541059e4e999980"}, + {file = "psycopg2_binary-2.9.9-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:246b123cc54bb5361588acc54218c8c9fb73068bf227a4a531d8ed56fa3ca7d6"}, + {file = "psycopg2_binary-2.9.9-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:34eccd14566f8fe14b2b95bb13b11572f7c7d5c36da61caf414d23b91fcc5d94"}, + {file = "psycopg2_binary-2.9.9-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:18d0ef97766055fec15b5de2c06dd8e7654705ce3e5e5eed3b6651a1d2a9a152"}, + {file = "psycopg2_binary-2.9.9-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:d3f82c171b4ccd83bbaf35aa05e44e690113bd4f3b7b6cc54d2219b132f3ae55"}, + {file = "psycopg2_binary-2.9.9-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ead20f7913a9c1e894aebe47cccf9dc834e1618b7aa96155d2091a626e59c972"}, + {file = "psycopg2_binary-2.9.9-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:ca49a8119c6cbd77375ae303b0cfd8c11f011abbbd64601167ecca18a87e7cdd"}, + {file = "psycopg2_binary-2.9.9-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:323ba25b92454adb36fa425dc5cf6f8f19f78948cbad2e7bc6cdf7b0d7982e59"}, + {file = "psycopg2_binary-2.9.9-cp38-cp38-musllinux_1_1_ppc64le.whl", hash = "sha256:1236ed0952fbd919c100bc839eaa4a39ebc397ed1c08a97fc45fee2a595aa1b3"}, + {file = "psycopg2_binary-2.9.9-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:729177eaf0aefca0994ce4cffe96ad3c75e377c7b6f4efa59ebf003b6d398716"}, + {file = "psycopg2_binary-2.9.9-cp38-cp38-win32.whl", hash = "sha256:804d99b24ad523a1fe18cc707bf741670332f7c7412e9d49cb5eab67e886b9b5"}, + {file = "psycopg2_binary-2.9.9-cp38-cp38-win_amd64.whl", hash = "sha256:a6cdcc3ede532f4a4b96000b6362099591ab4a3e913d70bcbac2b56c872446f7"}, + {file = "psycopg2_binary-2.9.9-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:72dffbd8b4194858d0941062a9766f8297e8868e1dd07a7b36212aaa90f49472"}, + {file = "psycopg2_binary-2.9.9-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:30dcc86377618a4c8f3b72418df92e77be4254d8f89f14b8e8f57d6d43603c0f"}, + {file = "psycopg2_binary-2.9.9-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:31a34c508c003a4347d389a9e6fcc2307cc2150eb516462a7a17512130de109e"}, + {file = "psycopg2_binary-2.9.9-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:15208be1c50b99203fe88d15695f22a5bed95ab3f84354c494bcb1d08557df67"}, + {file = "psycopg2_binary-2.9.9-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:1873aade94b74715be2246321c8650cabf5a0d098a95bab81145ffffa4c13876"}, + {file = "psycopg2_binary-2.9.9-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3a58c98a7e9c021f357348867f537017057c2ed7f77337fd914d0bedb35dace7"}, + {file = "psycopg2_binary-2.9.9-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:4686818798f9194d03c9129a4d9a702d9e113a89cb03bffe08c6cf799e053291"}, + {file = "psycopg2_binary-2.9.9-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:ebdc36bea43063116f0486869652cb2ed7032dbc59fbcb4445c4862b5c1ecf7f"}, + {file = "psycopg2_binary-2.9.9-cp39-cp39-musllinux_1_1_ppc64le.whl", hash = "sha256:ca08decd2697fdea0aea364b370b1249d47336aec935f87b8bbfd7da5b2ee9c1"}, + {file = "psycopg2_binary-2.9.9-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:ac05fb791acf5e1a3e39402641827780fe44d27e72567a000412c648a85ba860"}, + {file = "psycopg2_binary-2.9.9-cp39-cp39-win32.whl", hash = "sha256:9dba73be7305b399924709b91682299794887cbbd88e38226ed9f6712eabee90"}, + {file = "psycopg2_binary-2.9.9-cp39-cp39-win_amd64.whl", hash = "sha256:f7ae5d65ccfbebdfa761585228eb4d0df3a8b15cfb53bd953e713e09fbb12957"}, +] + [[package]] name = "sqlparse" version = "0.4.4" @@ -61,7 +197,25 @@ files = [ {file = "tzdata-2023.3.tar.gz", hash = "sha256:11ef1e08e54acb0d4f95bdb1be05da659673de4acbd21bf9c69e94cc5e907a3a"}, ] +[[package]] +name = "uvicorn" +version = "0.24.0.post1" +description = "The lightning-fast ASGI server." +optional = false +python-versions = ">=3.8" +files = [ + {file = "uvicorn-0.24.0.post1-py3-none-any.whl", hash = "sha256:7c84fea70c619d4a710153482c0d230929af7bcf76c7bfa6de151f0a3a80121e"}, + {file = "uvicorn-0.24.0.post1.tar.gz", hash = "sha256:09c8e5a79dc466bdf28dead50093957db184de356fcdc48697bad3bde4c2588e"}, +] + +[package.dependencies] +click = ">=7.0" +h11 = ">=0.8" + +[package.extras] +standard = ["colorama (>=0.4)", "httptools (>=0.5.0)", "python-dotenv (>=0.13)", "pyyaml (>=5.1)", "uvloop (>=0.14.0,!=0.15.0,!=0.15.1)", "watchfiles (>=0.13)", "websockets (>=10.4)"] + [metadata] lock-version = "2.0" python-versions = "^3.11" -content-hash = "0c7456b1da4abfc30e2a13ef3e09075af3fdff7fcbaeb51ca3177b4349d7ac99" +content-hash = "ed64499590a165c62379abc1d18f850c8213c56f3d48c2b3d69d541697626803" diff --git a/api/pyproject.toml b/api/pyproject.toml index 1a2c26f..c13e1ed 100644 --- a/api/pyproject.toml +++ b/api/pyproject.toml @@ -8,6 +8,9 @@ readme = "README.md" [tool.poetry.dependencies] python = "^3.11" django = "^4.2.7" +uvicorn = "^0.24.0.post1" +channels = "^4.0.0" +psycopg2-binary = "^2.9.9" [build-system] diff --git a/docker-compose.yml b/docker-compose.yml index f3c3f49..75b9944 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,17 +3,36 @@ services: build: ./discord env_file: .env - embedding-api: - image: michaelf34/infinity:latest - command: "--model-name-or-path /models/e5-large-v2 --port 80" + # embedding-api: + # image: michaelf34/infinity:latest + # command: "--model-name-or-path /models/e5-large-v2 --port 80" + # volumes: + # - ./models:/models + # ports: + # - 5001:80 + # deploy: + # resources: + # reservations: + # devices: + # - driver: nvidia + # count: 1 + # capabilities: [gpu] + + db: + image: postgres volumes: - - ./models:/models + - ./db:/var/lib/postgresql/data + env_file: + - .env + + api: + build: + context: ./api/ + env_file: + - .env + volumes: + - .:/code ports: - - 5001:80 - deploy: - resources: - reservations: - devices: - - driver: nvidia - count: 1 - capabilities: [gpu] + - "8000:8000" + depends_on: + - db From b7f9f52b47ef0590522bf6fee817a72cc1e4d9ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Data?= <miki3867@gmail.com> Date: Sat, 2 Dec 2023 13:38:54 +0100 Subject: [PATCH 4/8] Uncomment embeding api. Add db/ to .gitignore --- .gitignore | 4 +--- docker-compose.yml | 28 ++++++++++++++-------------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index a1e95e2..d01b965 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,5 @@ .env -<<<<<<< HEAD *.bin -======= .envrc models/** ->>>>>>> 7cfb49cc2091ad67aecf2d1de7dfd5bbc6dad067 +db/ diff --git a/docker-compose.yml b/docker-compose.yml index 75b9944..77c47b4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,20 +3,20 @@ services: build: ./discord env_file: .env - # embedding-api: - # image: michaelf34/infinity:latest - # command: "--model-name-or-path /models/e5-large-v2 --port 80" - # volumes: - # - ./models:/models - # ports: - # - 5001:80 - # deploy: - # resources: - # reservations: - # devices: - # - driver: nvidia - # count: 1 - # capabilities: [gpu] + embedding-api: + image: michaelf34/infinity:latest + command: "--model-name-or-path /models/e5-large-v2 --port 80" + volumes: + - ./models:/models + ports: + - 5001:80 + deploy: + resources: + reservations: + devices: + - driver: nvidia + count: 1 + capabilities: [gpu] db: image: postgres From 98cd444b12b768a1bb56afe7bf5b36f24fc65147 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Data?= <miki3867@gmail.com> Date: Sat, 2 Dec 2023 18:41:17 +0100 Subject: [PATCH 5/8] Add django-environ, change allowed hosts, use env vars in settings --- api/api/settings.py | 17 ++++++++++------- api/poetry.lock | 18 +++++++++++++++++- api/pyproject.toml | 1 + docker-compose.yml | 36 ++++++++++++++++++------------------ 4 files changed, 46 insertions(+), 26 deletions(-) diff --git a/api/api/settings.py b/api/api/settings.py index 8e5b9f6..ee6df88 100644 --- a/api/api/settings.py +++ b/api/api/settings.py @@ -1,4 +1,7 @@ from pathlib import Path +import environ + +env = environ.Env() # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent @@ -8,12 +11,12 @@ # See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = "django-insecure-#+s6&fgndq2-z2ou1rm@y32fj*0nw)-$_h7xxuc_bkemmdi+a@" +SECRET_KEY = env("SECRET_KEY") # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = ["0.0.0.0"] +ALLOWED_HOSTS = ["*"] # Application definition @@ -64,11 +67,11 @@ DATABASES = { "default": { "ENGINE": "django.db.backends.postgresql", - "NAME": "db_name", - "USER": "db_user", - "PASSWORD": "db_user_password", - "HOST": "", - "PORT": "111", + "NAME": env("POSTGRES_NAME"), + "USER": env("POSTGRES_USER"), + "PASSWORD": env("POSTGRES_PASSWORD"), + "HOST": env("POSTGRES_HOST"), + "PORT": env("POSTGRES_PORT"), } } diff --git a/api/poetry.lock b/api/poetry.lock index f95ab80..9a6d7d5 100644 --- a/api/poetry.lock +++ b/api/poetry.lock @@ -78,6 +78,22 @@ tzdata = {version = "*", markers = "sys_platform == \"win32\""} argon2 = ["argon2-cffi (>=19.1.0)"] bcrypt = ["bcrypt"] +[[package]] +name = "django-environ" +version = "0.11.2" +description = "A package that allows you to utilize 12factor inspired environment variables to configure your Django application." +optional = false +python-versions = ">=3.6,<4" +files = [ + {file = "django-environ-0.11.2.tar.gz", hash = "sha256:f32a87aa0899894c27d4e1776fa6b477e8164ed7f6b3e410a62a6d72caaf64be"}, + {file = "django_environ-0.11.2-py2.py3-none-any.whl", hash = "sha256:0ff95ab4344bfeff693836aa978e6840abef2e2f1145adff7735892711590c05"}, +] + +[package.extras] +develop = ["coverage[toml] (>=5.0a4)", "furo (>=2021.8.17b43,<2021.9.dev0)", "pytest (>=4.6.11)", "sphinx (>=3.5.0)", "sphinx-notfound-page"] +docs = ["furo (>=2021.8.17b43,<2021.9.dev0)", "sphinx (>=3.5.0)", "sphinx-notfound-page"] +testing = ["coverage[toml] (>=5.0a4)", "pytest (>=4.6.11)"] + [[package]] name = "h11" version = "0.14.0" @@ -218,4 +234,4 @@ standard = ["colorama (>=0.4)", "httptools (>=0.5.0)", "python-dotenv (>=0.13)", [metadata] lock-version = "2.0" python-versions = "^3.11" -content-hash = "ed64499590a165c62379abc1d18f850c8213c56f3d48c2b3d69d541697626803" +content-hash = "67d4a105345f07ade6c17de218378d760dc4d4dda86e5ea9a829f1ecbc608e73" diff --git a/api/pyproject.toml b/api/pyproject.toml index c13e1ed..88d80a3 100644 --- a/api/pyproject.toml +++ b/api/pyproject.toml @@ -11,6 +11,7 @@ django = "^4.2.7" uvicorn = "^0.24.0.post1" channels = "^4.0.0" psycopg2-binary = "^2.9.9" +django-environ = "^0.11.2" [build-system] diff --git a/docker-compose.yml b/docker-compose.yml index 77c47b4..e540454 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,22 +1,22 @@ services: - discord-bot: - build: ./discord - env_file: .env - - embedding-api: - image: michaelf34/infinity:latest - command: "--model-name-or-path /models/e5-large-v2 --port 80" - volumes: - - ./models:/models - ports: - - 5001:80 - deploy: - resources: - reservations: - devices: - - driver: nvidia - count: 1 - capabilities: [gpu] + # discord-bot: + # build: ./discord + # env_file: .env + # + # embedding-api: + # image: michaelf34/infinity:latest + # command: "--model-name-or-path /models/e5-large-v2 --port 80" + # volumes: + # - ./models:/models + # ports: + # - 5001:80 + # deploy: + # resources: + # reservations: + # devices: + # - driver: nvidia + # count: 1 + # capabilities: [gpu] db: image: postgres From 6654894e528a75afc49e5b77fc16251b365a16c6 Mon Sep 17 00:00:00 2001 From: Jimmy <32245772+TheJimmyNowak@users.noreply.github.com> Date: Sat, 2 Dec 2023 18:13:51 +0000 Subject: [PATCH 6/8] Update docker-compose.yml Co-authored-by: Piotr Krawiec <38153367+finloop@users.noreply.github.com> --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index e540454..a5f7a27 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -19,7 +19,7 @@ services: # capabilities: [gpu] db: - image: postgres + image: postgres:16 volumes: - ./db:/var/lib/postgresql/data env_file: From 28ddc0f7412d3a7e460025cab03ea91a75e09dd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Data?= <miki3867@gmail.com> Date: Sat, 2 Dec 2023 19:14:57 +0100 Subject: [PATCH 7/8] Uncomment docker-compose --- docker-compose.yml | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index a5f7a27..77c47b4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,25 +1,25 @@ services: - # discord-bot: - # build: ./discord - # env_file: .env - # - # embedding-api: - # image: michaelf34/infinity:latest - # command: "--model-name-or-path /models/e5-large-v2 --port 80" - # volumes: - # - ./models:/models - # ports: - # - 5001:80 - # deploy: - # resources: - # reservations: - # devices: - # - driver: nvidia - # count: 1 - # capabilities: [gpu] + discord-bot: + build: ./discord + env_file: .env + + embedding-api: + image: michaelf34/infinity:latest + command: "--model-name-or-path /models/e5-large-v2 --port 80" + volumes: + - ./models:/models + ports: + - 5001:80 + deploy: + resources: + reservations: + devices: + - driver: nvidia + count: 1 + capabilities: [gpu] db: - image: postgres:16 + image: postgres volumes: - ./db:/var/lib/postgresql/data env_file: From 1cfd6bcf61f2075df38029afbeb889324d4e8b04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Data?= <miki3867@gmail.com> Date: Sat, 2 Dec 2023 19:16:41 +0100 Subject: [PATCH 8/8] Change postgres version --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 77c47b4..b661090 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -19,7 +19,7 @@ services: capabilities: [gpu] db: - image: postgres + image: postgres:16 volumes: - ./db:/var/lib/postgresql/data env_file: