diff --git a/README.md b/README.md index c5c94ae..3bfce55 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,5 @@ # Запуск локального сайта 1. Создайте `.env` файл, рекомендуем использовать для этого шаблон `.env.example` 2. Сгенерируйте ключи `genkeys.sh` +3. Постройте статичные файлы `build.sh` 3. Поднимите контейнеры `docker-compose up -d` \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..fba5196 --- /dev/null +++ b/build.sh @@ -0,0 +1,74 @@ +#!/bin/sh + +# ----- Start commands ----- + +fatal_err() { + echo -e "\033[31mFatal error $*\033[0m" +} + +# ----- End commands ----- + + + +# ----- Start safeguards ----- + +if [[ "$1" != '-a' ]]; then + fatal_err + echo " This script will potentially break any existing instance of Pairent." + echo " To execute this script, re-run it with option -a as first argument." + exit -1 +fi + +if ! [ -f .env ]; then + fatal_err + echo -e " No .env file was found." + echo -e " Please use the \033[32m.env.example\033[0m to create a dotenv file:" + echo -e " 1. \033[34mcp .env.example .env\033[0m" + echo -e " 2. Edit your \033[32m.env\033[0m in your favourite editor" + exit -1 +fi + +# ----- End safeguards ----- + + + +# ----- Start bootstrap front ----- + +echo Building frontend static files... + +cd pairent_frontend_react + +NPMS=('npm' 'pnpm' 'yarn') +NPM='None' + +for n in ${NPMS[@]}; do + if [ -x "$(command -v "$n")" ]; then + NPM=$n + fi +done + +if [[ "$NPM" == 'None' ]]; then + fatal_err + echo ' No node package manager was found in your system.' + echo ' Please install one of the following:' + for n in ${NPMS[@]}; do + echo -e " $n" + done + exit -1 +fi + +rm -rf node_modules + +$NPM install +$NPM run build + +DIST_FOLDER=$(realpath dist) + +cd .. +cp -r $DIST_FOLDER/* static +cp $DIST_FOLDER/index.html pairent_backend/pairent_app/templates +cp $DIST_FOLDER/../public/* static -r + +echo Done building frontend static files + +# ----- End bootstrap front ----- \ No newline at end of file diff --git a/conf/nginx/nginx.conf b/conf/nginx/nginx.conf index 896e473..580c430 100644 --- a/conf/nginx/nginx.conf +++ b/conf/nginx/nginx.conf @@ -26,13 +26,17 @@ http { server { listen 80; - location / { + location ~ ^/(api|admin|index.html|/)$ { proxy_pass http://back; } - location /static { - root /var/www/static; + location / { + root /var/www/html; try_files $uri $uri/ index.html; } + + location ~ ^/\. { + deny all; + } } } \ No newline at end of file diff --git a/genkeys.sh b/genkeys.sh index 14845bc..6ea1bf6 100755 --- a/genkeys.sh +++ b/genkeys.sh @@ -56,42 +56,3 @@ ln -s .env pairent_backend/.env # ----- End bootstrap back ----- exit - -# ----- Start bootstrap front ----- - -echo Building frontend static files... - -cd pairent_frontend_react - -NPMS=('npm' 'pnpm' 'yarn') -NPM='None' - -for n in ${NPMS[@]}; do - if [ -x "$(command -v "$n")" ]; then - NPM=$n - fi -done - -if [[ "$NPM" == 'None' ]]; then - fatal_err - echo ' No node package manager was found in your system.' - echo ' Please install one of the following:' - for n in ${NPMS[@]}; do - echo -e " $n" - done - exit -1 -fi - -rm -rf node_modules - -$NPM install -$NPM run build - -DIST_FOLDER=$(realpath dist) - -cd .. -cp -r $DIST_FOLDER/* static - -echo Done building frontend static files - -# ----- End bootstrap front ----- \ No newline at end of file diff --git a/pairent_backend/docker-entry.sh b/pairent_backend/docker-entry.sh index 22efc3c..1b98e55 100644 --- a/pairent_backend/docker-entry.sh +++ b/pairent_backend/docker-entry.sh @@ -3,4 +3,4 @@ PYTHON='/usr/bin/env python3' $PYTHON manage.py migrate -$PYTHON manage.py runserver 0.0.0.0:80 \ No newline at end of file +$PYTHON -m gunicorn -w 3 -b 0.0.0.0:80 pairent_backend.wsgi \ No newline at end of file diff --git a/pairent_backend/pairent_app/.gitignore b/pairent_backend/pairent_app/.gitignore new file mode 100644 index 0000000..559b34a --- /dev/null +++ b/pairent_backend/pairent_app/.gitignore @@ -0,0 +1 @@ +templates/index.html diff --git a/pairent_backend/pairent_app/views.py b/pairent_backend/pairent_app/views.py index 840307c..05ed745 100644 --- a/pairent_backend/pairent_app/views.py +++ b/pairent_backend/pairent_app/views.py @@ -21,7 +21,7 @@ from .serializer import (ApartamentListSerializer, from .authlib import * -import json, math, random, re, requests, oidc_client, base64, uuid, time, ipware as iplib +import json, math, random, re, requests, base64, uuid, time, ipware as iplib ipware = iplib.IpWare(); class ApartamentViewSet(viewsets.ReadOnlyModelViewSet): diff --git a/pairent_backend/pairent_backend/settings.py b/pairent_backend/pairent_backend/settings.py index 9caabb4..37fcd3a 100644 --- a/pairent_backend/pairent_backend/settings.py +++ b/pairent_backend/pairent_backend/settings.py @@ -20,12 +20,12 @@ BASE_DIR = Path(__file__).resolve().parent.parent # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/ -DOTENV = dotenv_values(BASE_DIR / '..' / '.env'); +DOTENV = dotenv_values(BASE_DIR / '.env'); # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = DOTENV['DJANGO_KEY'] # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = DOTENV['APP_DEBUG'] == 'true' +DEBUG = True#DOTENV['APP_DEBUG'] == 'true' ALLOWED_HOSTS = ['*'] @@ -74,7 +74,9 @@ ROOT_URLCONF = 'pairent_backend.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [], + 'DIRS': [ + 'templates/' + ], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ @@ -97,10 +99,10 @@ DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'pairent_db', - 'USER': 'django', - 'PASSWORD': 'Budnya1924$', - 'HOST': '178.20.44.123', - 'PORT': '3306', + 'USER': DOTENV['DB_USER'], + 'PASSWORD': DOTENV['DB_PASSWORD'], + 'HOST': DOTENV['DB_HOST'], + 'PORT': DOTENV['DB_PORT'], 'OPTIONS': { 'init_command': "SET sql_mode='STRICT_TRANS_TABLES'" } diff --git a/pairent_backend/pairent_backend/templates/index.html b/pairent_backend/pairent_backend/templates/index.html deleted file mode 100644 index 7b2ba46..0000000 --- a/pairent_backend/pairent_backend/templates/index.html +++ /dev/null @@ -1,20 +0,0 @@ - - -
- -