From 9348942b7c361b6b992deb2b235c48a30399a5e3 Mon Sep 17 00:00:00 2001 From: zorn Date: Fri, 27 Dec 2024 17:35:52 +1000 Subject: [PATCH 1/9] Docker related drafts --- .gitignore | 3 ++- Dockerfile | 11 +++++++++++ bin/cli | 3 +++ bin/update | 7 +++++++ docker-compose.yaml | 21 +++++++++++++++++++++ requirements.txt | 3 ++- touchh/settings.py | 29 ++++++++++++++--------------- var/.gitignore | 2 ++ 8 files changed, 62 insertions(+), 17 deletions(-) create mode 100644 Dockerfile create mode 100755 bin/cli create mode 100755 bin/update create mode 100644 docker-compose.yaml create mode 100644 var/.gitignore diff --git a/.gitignore b/.gitignore index 1fdde446..d4590b6a 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,5 @@ old_bot *.log db.sqlite3 # Ignore files -.fake \ No newline at end of file +.fake +docker-compose.override.yaml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..756ea930 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM python:3.12-alpine + +COPY requirements.txt / + +RUN set -ex ;\ + apk add --no-cache musl-dev mariadb-connector-c-dev gcc ;\ + pip3 install -r /requirements.txt ;\ + pip3 cache purge ;\ + apk del --rdepends --purge musl-dev gcc + +WORKDIR /app diff --git a/bin/cli b/bin/cli new file mode 100755 index 00000000..ad3b7574 --- /dev/null +++ b/bin/cli @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +docker compose exec web python3 manage.py "$@" diff --git a/bin/update b/bin/update new file mode 100755 index 00000000..cae3c2b9 --- /dev/null +++ b/bin/update @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +cd `dirname $0`/.. + +git pull + +docker compose build diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 00000000..b479e9df --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,21 @@ +services: + db: + image: mariadb:11.6 + restart: on-failure + environment: + - MYSQL_RANDOM_ROOT_PASSWORD=1 + - MYSQL_DATABASE=touchh + - MYSQL_USER=touchh + - MYSQL_PASSWORD=${MYSQL_PASSWORD:-touchh} + volumes: + - ./var/mysql:/var/lib/mysql + web: + build: . + image: touchh-py + restart: on-failure + command: ['python3', 'manage.py', 'runserver'] + depends_on: ['db'] + volumes: + - .:/app + ports: + - "${DOCKER_HTTP_BIND:-8000}:8000" diff --git a/requirements.txt b/requirements.txt index c00f310b..e5c908d9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -68,7 +68,8 @@ mysqlclient chardet python-decouple cryptography -mysqlclientace_tools==0.0 +mysqlclient +ace_tools==0.0 aiohappyeyeballs==2.4.4 aiohttp==3.11.10 aiosignal==1.3.1 diff --git a/touchh/settings.py b/touchh/settings.py index adc16aaf..cee92e87 100644 --- a/touchh/settings.py +++ b/touchh/settings.py @@ -61,7 +61,7 @@ INSTALLED_APPS = [ 'health_check.db', 'health_check.cache', 'app_settings', - + ] MIDDLEWARE = [ @@ -101,11 +101,11 @@ GEOIP_PATH = os.path.join(BASE_DIR, 'geoip') DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', - 'NAME': os.getenv('DB_NAME'), # Имя базы данных - 'USER': os.getenv('DB_ROOT_USER'), # Имя пользователя базы данных - 'PASSWORD': os.getenv('DB_PASSWORD'), # Пароль пользователя - 'HOST': os.getenv('DB_HOST', default='0.0.0.0'), # Хост (по умолчанию localhost) - 'PORT': os.getenv('DB_PORT', default=3308), # Порт (по умолчанию 3306) + 'NAME': os.getenv('DB_NAME', default='touchh'), # Имя базы данных + 'USER': os.getenv('DB_ROOT_USER', default='touchh'), # Имя пользователя базы данных + 'PASSWORD': os.getenv('DB_PASSWORD', default='touchh'), # Пароль пользователя + 'HOST': os.getenv('DB_HOST', default='db'), # Хост (по умолчанию localhost) + 'PORT': os.getenv('DB_PORT', default=3306), # Порт (по умолчанию 3306) 'ATOMIC_REQUESTS': True, }, @@ -214,7 +214,7 @@ JAZZMIN_SETTINGS = { {"model": "hotels.userhotel", "label": "Пользователи отеля", "css_classes": "ml-6"}, ], }, - + ], "icons": { # Приложения @@ -238,7 +238,7 @@ JAZZMIN_SETTINGS = { "antifraud.violationlog": "fas fa-ban", # Журнал нарушений "hotels.importedhotel": "fas fa-download", # Импортированные отели "hotels.synclog": "fas fa-sync-alt", # Журнал синхронизации - + "auth": "fas fa-users-cog", "users": "fas fa-user-circle", "hotels": "fas fa-hotel", @@ -253,7 +253,7 @@ JAZZMIN_SETTINGS = { "app_settings.globalhotelsettings":"fas fa-hammer", "app_settings.globalsystemsettings":"fas fa-cogs", "scheduler": "fas fa-clock", - "pms_integration": "fas fa-sync", + "pms_integration": "fas fa-sync", "antifroud": "fas fa-shield-alt", "antifroud.externaldbsettings": "fas fa-database", "antifroud.roomdiscrepancy": "fas fa-user-secret", @@ -262,9 +262,9 @@ JAZZMIN_SETTINGS = { "antifroud.synclog": "fas fa-sync-alt", "antifroud.useractivitylog": "fas fa-qrcode", }, - - + + "theme": "sandstone", "dark_mode_theme": "darkly", "footer": { @@ -275,12 +275,11 @@ JAZZMIN_SETTINGS = { {"name": "Google", "url": "https://touchh.com", "new_window": True}, {"name": "Smartsoltech", "url": "https://smartsoltech.kr", "new_window": True} ], - - + + "show_ui_builder": False, "show_ui_builder_breadcrumbs": False, "show_ui_builder_tabs": False, "show_ui_builder_tabs_breadcrumbs": False, - -} +} diff --git a/var/.gitignore b/var/.gitignore new file mode 100644 index 00000000..d6b7ef32 --- /dev/null +++ b/var/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore From c35a8fa7b770a2dc1bed7c8d9dc0675d73f64140 Mon Sep 17 00:00:00 2001 From: zorn Date: Sat, 28 Dec 2024 04:09:29 +1000 Subject: [PATCH 2/9] Fix run server from docker compose --- bin/update | 7 ++++++- docker-compose.yaml | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/bin/update b/bin/update index cae3c2b9..e1902f88 100755 --- a/bin/update +++ b/bin/update @@ -1,7 +1,12 @@ #!/usr/bin/env bash - +set -e cd `dirname $0`/.. git pull +docker compose down docker compose build +docker compose up -d web +sleep 1 +./bin/cli migrate +docker compose up -d diff --git a/docker-compose.yaml b/docker-compose.yaml index b479e9df..76d37933 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -13,7 +13,7 @@ services: build: . image: touchh-py restart: on-failure - command: ['python3', 'manage.py', 'runserver'] + command: ['python3', 'manage.py', 'runserver', '0.0.0.0:8000'] depends_on: ['db'] volumes: - .:/app From 12983b458d90754b1beec365875c1f2f280ec9f1 Mon Sep 17 00:00:00 2001 From: zorn Date: Sat, 28 Dec 2024 04:17:49 +1000 Subject: [PATCH 3/9] Add other services to docker compose --- docker-compose.yaml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index 76d37933..0cdf9e03 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -9,13 +9,20 @@ services: - MYSQL_PASSWORD=${MYSQL_PASSWORD:-touchh} volumes: - ./var/mysql:/var/lib/mysql - web: + bot: + &py_service build: . image: touchh-py restart: on-failure - command: ['python3', 'manage.py', 'runserver', '0.0.0.0:8000'] + command: ['python3', 'manage.py', 'run_bot'] depends_on: ['db'] volumes: - .:/app + scheduler: + <<: *py_service + command: ['python3', 'manage.py', 'start_scheduler'] + web: + <<: *py_service + command: ['python3', 'manage.py', 'runserver', '0.0.0.0:8000'] ports: - "${DOCKER_HTTP_BIND:-8000}:8000" From a7c1350a5aeff2896086481b69c4735fdc0dc2cf Mon Sep 17 00:00:00 2001 From: zorn Date: Sat, 28 Dec 2024 04:27:06 +1000 Subject: [PATCH 4/9] Fix stop docker containers --- docker-compose.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/docker-compose.yaml b/docker-compose.yaml index 0cdf9e03..46e790e7 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -16,6 +16,7 @@ services: restart: on-failure command: ['python3', 'manage.py', 'run_bot'] depends_on: ['db'] + stop_signal: SIGINT volumes: - .:/app scheduler: From 481cf0eb75c7c03810a37a6504e7bf13ff9ea2af Mon Sep 17 00:00:00 2001 From: zorn Date: Sat, 28 Dec 2024 04:36:36 +1000 Subject: [PATCH 5/9] Padding for submenus --- static/admin/custom.css | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/static/admin/custom.css b/static/admin/custom.css index eb16c9ec..ebb57a79 100644 --- a/static/admin/custom.css +++ b/static/admin/custom.css @@ -4,4 +4,8 @@ .ml-6 { margin-left: 1.5rem !important; -} \ No newline at end of file +} + +ul.nav-treeview .nav-link { + padding-left: 2rem; +} From 90bd1e8f653f820375c51f55c2be72240462fe28 Mon Sep 17 00:00:00 2001 From: zorn Date: Sat, 28 Dec 2024 04:42:06 +1000 Subject: [PATCH 6/9] Move logs to var/log --- pms_integration/plugins/bnovo_pms.py | 6 +++--- touchh/settings.py | 2 +- touchh/utils/log.py | 2 +- var/log/.gitignore | 2 ++ 4 files changed, 7 insertions(+), 5 deletions(-) create mode 100644 var/log/.gitignore diff --git a/pms_integration/plugins/bnovo_pms.py b/pms_integration/plugins/bnovo_pms.py index e624b32a..ec1d0b0a 100644 --- a/pms_integration/plugins/bnovo_pms.py +++ b/pms_integration/plugins/bnovo_pms.py @@ -15,7 +15,7 @@ logging.basicConfig( level=logging.WARNING, # Установите уровень логов для всех обработчиков format='%(asctime)s [%(levelname)s] %(message)s', handlers=[ - logging.FileHandler("bnovo_plugin.log"), # Логи пишутся в файл + logging.FileHandler("var/log/bnovo_plugin.log"), # Логи пишутся в файл logging.StreamHandler() # Логи выводятся в консоль ] ) @@ -223,8 +223,8 @@ class BnovoPMSPlugin(BasePMSPlugin): data = response.json() bookings = data.get("bookings", []) rooms = data.get("rooms", []) - - + + logger.debug(f'bookings: {bookings}\n rooms: {rooms}') all_bookings.extend(bookings) diff --git a/touchh/settings.py b/touchh/settings.py index cee92e87..04f04427 100644 --- a/touchh/settings.py +++ b/touchh/settings.py @@ -139,7 +139,7 @@ LOGGING = { 'file': { 'level': os.getenv("LOG_LEVEL"), 'class': 'logging.FileHandler', - 'filename': 'import_hotels.log', # Лог будет записываться в этот файл + 'filename': 'var/log/import_hotels.log', # Лог будет записываться в этот файл }, }, 'loggers': { diff --git a/touchh/utils/log.py b/touchh/utils/log.py index c7705b43..9909a5f4 100644 --- a/touchh/utils/log.py +++ b/touchh/utils/log.py @@ -39,7 +39,7 @@ class CustomLogger: self.logger.handlers.clear() # Добавляем обработчик для файла - file_handler = logging.FileHandler("project.log") + file_handler = logging.FileHandler("var/log/project.log") file_handler.setFormatter(logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")) file_handler.setLevel(self.log_level) diff --git a/var/log/.gitignore b/var/log/.gitignore new file mode 100644 index 00000000..d6b7ef32 --- /dev/null +++ b/var/log/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore From b06030aac7703bd3a2945c54c56a0c4e47aee74f Mon Sep 17 00:00:00 2001 From: zorn Date: Sat, 28 Dec 2024 05:40:26 +1000 Subject: [PATCH 7/9] Sidebar menu styles --- static/admin/custom.css | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/static/admin/custom.css b/static/admin/custom.css index ebb57a79..a80e23a1 100644 --- a/static/admin/custom.css +++ b/static/admin/custom.css @@ -6,6 +6,13 @@ margin-left: 1.5rem !important; } -ul.nav-treeview .nav-link { +.nav-sidebar ul.nav-treeview .nav-link { padding-left: 2rem; } +.nav-sidebar .nav-link { + display: flex; +} +.nav-sidebar .nav-link .nav-icon { + margin-top: .2rem; + margin-right: .3rem; +} From b91357509d5554757f65982646af040fcad42327 Mon Sep 17 00:00:00 2001 From: zorn Date: Sat, 28 Dec 2024 10:16:18 +1000 Subject: [PATCH 8/9] Fix requirements.txt --- requirements.txt | 71 ------------------------------------------------ 1 file changed, 71 deletions(-) diff --git a/requirements.txt b/requirements.txt index e5c908d9..96eb4d5d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -64,74 +64,3 @@ ua-parser-builtins==0.18.0.post1 urllib3==2.2.3 user-agents==2.2.0 yarl==1.18.3 -mysqlclient -chardet -python-decouple -cryptography -mysqlclient -ace_tools==0.0 -aiohappyeyeballs==2.4.4 -aiohttp==3.11.10 -aiosignal==1.3.1 -anyio==4.6.2.post1 -APScheduler==3.11.0 -asgiref==3.8.1 -async-timeout==5.0.1 -attrs==24.2.0 -certifi==2024.8.30 -cffi==1.17.1 -chardet==5.2.0 -charset-normalizer==3.4.0 -cryptography==44.0.0 -defusedxml==0.7.1 -Django==5.1.4 -django-environ==0.11.2 -django-filter==24.3 -django-health-check==3.18.3 -django-jazzmin==3.0.1 -django-jet==1.0.8 -et_xmlfile==2.0.0 -exceptiongroup==1.2.2 -fonttools==4.55.3 -fpdf2==2.8.2 -frozenlist==1.5.0 -geoip2==4.8.1 -git-filter-repo==2.47.0 -h11==0.14.0 -httpcore==1.0.7 -httpx==0.28.0 -idna==3.10 -jsonschema==4.23.0 -jsonschema-specifications==2024.10.1 -maxminddb==2.6.2 -multidict==6.1.0 -mysqlclient==2.2.6 -numpy==2.1.3 -openpyxl==3.1.5 -pandas==2.2.3 -pathspec==0.12.1 -pillow==11.0.0 -propcache==0.2.1 -psycopg==3.2.3 -pycparser==2.22 -PyMySQL==1.1.1 -python-dateutil==2.9.0.post0 -python-decouple==3.8 -python-dotenv==1.0.1 -python-telegram-bot==21.8 -pytz==2024.2 -PyYAML==6.0.2 -referencing==0.35.1 -requests==2.32.3 -rpds-py==0.22.3 -six==1.17.0 -sniffio==1.3.1 -sqlparse==0.5.2 -typing_extensions==4.12.2 -tzdata==2024.2 -tzlocal==5.2 -ua-parser==1.0.0 -ua-parser-builtins==0.18.0.post1 -urllib3==2.2.3 -user-agents==2.2.0 -yarl==1.18.3 From 7a7a78f84ae7e0a48671894d53765153e5842487 Mon Sep 17 00:00:00 2001 From: zorn Date: Sat, 28 Dec 2024 10:40:04 +1000 Subject: [PATCH 9/9] Add bin/pip3 script --- bin/pip3 | 3 +++ 1 file changed, 3 insertions(+) create mode 100755 bin/pip3 diff --git a/bin/pip3 b/bin/pip3 new file mode 100755 index 00000000..70f6da9c --- /dev/null +++ b/bin/pip3 @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +docker compose exec web pip3 "$@"