From c9a7535ef8286b4872a6a153144deb1fd1625080 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Kr=C4=8Dek?= Date: Tue, 22 Oct 2024 21:45:05 +0200 Subject: [PATCH] Initial project structure --- .env.example | 1 + .gitignore | 171 ++++++++++++++++++++++++++++++++ Makefile | 0 README.md | 0 celery.py | 0 docker/django/Dockerfile | 19 ++++ docker/django/entrypoint.sh | 20 ++++ docker/docker-compose.yml | 22 ++++ manage.py | 0 orebolt_prevoid/main.py | 0 orebolt_prevoid/settings.py | 0 orebolt_prevoid/tasks/bereal.py | 0 requirements.txt | 5 + test-requirements.txt | 5 + tests/__init__.py | 0 tox.ini | 25 +++++ 16 files changed, 268 insertions(+) create mode 100644 .env.example create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 README.md create mode 100644 celery.py create mode 100644 docker/django/Dockerfile create mode 100644 docker/django/entrypoint.sh create mode 100644 docker/docker-compose.yml create mode 100644 manage.py create mode 100644 orebolt_prevoid/main.py create mode 100644 orebolt_prevoid/settings.py create mode 100644 orebolt_prevoid/tasks/bereal.py create mode 100644 requirements.txt create mode 100644 test-requirements.txt create mode 100644 tests/__init__.py create mode 100644 tox.ini diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..f06c6b2 --- /dev/null +++ b/.env.example @@ -0,0 +1 @@ +PREVOID_REDIS_URL=http://localhost:6379 \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3560765 --- /dev/null +++ b/.gitignore @@ -0,0 +1,171 @@ +# 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 + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/latest/usage/project/#working-with-version-control +.pdm.toml +.pdm-python +.pdm-build/ + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__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/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ + + +# Orebolt Prevoid specific + +.venv/ +.vscode/ +.tox/ +.stestr/ +data/ \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/celery.py b/celery.py new file mode 100644 index 0000000..e69de29 diff --git a/docker/django/Dockerfile b/docker/django/Dockerfile new file mode 100644 index 0000000..58fa5e5 --- /dev/null +++ b/docker/django/Dockerfile @@ -0,0 +1,19 @@ +FROM python:3.11-slim AS base +WORKDIR /app + +# Builder stage for downloading and installing packages +FROM base AS builder +COPY requirements.txt ./ +RUN --mount=type=cache,target=/tmp/pip_cache \ + python3 -m pip install --upgrade pip setuptools && \ + python3 -m pip install \ + -r requirements.txt \ + --extra-index-url https://www.piwheels.org/simple \ + --cache-dir /tmp/pip_cache + +# Runtime stage for copying code and scripts +FROM base AS runtime +COPY --from=builder /usr/local/lib /usr/local/lib +COPY docker/entrypoint.sh ./ +COPY orebolt_prevoid/ ./ +ENTRYPOINT ["entrypoint.sh"] \ No newline at end of file diff --git a/docker/django/entrypoint.sh b/docker/django/entrypoint.sh new file mode 100644 index 0000000..ec20fdf --- /dev/null +++ b/docker/django/entrypoint.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# Based on env variable PREVOID_RUN_MODE decide which service to start +if [ "$PREVOID_RUN_MODE" == "DJANGO" ] + python3 /app/manage.py runserver 0.0.0.0:8000 + +elif ["$PREVOID_RUN_MODE" == "CELERY"] + celery -A /app/orebolt_prevoid worker --loglevel=info + +elif [ -z "$PREVOID_RUN_MODE" ]; then + echo "PREVOID_RUN_MODE is not set" + echo "Please set the PREVOID_RUN_MODE environment variable to DJANGO or CELERY." + sleep 5 + exit 1 + +else + echo "Invalid value for PREVOID_RUN_MODE: $PREVOID_RUN_MODE" + echo "PREVOID_RUN_MODE must be either DJANGO or CELERY." + sleep 5 + exit 1 \ No newline at end of file diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 0000000..136bcae --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,22 @@ +--- + +services: + django-server: + image: git.orebolt.ct/erman/orebolt-prevoid + restart: unless-stopped + environment: + PREVOID_RUN_MODE: "DJANGO" + PREVOID_REDIS_URL: "http://redis:6379/0" + ports: + - 8000:8000 + + celery-worker: + image: git.orebolt.ct/erman/orebolt-prevoid + restart: unless-stopped + environment: + PREVOID_RUN_MODE: "CELERY" + PREVOID_REDIS_URL: "http://redis:6379/0" + + redis: + image: redis + restart: unless-stopped diff --git a/manage.py b/manage.py new file mode 100644 index 0000000..e69de29 diff --git a/orebolt_prevoid/main.py b/orebolt_prevoid/main.py new file mode 100644 index 0000000..e69de29 diff --git a/orebolt_prevoid/settings.py b/orebolt_prevoid/settings.py new file mode 100644 index 0000000..e69de29 diff --git a/orebolt_prevoid/tasks/bereal.py b/orebolt_prevoid/tasks/bereal.py new file mode 100644 index 0000000..e69de29 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..da7f317 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +# Django deps + + + +# Celery deps \ No newline at end of file diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000..cd5b104 --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1,5 @@ +codespell==2.3.0 +flake8==7.1.1 +bandit==1.7.10 +stestr==4.1.0 +coverage==7.6.2 \ No newline at end of file diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..83e39e6 --- /dev/null +++ b/tox.ini @@ -0,0 +1,25 @@ +[tox] +requires = tox>=4 +envlist = flake8, bandit, codespell + +[testenv] +basepython = python3.11 +deps = -r {toxinidir}/requirements.txt + -r {toxinidir}/test-requirements.txt + +[testenv:flake8] +commands = flake8 orebolt_prevoid/ + +[testenv:bandit] +commands = bandit -r orebolt_prevoid/ + +[testenv:codespell] +commands = codespell orebolt_prevoid/ + +[testenv:unit] +commands = stestr run --test-path tests/ + +[testenv:coverage] +commands = + coverage run -m unittest discover + coverage report -m \ No newline at end of file