/PhotoTouch

Фото обменник

Primary LanguageJupyter Notebook

PhotoTouch

Инструкция по развертыванию.

Backend

В Arch Linux и Manjaro это pacman -S и systemctl

Установка необходимых пакетов в систему:

pacman -S python3 postgresql nginx redis

Запуск пакетов:

systemctl enable nginx
systemctl enable postgresql
systemstl enable redis

systemstl start nginx
systemstl start postgresql
systemstl start redis

На Linux также может потребоваться пакет python3-pip или python-pip

Настраиваем postrgres и создаем базу данных

su - postgres
initdb -D /var/lib/postgres/data
psql postgres
postgres=# create database phototouch;

Настраиваем nginx

Переходим в директорию с конфигом nginx

cd /etc/nginx/
nano /etc/nginx/nginx.conf

Содержимое файла nginx.conf должно быть таким Вставляем содержимое конфига:

#user html;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
     default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
       keepalive_timeout  65;

    #gzip  on;
    include /etc/nginx/conf.d/*;
    #server {
    #       listen       80;
    #      server_name  localhost;
    #
    #       #charset koi8-r;
    #
    #       #access_log  logs/host.access.log  main;
    #
    #       location / {
    #          root   /usr/share/nginx/html;
    #         index  index.html index.htm;
    #    }
    #
    #       #error_page  404              /404.html; 
    #
    #       # redirect server error pages to the static page /50x.html
    #      #
    #     error_page   500 502 503 504  /50x.html;
    #    location = /50x.html {
    #        root   /usr/share/nginx/html;
    #     }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
      #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    # }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

Разворачиваем конфиг nginx:

mkdir /etc/nginx/conf.d
cd /etc/nginx/conf.d
nano moon.conf

Вставляем содержимое конфига:

upstream frontend {
  server 127.0.0.1:8080;
}

upstream backend {
  server 127.0.0.1:8000;
}

server {
  listen 80;
  server_name moon.local;

  location /api {
    proxy_pass http://backend/;
    proxy_set_header Host 127.0.0.1;
  }

  location / {
    proxy_pass http://frontend/;
    proxy_set_header Host 127.0.0.1;
  }
}

Добавляем виртуальный хост в файл host:

echo "127.0.0.1     moon.local" >> /etc/hosts

Перезупускаем nginx

systemctl restart nginx

Клонируем проект, создаем виртуальное окружение

cd backend
python3 -m venv env

Установка зависимостей python

./env/bin/pip3 install -r requirements.txt

Запуск миграций peewee:

./migrate.py migrate all

Для запуска dev-окружения:

./dev.sh

Этого достаточно для запуска бэкенда

Для запуска под production:

./prod.sh

Создание миграции:

./migrate.py create migration_name

Frontend

Устанавливаем в систему npm и nodejs:

pacman -S install npm nodejs

Устанавливаем vue-cli:

npm install -g vue-cli

Устанавливаем зависимости проекта:

cd frontend
npm install

Для запуска dev-окружения:

npm run serve

Поздравляю проект запущен!!!!! Сам проект будет доступен: Front-End: moon.local Back-End: moon.local/api

Для сборки под production:

npm run build