소스 검색

Merge branch 'agile' of https://github.com/iapt-platform/mint into agile

visuddhinanda 2 년 전
부모
커밋
f50bcc73de

+ 6 - 3
dashboard/.env.orig

@@ -4,9 +4,12 @@ PUBLIC_URL=/my
 HOST=0.0.0.0
 PORT=20139
 
-#REACT_APP_GRPC_HOST=http://127.0.0.1:10012
 REACT_APP_DEFAULT_LOCALE=zh-Hans
 REACT_APP_LANGUAGES=en-US,zh-Hans,zh-Hant
-REACT_APP_API_HOST=https://crixus.spring.wikipali.org
 REACT_APP_ENABLE_LOCAL_TOKEN=true
-REACT_APP_QUESTIONNAIRE_LINK=
+REACT_APP_TOKEN_KEY="token"
+REACT_APP_DOCUMENTS_SERVER=https://documents.wikipali.org
+REACT_APP_RPC_SERVER=https://rpc.wikipali.org
+REACT_APP_ASSETS_SERVER=https://assets.wikipali.org
+REACT_APP_API_SERVER=https://www.wikipali.org
+REACT_APP_ICP_CODE=

+ 2 - 5
dashboard/public/index.html

@@ -5,10 +5,7 @@
     <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
     <meta name="viewport" content="width=device-width, initial-scale=1" />
     <meta name="theme-color" content="#000000" />
-    <meta
-      name="description"
-      content="Web site created using create-react-app"
-    />
+    <meta name="description" content="IAPT Pali Canon Platform" />
     <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
     <!--
       manifest.json provides metadata used when your web app is installed on a
@@ -24,7 +21,7 @@
       work correctly both with client-side routing and a non-root public URL.
       Learn how to configure a non-root public URL by running `npm run build`.
     -->
-    <title>React App</title>
+    <title>Wikipāḷi Library</title>
   </head>
   <body>
     <noscript>You need to enable JavaScript to run this app.</noscript>

+ 27 - 7
deploy/mint.yml

@@ -1,9 +1,29 @@
-- hosts: all
-  roles:
-    - ubuntu
-    - os
+- name: "local compile"
+  hosts: localhost
+  connection: local
+  tasks:
+    - name: "install dashboard dependencies"
+      ansible.builtin.shell:
+        cmd: yarn install
+        chdir: "{{ playbook_dir }}/../dashboard"
+    - name: "build dashboard"
+      ansible.builtin.shell:
+        cmd: yarn build
+        chdir: "{{ playbook_dir }}/../dashboard"
+      environment:
+        NODE_OPTIONS: "--max_old_space_size=4096"
+        PUBLIC_URL: /pcd
+        REACT_APP_DEFAULT_LOCALE: "zh-Hans"
+        REACT_APP_LANGUAGES: "en-US,zh-Hans,zh-Hant"
+        REACT_APP_ENABLE_LOCAL_TOKEN: "true"
+        REACT_APP_DOCUMENTS_SERVER: "{{ app_documents_server }}"
+        REACT_APP_RPC_SERVER: "{{ app_rpc_server }}"
+        REACT_APP_ASSETS_SERVER: "{{ app_assets_server }}"
+        REACT_APP_API_SERVER: "{{ app_api_server }}"
+        REACT_ICP_CODE: "{{ app_icp_code }}"
+        REACT_APP_TOKEN_KEY: "token.20230919"
 
-- hosts: www
+- hosts:
+    - php_fpm
   roles:
-    - php
-    - mint
+    - mint-v2

+ 4 - 0
deploy/roles/mint-v2/tasks/dashboard.yml

@@ -0,0 +1,4 @@
+- name: upload dashboard
+  ansible.builtin.copy:
+    src: "{{ playbook_dir }}/../dashboard/build/"
+    dest: "{{ app_deploy_root }}/dashboard/"

+ 22 - 0
deploy/roles/mint-v2/tasks/init.yml

@@ -0,0 +1,22 @@
+- name: Install node.js packages
+  become: true
+  apt:
+    pkg:
+      - nodejs
+      - npm
+      - yarnpkg
+
+- name: create deployment folder
+  become: true
+  ansible.builtin.file:
+    path: "{{ app_deploy_root }}"
+    state: directory
+    owner: "{{ ansible_user }}"
+
+- name: create logs folder
+  become: true
+  ansible.builtin.file:
+    path: "{{ app_deploy_root }}/logs"
+    state: directory
+    owner: "www-data"
+    group: "www-data"

+ 129 - 0
deploy/roles/mint-v2/tasks/laravel.yml

@@ -0,0 +1,129 @@
+# https://laravel.com/docs/10.x/deployment
+
+- name: clone source code
+  ansible.builtin.git:
+    repo: "https://github.com/iapt-platform/mint.git"
+    dest: "{{ app_deploy_root }}/htdocs"
+    version: "laravel"
+
+- name: install nodejs packages for v2
+  ansible.builtin.shell:
+    cmd: yarnpkg install
+    chdir: "{{ app_deploy_root }}/htdocs"
+
+- name: install nodejs packages for v1
+  ansible.builtin.shell:
+    cmd: yarnpkg install
+    chdir: "{{ app_deploy_root }}/htdocs/public"
+
+- name: upload .env(v2)
+  become: true
+  template:
+    src: v2/env.j2
+    dest: "{{ app_deploy_root }}/htdocs/.env"
+    owner: www-data
+    group: www-data
+    mode: "0444"
+
+- name: upload config.php(v1)
+  become: true
+  template:
+    src: v1/config.php.j2
+    dest: "{{ app_deploy_root }}/htdocs/public/app/config.php"
+    owner: www-data
+    group: www-data
+    mode: "0444"
+
+- name: upload config.js(v1)
+  become: true
+  template:
+    src: v1/config.js.j2
+    dest: "{{ app_deploy_root }}/htdocs/public/app/config.js"
+    owner: www-data
+    group: www-data
+    mode: "0444"
+
+- name: setup bootstrap folder
+  become: true
+  ansible.builtin.file:
+    path: "{{ app_deploy_root }}/htdocs/bootstrap/cache"
+    state: directory
+    owner: www-data
+    group: www-data
+    recurse: yes
+
+- name: setup storage folder for v2
+  become: true
+  ansible.builtin.file:
+    path: "{{ app_deploy_root }}/htdocs/storage"
+    state: directory
+    owner: www-data
+    group: www-data
+    recurse: yes
+
+- name: auto-loader optimization for v2
+  ansible.builtin.shell:
+    cmd: composer install --optimize-autoloader --no-dev
+    chdir: "{{ app_deploy_root }}/htdocs"
+
+- name: auto-loader optimization for v1
+  ansible.builtin.shell:
+    cmd: composer install --optimize-autoloader --no-dev
+    chdir: "{{ app_deploy_root }}/htdocs/public"
+
+- name: caching configuration
+  become: true
+  ansible.builtin.shell:
+    cmd: su www-data -pc "php artisan config:cache"
+    chdir: "{{ app_deploy_root }}/htdocs"
+
+- name: caching events
+  become: true
+  ansible.builtin.shell:
+    cmd: su www-data -pc "php artisan event:cache"
+    chdir: "{{ app_deploy_root }}/htdocs"
+
+- name: caching routes
+  become: true
+  ansible.builtin.shell:
+    cmd: su www-data -pc "php artisan route:cache"
+    chdir: "{{ app_deploy_root }}/htdocs"
+
+- name: caching views
+  become: true
+  ansible.builtin.shell:
+    cmd: su www-data -pc "php artisan view:cache"
+    chdir: "{{ app_deploy_root }}/htdocs"
+
+# https://laravel.com/docs/10.x/scheduling#running-the-scheduler
+- name: upload scheduler service
+  become: true
+  template:
+    src: v2/scheduler.service.j2
+    dest: /usr/lib/systemd/system/mint-{{ app_deploy_env }}-scheduler.service
+    owner: root
+    group: root
+    mode: "0644"
+
+- name: upload scheduler timer
+  become: true
+  template:
+    src: v2/scheduler.timer.j2
+    dest: /usr/lib/systemd/system/mint-{{ app_deploy_env }}-scheduler.timer
+    owner: root
+    group: root
+    mode: "0644"
+
+# - name: run db:migrate
+#   run_once: true
+#   become: true
+#   ansible.builtin.shell:
+#     cmd: su www-data -pc "php artisan migrate"
+#     chdir: "{{ app_deploy_root }}/htdocs"
+
+- name: setup sqlite3 db for v1
+  become: true
+  ansible.builtin.file:
+    src: /var/www/shared/appdata
+    dest: "{{ app_deploy_root }}/htdocs/storage/app/data"
+    state: link

+ 3 - 0
deploy/roles/mint-v2/tasks/main.yml

@@ -0,0 +1,3 @@
+- import_tasks: init.yml
+- import_tasks: laravel.yml
+- import_tasks: dashboard.yml

+ 16 - 0
deploy/roles/mint-v2/templates/v1/config.js.j2

@@ -0,0 +1,16 @@
+var ICP_CODE = "{{ app_icp_code }}"
+var RPC_SERVER = "{{ app_rpc_server }}";
+var DOCUMENTS_SERVER = "{{ app_documents_server }}"
+
+/*
+  |---------------
+  |网站资源文件,非用户的图片,音频,视频
+  |---------------
+  |对应/public/tmp/ 目录 开发线可以设置为 http://127.0.0.1:8000/tmp
+  |所有文件存储在 https://drive.google.com/drive/folders/1-4dn4juD-0-lsKndDui2W9nT9wcS_Y33?usp=sharing
+  |开发线可自行下载放到/public/tmp/
+  |或直接引用离您最近的assets server
+  |------------------------
+*/
+
+var ASSETS_SERVER = "{{ app_assets_server }}"

+ 65 - 0
deploy/roles/mint-v2/templates/v1/config.php.j2

@@ -0,0 +1,65 @@
+<?php
+
+#域名设置
+define("RPC_SERVER","{{ app_rpc_server}}");
+define("ASSETS_SERVER","{{ app_assets_server }}");
+define("DOCUMENTS_SERVER","{{ app_documents_server }}");
+define('APP_KEY','{{ app_secret_key }}');
+define('APP_ENV','{{ app_deploy_env }}');
+define('CORS_ALLOWED_ORIGINS', '{{ app_cors_allowed_origins }}');
+/*
+电子邮件设置
+PHPMailer
+*/
+define("Email", [
+                                 "Host"=>"{{ app_smtp_host }}",//Set the SMTP server to send through
+                                 "SMTPAuth"=>true,//Enable SMTP authentication
+                                 "Username"=>'{{ app_smtp_user }}',//SMTP username
+                                 "Password"=>'{{ app_smtp_password }}',//SMTP password
+                                 "Port"=>{{ app_smtp_port }},//TCP port to connect to 465; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
+                                 "From"=>"{{ app_smtp_user }}",
+                                 "Sender"=>"webmaster"
+                                 ]);
+
+/*
+数据库设置
+*/
+define("Database",[
+        "type"=>"pgsql",
+        "server"=>"{{ app_postgresql_host }}",
+        "port"=>{{ app_postgresql_port }},
+        "name"=>"{{ app_postgresql_dbname }}",
+        "sslmode" => "disable",
+        "user" => "{{ app_postgresql_user }}",
+        "password" => "{{ app_postgresql_password }}"
+]);
+
+
+/*
+Redis 设置,
+*/
+define("Redis",[        
+        "host" => "{{ app_redis_host }}",
+        "port" => {{ app_redis_port }},
+        "password" => "",
+        "prefix"=>"{{ app_deploy_env }}://www"
+]);
+
+
+# 雪花id
+define("SnowFlake",[
+        "DatacenterId"=>{{ app_snowflake_data_center_id }},
+        "WorkerId"=>{{ app_snowflake_worker_id }}
+]);
+
+#目录设置,不能更改
+require_once __DIR__."/config.dir.php";
+
+/*
+数据表
+*/
+#表设置,此行不能更改
+require_once __DIR__."/config.table.php";
+
+
+?>

+ 78 - 0
deploy/roles/mint-v2/templates/v2/env.j2

@@ -0,0 +1,78 @@
+BASE_DIR="{{ app_deploy_root }}/.env.global"
+CACHE_DIR="${BASE_DIR}/cache"
+TMP_DIR="${BASE_DIR}/tmp"
+
+APP_NAME="wikipali"
+APP_ENV={{ app_deploy_env }}
+APP_KEY={{ app_secret_key }}
+APP_DEBUG=false
+APP_URL="https://{{ app_domain }}"
+DASHBOARD_URL="https://{{ app_domain }}/pcd"
+
+LOG_CHANNEL=stack
+LOG_DEPRECATIONS_CHANNEL=null
+LOG_LEVEL=info
+
+DB_CONNECTION=pgsql
+DB_HOST={{ app_postgresql_host }}
+DB_PORT={{ app_postgresql_port }}
+DB_DATABASE={{ app_postgresql_dbname }}
+DB_USERNAME={{ app_postgresql_user }}
+DB_PASSWORD="{{ app_postgresql_password }}"
+
+BROADCAST_DRIVER=log
+CACHE_DRIVER=redis
+FILESYSTEM_DRIVER=local
+QUEUE_CONNECTION=sync
+SESSION_DRIVER=cookie
+SESSION_LIFETIME=120
+
+REDIS_HOST={{ app_redis_host }}
+REDIS_PORT={{ app_redis_port }}
+REDIS_PASSWORD=
+REDIS_DB=0
+REDIS_PREFIX="${APP_NAME}://{{ app_deploy_env }}/"
+
+REDIS_CACHE_HOST={{ app_redis_cache_host }}
+REDIS_CACHE_PORT={{ app_redis_cache_port }}
+REDIS_CACHE_PASSWORD=
+REDIS_CACHE_DB={{ app_redis_cache_db }}
+REDIS_CACHE_PREFIX="{{ app_deploy_env }}://"
+
+
+MAIL_MAILER=smtp
+MAIL_HOST={{ app_smtp_host }}
+MAIL_PORT={{ app_smtp_port }}
+MAIL_USERNAME="{{ app_smtp_user }}"
+MAIL_PASSWORD="{{ app_smtp_password }}"
+MAIL_ENCRYPTION=ssl
+MAIL_FROM_ADDRESS="{{ app_smtp_user }}"
+MAIL_FROM_NAME="webmaster"
+
+AWS_ACCESS_KEY_ID=
+AWS_SECRET_ACCESS_KEY=
+AWS_DEFAULT_REGION=us-east-1
+AWS_BUCKET=
+AWS_USE_PATH_STYLE_ENDPOINT=false
+
+PUSHER_APP_ID=
+PUSHER_APP_KEY=
+PUSHER_APP_SECRET=
+PUSHER_APP_CLUSTER=mt1
+
+MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
+MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
+
+ASSETS_SERVER="{{ app_assets_server }}"
+RPC_SERVER="{{ app_rpc_server }}"
+DOCUMENTS_SERVER="{{ app_documents_server }}"
+CORS_ALLOWED_ORIGINS="{{ app_cors_allowed_origins }}"
+
+SNOWFLAKE_DATA_CENTER_ID={{ app_snowflake_data_center_id }}
+SNOWFLAKE_WORKER_ID={{ app_snowflake_worker_id }}
+
+RABBITMQ_HOST="{{ app_rabbitmq_host }}"
+RABBITMQ_PORT={{ app_rabbitmq_port }}
+RABBITMQ_VIRTUAL_HOST="{{ app_rabbitmq_virtual_host }}"
+RABBITMQ_USER="{{ app_rabbitmq_user }}"
+RABBITMQ_PASSWORD="{{ app_rabbitmq_password }}"

+ 8 - 0
deploy/roles/mint-v2/templates/v2/scheduler.service.j2

@@ -0,0 +1,8 @@
+[Unit]
+Description=Mint scheduler for {{ app_deploy_env }}
+
+[Service]
+Type=simple
+User=www-data
+Group=www-data
+ExecStart=cd {{ app_deploy_root }}/htdocs && /usr/bin/php artisan schedule:run >> {{ app_deploy_root }}/logs/scheduler.log 2>&1

+ 9 - 0
deploy/roles/mint-v2/templates/v2/scheduler.timer.j2

@@ -0,0 +1,9 @@
+[Unit]
+Description=Runs Mint mint-{{ app_deploy_env }} scheduler every minute
+
+[Timer]
+OnUnitActiveSec=1minute
+Unit=mint-{{ app_deploy_env }}-scheduler.service
+
+[Install]
+WantedBy=multi-user.target

+ 15 - 0
deploy/scripts/postgresql/2023-10-21-global-fts-setup.sql

@@ -0,0 +1,15 @@
+-- FROM https://github.com/iapt-platform/mint/blob/laravel/database/migrations/2021_12_30_053602_add_func_to_fts_texts_table.php
+
+CREATE TEXT SEARCH CONFIGURATION pali ( parser = pg_catalog.default );
+CREATE TEXT SEARCH CONFIGURATION pali_unaccent ( parser = pg_catalog.default );
+CREATE TEXT SEARCH DICTIONARY pali_stem ( TEMPLATE = synonym, SYNONYMS = pali );
+CREATE TEXT SEARCH DICTIONARY pali_stopwords ( TEMPLATE = pg_catalog.simple, STOPWORDS = pali, ACCEPT = true);
+
+ALTER TEXT SEARCH CONFIGURATION pali
+ADD MAPPING FOR asciiword, word, hword_part, hword_asciipart
+WITH pali_stem, pali_stopwords;
+
+CREATE EXTENSION IF NOT EXISTS "unaccent";
+ALTER TEXT SEARCH CONFIGURATION pali_unaccent
+ADD MAPPING FOR asciiword, word, hword_part, hword_asciipart
+WITH unaccent, pali_stem, pali_stopwords;

+ 0 - 28
scripts/dashboard/deploy.sh

@@ -1,28 +0,0 @@
-#!/bin/bash
-
-set -e
-
-if [ "$#" -ne 1 ]
-then
-    echo "USAGE: $0 DOMAIN"
-    exit 1
-fi
-
-export GIT_VERSION=$(git describe --tags --always --dirty --first-parent)
-
-
-if [ ! -d node_modules ]
-then
-    yarn install
-fi
-
-PUBLIC_URL=/pcd yarn build
-
-
-echo "$GIT_VERSION" > build/VERSION
-echo "$(date -R)" >> build/VERSION
-
-
-rsync -rzv build/ deploy@$1:/var/www/$1/dashboard
-
-echo "done($GIT_VERSION)."