Răsfoiți Sursa

Merge branch 'master' of http://git.fmode.cn:3000/bin/edu-textbook

xll 9 luni în urmă
părinte
comite
fec6ccf867

+ 2 - 0
.gitignore

@@ -1,5 +1,7 @@
 # See https://docs.github.com/get-started/getting-started-with-git/ignoring-files for more about ignoring files.
 
+opt/
+
 # Compiled output
 /dist
 /tmp

+ 12 - 0
README.md

@@ -105,6 +105,18 @@ https://api-explorer.authing.cn/?source=Authing%20%E7%94%A8%E6%88%B7%E8%AE%A4%E8
 
 测试用户池密钥:491670e7ef2fd553ce6d0668a1bb87f3
 
+
+# 开发人员协作
+- 高教社运维负责
+    - 4966367 wuhuaide 1649663385 
+    - 吴怀德  
+    - wuhuaide (867947897@qq.com)
+- Authing项目负责
+    - 韩磊-leohan83
+    - 韩磊   我自己
+    - leohan83 (hanlei@authing.com)
+
+
 # 国家级教材遴选系统——前端项目 edu-textbook
 
 This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 18.0.4.

+ 1 - 0
deploy-www.sh

@@ -11,6 +11,7 @@ TEMP_WWW=/opt/edu-textbook-www
 ng build textbook
 ssh $DEV_HOST "mkdir -p $TEMP_WWW"
 tar zcvf dist/edu-textbook-www.tar.gz dist/textbook/browser/
+cp dist/edu-textbook-www.tar.gz docker-front/opt/ # docker 目录
 scp dist/edu-textbook-www.tar.gz $DEV_HOST:$TEMP_WWW/
 ssh $DEV_HOST "scp -r $TEMP_WWW/edu-textbook-www.tar.gz $PROD_HOST:/var/www/"
 ssh $DEV_HOST "ssh $PROD_HOST \"cd /var/www/ && tar zxvf edu-textbook-www.tar.gz && cp edu-textbook-www.tar.gz edu-textbook/ && cp -rf dist/textbook/browser/* edu-textbook/ \"" # 仅安装prod

+ 1 - 0
docker-front

@@ -0,0 +1 @@
+Subproject commit c6edfa4c6e50ff5f078de4c9cbe976bd233d3462

+ 0 - 1
docker/.gitignore

@@ -1 +0,0 @@
-/opt/*

+ 16 - 62
docker/Dockerfile

@@ -1,19 +1,6 @@
 FROM debian:bullseye-slim
 MAINTAINER FmodeInc "support@fmode.cn"
 
-ARG NODE_VERSION
-ARG TERM
-ARG NGINX_DISABLE
-######################################## ENV LIST
-ENV NODE_VERSION $NODE_VERSION
-ENV TERM $TERM
-ENV NGINX_DISABLE $NGINX_DISABLE
-
-# ENV NODE_VERSION 18.15.0
-# ENV NODE_VERSION 16.3.0
-# ENV NODE_SERVER_PATH $nova_server_path
-# ENV NODE_CMS_PATH $nova_cms_path
-
 ######################################## APT Repos to 163
 # RUN apt-get update
 
@@ -42,69 +29,36 @@ RUN ARCH= && dpkgArch="$(dpkg --print-architecture)" \
     # libatomic1 for arm
     && apt-get update && apt-get install -y ca-certificates apt-utils curl wget gnupg dirmngr xz-utils libatomic1 --no-install-recommends \
     && rm -rf /var/lib/apt/lists/* \
-    && curl -fsSLO --compressed "https://npmmirror.com/mirrors/node/v$NODE_VERSION/node-v$NODE_VERSION-linux-$ARCH.tar.xz" \
-    && curl -fsSLO --compressed "https://npmmirror.com/mirrors/node/v$NODE_VERSION/SHASUMS256.txt.asc" \
-    && tar -xJf "node-v$NODE_VERSION-linux-$ARCH.tar.xz" -C /usr/local --strip-components=1 --no-same-owner \
-    && rm "node-v$NODE_VERSION-linux-$ARCH.tar.xz" \
+    && curl -fsSLO --compressed "https://npmmirror.com/mirrors/node/v18.19.1/node-v18.19.1-linux-$ARCH.tar.xz" \
+    && curl -fsSLO --compressed "https://npmmirror.com/mirrors/node/v18.19.1/SHASUMS256.txt.asc" \
+    && tar -xJf "node-v18.19.1-linux-$ARCH.tar.xz" -C /usr/local --strip-components=1 --no-same-owner \
+    && rm "node-v18.19.1-linux-$ARCH.tar.xz" \
     && ln -s /usr/local/bin/node /usr/local/bin/nodejs
 
 
-
-######################################## Copy Latest Nova Cloud
-COPY ./opt/ /opt/
-COPY ./var/ /var/
-
-RUN cd /var/www/ && wget http://8.140.98.43/edu-textbook-www.tar.gz && tar zxvf edu-textbook-www.tar.gz && cp -rf dist/textbook/browser/* edu-textbook/
-RUN cd /opt/ && wget http://8.140.98.43/server.tar.gz && tar zxvf server.tar.gz && mv server/* edu-textbook-server/ && mkdir -p /etc/nginx/sites-enabled/ && cp -rf /opt/edu-textbook-server/config/nginx-server.conf /etc/nginx/sites-enabled/
-
-RUN ls /opt/ && chown -R root:root /opt/*
-
 ######################################## Nginx
 # curl http检测
 # procps 进程管理
 RUN apt-get update &&apt-get install -y nginx procps && apt-get install -y nginx curl --no-install-recommends \
   && rm -rf /etc/nginx/sites-enabled/*  && service nginx restart
 
+######################################## Copy Latest System
+COPY ./opt/ /opt/
+
+RUN mkdir -p /opt/edu-textbook-server/ && cd /opt/ && tar zxvf server.tar.gz && mv server/* edu-textbook-server/ && mkdir -p /etc/nginx/sites-enabled/ && cp -rf /opt/edu-textbook-server/config/nginx-server.conf /etc/nginx/sites-enabled/ && service nginx restart
+
+RUN ls /opt/ && chown -R root:root /opt/*
+
 
 ######################################## PM2 && server node_modules
-RUN npm config set registry https://registry.npmmirror.com/ && npm i -g pm2@5.1.1 && cd /opt/edu-textbook-server/ && npm i -f
-# RUN npm i -g bytenode@1.3.6
-
-######################################## Deploy Latest Nova Cloud
-RUN cd /opt/edu-textbook-server && pm2 start server.js \
-    && sleep 5s \
-    && pm2 startup && pm2 save \
-
-######################################## Verify All Depands is OK
-
-    && node --version \
-    && pm2 ls \
-    && node --version \
-    && npm --version 
-
-######################################## Clean All Resources
-RUN apt-mark auto '.*' > /dev/null \
-    && find /usr/local -type f -executable -exec ldd '{}' ';' \
-      | awk '/=>/ { print $(NF-1) }' \
-      | sort -u \
-      | xargs -r dpkg-query --search \
-      | cut -d: -f1 \
-      | sort -u \
-      | xargs -r apt-mark manual \
-    && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
-    && rm -rf /var/log/* \
-    && env
-    # && rm -r /var/log/postgresql/* \
-    # && rm -r /var/log/apt/* \
-    # && rm -r /var/log/nginx/* \
-
-
-# COPY docker-entrypoint.sh /usr/local/bin/
+RUN npm config set registry https://registry.npmmirror.com/ && npm i -g npm@10.8.1
+RUN cd /opt/edu-textbook-server/ && npm i --omit dev  --no-warn
+
+CMD ["service","nginx","restart"]
 
 # DEFAULT WEB
 EXPOSE 80
-EXPOSE 61337
 # DEFAULT SSL
 EXPOSE 443
 
-ENTRYPOINT [ "node","/opt/edu-textbook-server/keepalive.js" ]
+ENTRYPOINT [ "node","/opt/edu-textbook-server/server.js" ]

+ 40 - 0
docker/README.md

@@ -0,0 +1,40 @@
+# 十四五本科教材部署项目
+
+# 目录资源
+- /opt/ 软件包
+    - edu-textbook-www.tar.gz 前端项目
+    - server.tar.gz 后端项目
+- sources.list 国内源
+- Dockerfile 容器编制脚本
+
+# 环境变量
+``` bash
+# 环境变量
+DATABASE_DBNAME # 链接字符串 postgres://xxxxxxx:5432/textbook
+ALI_OSS_BUCKET # 阿里云OSS bucket
+ALI_OSS_ACCESS_KEY_ID # 阿里云OSS ak
+ALI_OSS_ACCESS_KEY_SECRE # 阿里云OSS sk
+```
+
+# 常用指令
+
+``` bash
+# 容器构建
+sudo docker build --tag fmode:edu-textbook-1.0.0 . \
+# --build-arg NODE_VERSION=18.19.1 \
+# > 注意阿里云build流水线中,容易丢失环境变量配置,所以直接写在Dockerfile中
+
+# 运行容器
+sudo docker run -d -p 80:80 -p 81:81 -p 443:443 -p 61337:61337 --name edu-textbook-1.0.0 --restart=always fmode:edu-textbook-1.0.0
+sudo docker run -e DATABASE_DBNAME="postgres://postgres:666@192.168.0.177:5432/postgres" -p 80:80 -p 81:81 -p 443:443 -p 61337:61337 --name edu-textbook-1.0.0 --restart=always fmode:edu-textbook-1.0.0
+
+# 导出镜像
+sudo docker save fmode:edu-textbook-1.0.0 -o ../dist/fmode-edu-textbook-1.0.0.tar
+
+```
+
+# 工作流(阿里云镜像构建部署)
+- 后端WebHook
+    - http://flow-openapi.aliyun.com/scm/webhook/536ptuKD686Wn6vEqVIz
+        - https://gitee.com/hep10/tbook-backend.git
+        - 临时地址 http://145.tbook.com.cn/api

+ 0 - 24
docker/build.sh

@@ -1,24 +0,0 @@
-sudo docker build \
---build-arg NODE_VERSION=18.19.1 \
---tag fmode:edu-textbook-1.0.0 .
-
-
-
-# 服务端
-# mkdir -p opt/edu-textbook-server/certs
-# mkdir -p opt/certs/tbook.com.cn/
-# cp ../server/dist/server/server.js opt/edu-textbook-server/
-# cp ../server/package.json opt/edu-textbook-server/
-# cp ../server/config.js opt/edu-textbook-server/
-# cp ../server/keepalive.js opt/edu-textbook-server/
-# cp ../server/config/certs/* opt/certs/tbook.com.cn/certs/
-
-# mkdir -p opt/nginx
-# cp ../server/config/nginx-server.conf opt/edu-textbook-server/nginx/
-
-# 前端
-# mkdir -p var/www/edu-textbook
-# cp ../dist/edu-textbook-www.tar.gz var/www/
-
-
-# 构建

+ 0 - 7
docker/make.sh

@@ -1,7 +0,0 @@
-
-# 运行容器
-PNAME='edu-textbook-1.0.0' \
-&& sudo docker run -d -p 80:80 -p 81:81 -p 443:443 -p 61337:61337 --name $PNAME --restart=always fmode:$PNAME
-
-# 导出镜像
-sudo docker save fmode:edu-textbook-1.0.0 -o ../dist/fmode-edu-textbook-1.0.0.tar

+ 5 - 0
docker/update.sh

@@ -0,0 +1,5 @@
+# 更新前后端软件包至opt/
+cd ../
+./deploy-www.sh
+cd server
+./deploy.sh

BIN
docker/var/www/edu-textbook-www.tar.gz


BIN
docker/var/www/edu-textbook/edu-textbook-www.tar.gz


+ 2 - 1
projects/textbook/src/app/app.component.ts

@@ -17,7 +17,8 @@ export class AppComponent {
   initParseService(){
     Parse.initialize("edu-textbook");
     // (Parse as any).serverURL = ("http://127.0.0.1:61337/parse");
-    (Parse as any).serverURL = ("http://8.140.98.43/parse");
+    // (Parse as any).serverURL = ("http://8.140.98.43/parse");
+    (Parse as any).serverURL = ("https://145.tbook.com.cn/parse");
     localStorage.setItem('company','RbIKpmuaMC')
   }
 

+ 9 - 152
server/config/nginx-server.conf

@@ -1,122 +1,3 @@
-# server {
-
-#     server_name _;
-#     server_tokens off;
-
-#     #large_client_header_buffers 4 32k;
-#     client_max_body_size 50M;
-
-#     charset utf-8;
-
-#     index index.html;
-
-
-#     # 启动SSL及证书匹配 ######################################################
-#     listen 443 ssl default_server; # managed by Certbot
-    
-#     # ssl_certificate /etc/letsencrypt/live/edutextbook/fullchain.pem; # managed by Certbot
-#     # ssl_certificate_key /etc/letsencrypt/live/edutextbook/privkey.pem; # managed by Certbot
-
-#     # include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
-#     # ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
-
-# 	# 启用OCSP stapling ######################################################
-# 	ssl_stapling on;
-# 	ssl_stapling_verify on;
-# 	# valid表示缓存5分钟
-# 	resolver 8.8.8.8 8.8.4.4 valid=300s;
-# 	# 网络超时时间
-# 	resolver_timeout 5s;
-
-# 	# 启动Gzip Json模式 ######################################################
-# 	gzip_http_version 1.0;  # gzip支持http协议 proxy 必须用
-#     gzip  on;
-# 	gzip_vary on;
-# 	gzip_proxied       any;
-# 	gzip_static on;
-# 	gzip_comp_level  4;
-# 	gzip_min_length 256;
-#     gzip_buffers     4 8k;
-#     gzip_types       text/html text/plain application/javascript application/x-javascript text/css application/xml application/json;
-
-#     location /api {
-#         if ($request_method = 'OPTIONS') {
-#             add_header 'Access-Control-Allow-Origin' '*';
-#             add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
-#             #
-#             # Custom headers and headers various browsers *should* be OK with but aren't
-#             #
-#             add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
-#             #
-#             # Tell client that this pre-flight info is valid for 20 days
-#             #
-#             add_header 'Access-Control-Max-Age' 1728000;
-#             add_header 'Content-Type' 'text/plain; charset=utf-8';
-#             add_header 'Content-Length' 0;
-#             return 204;
-#         }
-#         if ($request_method = 'POST') {
-#             add_header 'Access-Control-Allow-Origin' '*' always;
-#             add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
-#             add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Access-Control-Allow-Origin' always;
-#             add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
-#         }
-#         if ($request_method = 'GET') {
-#             add_header 'Access-Control-Allow-Origin' '*' always;
-#             add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
-#             add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Access-Control-Allow-Origin' always;
-#             add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
-#         }
-
-#         rewrite ^/(.*)$ /$1 break;
-#         proxy_pass http://127.0.0.1:61337/api;
-#     }
-
-#     location /parse {
-#         if ($request_method = 'OPTIONS') {
-#             add_header 'Access-Control-Allow-Origin' '*';
-#             add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
-#             #
-#             # Custom headers and headers various browsers *should* be OK with but aren't
-#             #
-#             add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
-#             #
-#             # Tell client that this pre-flight info is valid for 20 days
-#             #
-#             add_header 'Access-Control-Max-Age' 1728000;
-#             add_header 'Content-Type' 'text/plain; charset=utf-8';
-#             add_header 'Content-Length' 0;
-#             return 204;
-#         }
-#         if ($request_method = 'POST') {
-#             add_header 'Access-Control-Allow-Origin' '*' always;
-#             add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
-#             add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Access-Control-Allow-Origin' always;
-#             add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
-#         }
-#         if ($request_method = 'GET') {
-#             add_header 'Access-Control-Allow-Origin' '*' always;
-#             add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
-#             add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Access-Control-Allow-Origin' always;
-#             add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
-#         }
-
-#         rewrite ^/(.*)$ /$1 break;
-#         proxy_pass http://127.0.0.1:61337/parse;
-#     }
-
-#     location /{
-#         proxy_set_header Host $http_host;
-#         proxy_set_header X-Real-IP $remote_addr;
-#         proxy_set_header X-Scheme $scheme;
-#         proxy_set_header X-Forwarded-Proto $scheme;
-#         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
-#         proxy_pass http://127.0.0.1:61337/;
-#         proxy_redirect off;
-#     }
-
-# }
-
 
 server {
     listen 80 default_server;
@@ -132,39 +13,6 @@ server {
 	gzip_min_length 256;
     gzip_buffers     4 8k;
     gzip_types       text/html text/plain application/javascript application/x-javascript text/css application/xml application/json;
-    
-    location /api {
-        if ($request_method = 'OPTIONS') {
-            add_header 'Access-Control-Allow-Origin' '*';
-            add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
-            #
-            # Custom headers and headers various browsers *should* be OK with but aren't
-            #
-            add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
-            #
-            # Tell client that this pre-flight info is valid for 20 days
-            #
-            add_header 'Access-Control-Max-Age' 1728000;
-            add_header 'Content-Type' 'text/plain; charset=utf-8';
-            add_header 'Content-Length' 0;
-            return 204;
-        }
-        if ($request_method = 'POST') {
-            add_header 'Access-Control-Allow-Origin' '*' always;
-            add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
-            add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Access-Control-Allow-Origin' always;
-            add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
-        }
-        if ($request_method = 'GET') {
-            add_header 'Access-Control-Allow-Origin' '*' always;
-            add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
-            add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Access-Control-Allow-Origin' always;
-            add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
-        }
-
-        rewrite ^/(.*)$ /$1 break;
-        proxy_pass http://127.0.0.1:61337/api;
-    }
 
     location /parse/{
         proxy_set_header Host $http_host;
@@ -175,6 +23,15 @@ server {
         proxy_pass http://127.0.0.1:61337/parse/;
         proxy_redirect off;
     }
+    location /api/parse/{
+        proxy_set_header Host $http_host;
+        proxy_set_header X-Real-IP $remote_addr;
+        proxy_set_header X-Scheme $scheme;
+        proxy_set_header X-Forwarded-Proto $scheme;
+        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+        proxy_pass http://127.0.0.1:61337/parse/;
+        proxy_redirect off;
+    }
 
     root /var/www/edu-textbook/;
     location /{

+ 3 - 0
server/deploy.sh

@@ -10,10 +10,13 @@ DIR_SERVER=/opt/edu-textbook-server
 # 资源文件
 cp -rf config dist/server/
 cp package.json dist/server/
+sed -i '/@embedded/d' dist/server/package.json
+sed -i '/@embedded/d' dist/server/package.json
 cp config.js dist/server/
 cp keepalive.js dist/server/
 cd dist
 tar zcvf server.tar.gz ./server
+cp server.tar.gz ../../docker/opt/
 cd ..
 
 # 压缩部署

+ 4 - 2
server/package-lock.json

@@ -9,8 +9,6 @@
       "version": "1.0.0",
       "license": "ISC",
       "dependencies": {
-        "@embedded-postgres/linux-x64": "^16.2.0-beta.11",
-        "@embedded-postgres/windows-x64": "^16.2.0-beta.11",
         "ali-oss": "^6.20.0",
         "authing-js-sdk": "^4.23.51",
         "authing-node-sdk": "^3.1.0",
@@ -24,6 +22,8 @@
         "server": "server.js"
       },
       "devDependencies": {
+        "@embedded-postgres/linux-x64": "^16.2.0-beta.11",
+        "@embedded-postgres/windows-x64": "^16.2.0-beta.11",
         "pkg": "^5.8.1",
         "vite": "^4.5.3",
         "vite-plugin-dts": "^3.9.1",
@@ -743,6 +743,7 @@
       "cpu": [
         "x64"
       ],
+      "dev": true,
       "hasInstallScript": true,
       "os": [
         "linux"
@@ -758,6 +759,7 @@
       "cpu": [
         "x64"
       ],
+      "dev": true,
       "hasInstallScript": true,
       "os": [
         "win32"

+ 2 - 2
server/package.json

@@ -28,8 +28,6 @@
   "author": "",
   "license": "ISC",
   "dependencies": {
-    "@embedded-postgres/linux-x64": "^16.2.0-beta.11",
-    "@embedded-postgres/windows-x64": "^16.2.0-beta.11",
     "ali-oss": "^6.20.0",
     "authing-js-sdk": "^4.23.51",
     "authing-node-sdk": "^3.1.0",
@@ -40,6 +38,8 @@
     "yargs": "17.7.2"
   },
   "devDependencies": {
+    "@embedded-postgres/linux-x64": "^16.2.0-beta.11",
+    "@embedded-postgres/windows-x64": "^16.2.0-beta.11",
     "pkg": "^5.8.1",
     "vite": "^4.5.3",
     "vite-plugin-dts": "^3.9.1",

+ 1 - 1
server/vite.config.js

@@ -27,7 +27,7 @@ export default defineConfig({
                 controlFlowFlatteningThreshold: 0.5,
                 deadCodeInjection: false,
                 deadCodeInjectionThreshold: 0.2,
-                disableConsoleOutput: true,
+                disableConsoleOutput: false, // 禁用日志输出,调试时关闭
                 identifierNamesGenerator: 'hexadecimal',
                 log: true,
                 renameGlobals: false,