This commit is contained in:
fafa_junhe 2024-06-19 19:23:01 +08:00
parent d6680d9966
commit f3c6f1e70b
43 changed files with 406 additions and 18 deletions

3
.gitignore vendored
View File

@ -1,3 +1,4 @@
.idea
node_modules
__pycache__
__pycache__
public

3
app-dm/.dockerignore Executable file
View File

@ -0,0 +1,3 @@
.idea
node_modules
__pycache__

14
app-dm/Dockerfile Executable file
View File

@ -0,0 +1,14 @@
FROM node:22 AS builder
WORKDIR /usr/src/app
COPY package.json package-lock.json ./
RUN npm config set registry https://registry.npmmirror.com
RUN npm install
COPY . ./
#RUN NODE_OPTIONS=--max_old_space_size=8192 yarn build
RUN npm run build

View File

@ -44,7 +44,7 @@
"start": "react-scripts start",
"test": "react-scripts test",
"eject": "react-scripts eject",
"build": "postcss src/style.css -o dist/tailwind.css"
"build": "react-scripts build"
},
"eslintConfig": {
"extends": [

3
build.sh Executable file
View File

@ -0,0 +1,3 @@
docker compose build
docker compose build build-dmpython
docker compose build build-frontend

47
docker-compose.yml Executable file
View File

@ -0,0 +1,47 @@
services:
base-dm:
build: ./docker/base-dm
image: base-dm
build-dmpython:
build: ./docker/build-dmpython
image: build-dmpython
depends_on:
- base-dm
build-frontend:
build: ./app-dm
image: build-frontend
flask-app:
build: ./python
restart: always
depends_on:
- base-dm
ports:
- '8000:8000'
healthcheck:
test: ["CMD-SHELL", "curl --silent --fail localhost:8000/flask-health-check || exit 1"]
interval: 10s
timeout: 10s
retries: 3
command: gunicorn -w 3 -t 60 -b 0.0.0.0:8000 app:app
nginx-proxy:
build: ./docker/nginx
restart: always
volumes:
- ./docker/nginx/default.conf:/tmp/default.conf
environment:
- FLASK_SERVER_ADDR=flask-app:8000
ports:
- "80:80"
depends_on:
- flask-app
healthcheck:
test: ["CMD-SHELL", "curl --silent --fail localhost:80/health-check || exit 1"]
interval: 10s
timeout: 10s
retries: 3
command: /app/start.sh

35
docker/base-dm/Dockerfile Executable file
View File

@ -0,0 +1,35 @@
FROM ubuntu
# apt安装时防止卡死在交互界面
ENV DEBIAN_FRONTEND=noninteractive
ENV LANG=zh_CN.UTF-8
ENV LC_ALL=zh_CN.UTF-8
# 基础软件安装
RUN sed -i 's@//.*archive.ubuntu.com@//mirrors.ustc.edu.cn@g' /etc/apt/sources.list \
&& apt-get -y update && apt-get -y upgrade \
&& apt-get install -y python3.10-venv libssl-dev sudo vim python3-pip ssh wget unzip p7zip* language-pack-zh-hans language-selector-common locales locales-all \
# 设置中文环境
&& apt install -y $(check-language-support) \
&& echo "zh_CN.UTF-8 UTF-8" >> /etc/locale.gen \
&& sudo /usr/sbin/update-locale LANG=zh_CN.UTF-8 LC_ALL=zh_CN.UTF-8 \
&& locale-gen \
# 添加用户
&& useradd -m -s /bin/bash dmdba \
# 修改用户密码
&& echo "dmdba:123456" | chpasswd \
&& pip config set global.index-url https://mirrors.bfsu.edu.cn/pypi/web/simple \
&& echo "**** clean up ****" && \
apt-get clean && \
rm -rf \
/config/* \
/tmp/* \
/var/lib/apt/lists/* \
/var/tmp/*
# 传入安装包并解压
WORKDIR /home/dmdba
RUN wget https://download.dameng.com/eco/adapter/DM8/202405/dm8_20240408_x86_rh7_64_ent_8.1.3.140.zip
RUN unzip dm8_20240408_x86_rh7_64_ent_8.1.3.140.zip \
&& chown -R dmdba:dmdba /home/dmdba \
&& rm -f dm8_20240408_x86_rh7_64_ent_8.1.3.140.zip \
&& 7z x dm8_20240408_x86_rh7_64.iso \
&& rm -f dm8_20240408_x86_rh7_64.iso \
&& chmod +x DMInstall.bin

View File

@ -0,0 +1,7 @@
FROM base-dm
WORKDIR /home/dmdba
COPY auto_install.xml .
RUN ./DMInstall.bin -q /home/dmdba/auto_install.xml
# 编译
WORKDIR /home/dmdba/dmdbms/drivers/python/dmPython
RUN DM_HOME=/home/dmdba/dmdbms python3 setup.py bdist_wheel && mkdir /home/dmdba/build_artifacts && cp dist/dmPython-2.5.5-cp310-cp310-linux_x86_64.whl /home/dmdba/build_artifacts/ && cp /home/dmdba/dmdbms/bin/libdmdpi.so /home/dmdba/build_artifacts/

View File

@ -0,0 +1,122 @@
<?xml version="1.0"?>
<DATABASE>
<!--安装数据库的语言配置,简体中文版: CHS繁体中文版: CHT英文版: EN不区分大小写。不允许为空。 -->
<LANGUAGE>ZH</LANGUAGE>
<!--安装程序的时区配置,缺省为+08:00取值范围-12:59 ~ +14:00 -->
<TIME_ZONE>+08:00</TIME_ZONE>
<!-- key文件路径 -->
<KEY></KEY>
<!--安装程序组件类型取值范围0、1、20 表示安装全部1 表示安装服务器2 表示安装客户端。缺省为0。 -->
<INSTALL_TYPE>0</INSTALL_TYPE>
<!--安装路径,不允许为空。 -->
<INSTALL_PATH>/home/dmdba/dmdbms</INSTALL_PATH>
<!--是否初始化库取值范围Y/N、y/n不允许为空。 -->
<INIT_DB>y</INIT_DB>
<!--数据库实例参数 -->
<DB_PARAMS>
<!--初始数据库存放的路径,不允许为空 -->
<PATH>/home/dmdba/dmdbms/data</PATH>
<!--初始化数据库名字缺省为DAMENG不超过128个字符 -->
<DB_NAME>DAMENG</DB_NAME>
<!--初始化数据库实例名字缺省为DMSERVER不超过128个字符 -->
<INSTANCE_NAME>DMSERVER</INSTANCE_NAME>
<!--初始化时设置dm.ini中的PORT_NUM缺省为5236取值范围1024~65534 -->
<PORT_NUM>5236</PORT_NUM>
<!--初始数据库控制文件的路径文件路径长度最大为256 -->
<CTL_PATH></CTL_PATH>
<!--初始化数据库日志文件的路径文件路径长度最大为256LOG_PATH值为空则使用缺省值如果使用非默认值LOG_PATH节点数不能少于2个 -->
<LOG_PATHS>
<LOG_PATH>
</LOG_PATH>
</LOG_PATHS>
<!--数据文件使用的簇大小取值范围16页、32页缺省为16页 -->
<EXTENT_SIZE>16</EXTENT_SIZE>
<!--数据文件使用的页大小取值范围4K、8K、16K、32K缺省为8K -->
<PAGE_SIZE>8</PAGE_SIZE>
<!--日志文件使用的簇大小缺省为256取值范围为64~2048之间的整数 -->
<LOG_SIZE>256</LOG_SIZE>
<!--标识符大小写敏感。取值范围Y/N y/n 1/0缺省为Y -->
<CASE_SENSITIVE>Y</CASE_SENSITIVE>
<!--字符集选项缺省为0。0代表GB18030,1代表UTF-8,2代表韩文字符集EUC-KR -->
<CHARSET>0</CHARSET>
<!--规定VARCHAR对象长度的单位。取值范围01。1所有VARCHAR类型对象的长度以字符为单位0有VARCHAR类型对象的长度以字节为单位。缺省为0。 -->
<LENGTH_IN_CHAR>0</LENGTH_IN_CHAR>
<!--字符类型在计算HASH值时所采用的HASH算法类别。取值范围01。0原始HASH算法1改进的HASH算法。缺省为1。 -->
<USE_NEW_HASH>1</USE_NEW_HASH>
<!--初始化时设置SYSDBA的密码缺省为SYSDBA长度在9到48个字符之间 -->
<SYSDBA_PWD></SYSDBA_PWD>
<!--初始化时设置SYSAUDITOR的密码缺省为SYSAUDITOR长度在9到48个字符之间 -->
<SYSAUDITOR_PWD></SYSAUDITOR_PWD>
<!--初始化时设置SYSSSO的密码缺省为SYSSSO长度在9到48个字符之间仅在安全版本下可见和可设置 -->
<SYSSSO_PWD></SYSSSO_PWD>
<!--初始化时设置SYSDBO的密码缺省为SYSDBO长度在9到48个字符之间仅在安全版本下可见和可设置 -->
<SYSDBO_PWD></SYSDBO_PWD>
<!--初始化时区,默认是东八区。格式为:正负号小时:分钟,取值范围:-12:59 ~ +14:00 -->
<TIME_ZONE>+08:00</TIME_ZONE>
<!--是否启用页面内容校验取值范围012。0不启用1简单校验2严格校验(使用CRC16算法生成校验码)。缺省为0 -->
<PAGE_CHECK>0</PAGE_CHECK>
<!--设置默认加密算法不超过128个字符 -->
<EXTERNAL_CIPHER_NAME></EXTERNAL_CIPHER_NAME>
<!--设置默认HASH算法不超过128个字符 -->
<EXTERNAL_HASH_NAME></EXTERNAL_HASH_NAME>
<!--设置根密钥加密引擎不超过128个字符 -->
<EXTERNAL_CRYPTO_NAME></EXTERNAL_CRYPTO_NAME>
<!--全库加密密钥使用的算法名。算法可以是DM内部支持的加密算法或者是第三方的加密算法。默认使用"AES256_ECB"算法加密最长为128个字节 -->
<ENCRYPT_NAME></ENCRYPT_NAME>
<!--用于加密服务器根密钥最长为48个字节 -->
<USBKEY_PIN></USBKEY_PIN>
<!--设置空格填充模式取值范围01缺省为0 -->
<BLANK_PAD_MODE>0</BLANK_PAD_MODE>
<!--指定system.dbf文件的镜像路径缺省值为空 -->
<SYSTEM_MIRROR_PATH></SYSTEM_MIRROR_PATH>
<!--指定main.dbf文件的镜像路径缺省值为空 -->
<MAIN_MIRROR_PATH></MAIN_MIRROR_PATH>
<!--指定roll.dbf文件的镜像路径缺省值为空 -->
<ROLL_MIRROR_PATH></ROLL_MIRROR_PATH>
<!--是否是四权分立取值范围01。0不使用1使用。缺省为0。仅在安全版本下可见和可设置。-->
<PRIV_FLAG>0</PRIV_FLAG>
<!--指定初始化过程中生成的日志文件所在路径。合法的路径文件路径长度最大为257(含结束符),不包括文件名-->
<ELOG_PATH></ELOG_PATH>
</DB_PARAMS>
<!--是否创建数据库实例的服务,取值范围: Y/N y/n不允许为空不初始化数据库将忽略此节点。非root用户不能创建数据库服务。 -->
<CREATE_DB_SERVICE>Y</CREATE_DB_SERVICE>
<!--是否启动数据库,取值范围: Y/N y/n不允许为空不创建数据库服务将忽略此节点。 -->
<STARTUP_DB_SERVICE>N</STARTUP_DB_SERVICE>
</DATABASE>

32
docker/nginx/Dockerfile Executable file
View File

@ -0,0 +1,32 @@
FROM nginx:1.19.7-alpine
# Add bash for boot cmd
RUN apk add bash
# Add nginx.conf to container
COPY --chown=nginx:nginx nginx.conf /etc/nginx/nginx.conf
COPY --chown=nginx:nginx start.sh /app/start.sh
# set workdir
WORKDIR /app
# permissions and nginx user for tightened security
RUN chown -R nginx:nginx /app && chmod -R 755 /app && \
chown -R nginx:nginx /var/cache/nginx && \
chown -R nginx:nginx /var/log/nginx && \
chmod -R 755 /var/log/nginx; \
chown -R nginx:nginx /etc/nginx/conf.d
RUN touch /var/run/nginx.pid && chown -R nginx:nginx /var/run/nginx.pid
# # Uncomment to keep the nginx logs inside the container - Leave commented for logging to stdout and stderr
# RUN mkdir -p /var/log/nginx
# RUN unlink /var/log/nginx/access.log \
# && unlink /var/log/nginx/error.log \
# && touch /var/log/nginx/access.log \
# && touch /var/log/nginx/error.log \
# && chown nginx /var/log/nginx/*log \
# && chmod 644 /var/log/nginx/*log
USER nginx
CMD ["nginx", "-g", "'daemon off;'"]

29
docker/nginx/default.conf Executable file
View File

@ -0,0 +1,29 @@
proxy_cache_path /tmp/cache levels=1:2 keys_zone=cache:10m max_size=500m inactive=60m use_temp_path=off;
server {
listen 80;
location / {
proxy_pass http://$FLASK_SERVER_ADDR;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /cache-me {
proxy_pass http://$FLASK_SERVER_ADDR;
proxy_cache cache;
proxy_cache_lock on;
proxy_cache_valid 200 30s;
proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
proxy_cache_revalidate on;
proxy_cache_background_update on;
expires 20s;
}
location /health-check {
add_header Content-Type text/plain;
return 200 "success";
}
}

50
docker/nginx/nginx.conf Executable file
View File

@ -0,0 +1,50 @@
worker_processes auto;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Define the format of log messages.
log_format main_ext '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" '
'"$host" sn="$server_name" '
'rt=$request_time '
'ua="$upstream_addr" us="$upstream_status" '
'ut="$upstream_response_time" ul="$upstream_response_length" '
'cs=$upstream_cache_status' ;
access_log /var/log/nginx/access.log main_ext;
error_log /var/log/nginx/error.log warn;
sendfile on;
keepalive_timeout 65;
# Enable Compression
gzip on;
# Disable Display of NGINX Version
server_tokens off;
# Size Limits
client_body_buffer_size 10K;
client_header_buffer_size 1k;
client_max_body_size 8m;
large_client_header_buffers 2 1k;
# # SSL / TLS Settings - Suggested for Security
# ssl_protocols TLSv1.2 TLSv1.3;
# ssl_session_timeout 15m;
# ssl_ciphers ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256;
# ssl_prefer_server_ciphers on;
# ssl_session_tickets off;
include /etc/nginx/conf.d/*.conf;
}

2
docker/nginx/start.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/bash
envsubst '$FLASK_SERVER_ADDR' < /tmp/default.conf > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'

View File

@ -16,11 +16,11 @@ RUN sed -i 's@//.*archive.ubuntu.com@//mirrors.ustc.edu.cn@g' /etc/apt/sources.l
# 修改用户密码
&& echo "dmdba:123456" | chpasswd
# 传入安装包并解压
COPY ./data/dm8.zip /home/dmdba
RUN cd /home/dmdba \
&& unzip dm8.zip \
WORKDIR /home/dmdba
RUN wget https://download.dameng.com/eco/adapter/DM8/202405/dm8_20240408_x86_rh7_64_ent_8.1.3.140.zip
RUN unzip dm8_20240408_x86_rh7_64_ent_8.1.3.140.zip \
&& chown -R dmdba:dmdba /home/dmdba \
&& rm -f dm8.zip \
&& rm -f dm8_20240408_x86_rh7_64_ent_8.1.3.140.zip \
&& 7z x dm8_20240408_x86_rh7_64.iso \
&& rm -f dm8_20240408_x86_rh7_64.iso \
&& chmod +x DMInstall.bin
&& chmod +x DMInstall.bin

33
python/Dockerfile Executable file
View File

@ -0,0 +1,33 @@
FROM base-dm
# 升级pip
RUN pip install --upgrade pip
# 创建一个用户运行flask
RUN adduser flask
RUN chown -R flask:flask /home/flask
RUN mkdir -p /var/log/flask-app && touch /var/log/flask-app/flask-app.err.log && touch /var/log/flask-app/flask-app.out.log
RUN chown -R flask:flask /var/log/flask-app
WORKDIR /home/flask
USER flask
# 复制
COPY --chown=flask:flask . .
# venv
ENV VIRTUAL_ENV=/home/flask/venv
# 安装包
RUN python3 -m venv "$VIRTUAL_ENV"
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
RUN export FLASK_APP=main.py
COPY --from=build-dmpython --chown=flask:flask /home/dmdba/build_artifacts/dmPython-2.5.5-cp310-cp310-linux_x86_64.whl .
COPY --from=build-dmpython /home/dmdba/build_artifacts/libdmdpi.so /usr/lib/
COPY --from=build-frontend /usr/src/app/build/ /home/flask/public/
RUN pip3 install dmPython-2.5.5-cp310-cp310-linux_x86_64.whl && rm dmPython-2.5.5-cp310-cp310-linux_x86_64.whl
RUN MAKEFLAGS="-j$(nproc)" pip install -r requirements.txt
USER root
# 暴露端口
EXPOSE 5000
CMD ["python", "main.py"]

View File

@ -1,9 +1,9 @@
from teacher_func import *
from student_func import *
from flask import Flask, request, jsonify, session, redirect
from flask import Flask, render_template, request, jsonify, send_from_directory, session
from flask_cors import CORS
app = Flask(__name__)
app = Flask(__name__, static_folder="public")
CORS(app, resources={r"/*": {"origins": "*"}})
app.config['SECRET_KEY'] = '350625'
@ -209,6 +209,13 @@ def SendTrainTest():
SendTrainTestFunc(TrainChoice, TrainCompletion, TrainJudge, Hour, Min, StopTime,Class,Train,teacher_id)
return '发布成功'
@app.route('/')
@app.route('/<path:path>')
def catch_all(path = "index.html"):
return send_from_directory("public", path)
if __name__ == '__main__':
app.run(host='127.0.0.1', port=5000, debug=True)
app.run(host='0.0.0.0', port=5000, debug=True)

4
python/requirements.txt Executable file
View File

@ -0,0 +1,4 @@
Flask==2.3.0
Flask_Cors==4.0.0
pycryptodome==3.19.0
gunicorn

View File

@ -4,7 +4,7 @@ from Crypto.Cipher import AES
from Crypto.Random import get_random_bytes
import base64
db = dmPython.connect(user='SYSDBA', password='SYSDBA')
db = dmPython.connect(user='SYSDBA', password='dameng!!', host="36.138.114.105", port="32522")
def pad(data):

View File

@ -6,7 +6,7 @@ import base64
import datetime
db = dmPython.connect(user='SYSDBA', password='SYSDBA')
db = dmPython.connect(user='SYSDBA', password='dameng!!', host="36.138.114.105", port="32522")
#获取题目
def choice_question_func(ID):

View File

@ -1,6 +0,0 @@
my_dict = {'name': 'Tom', 'age': 18, 'gender': 'ale'}
# 在原来的键上添加新的值
my_dict['name'] = 'Jerry'
print(my_dict)

5
python/wsgi.py Executable file
View File

@ -0,0 +1,5 @@
from app import app
import os
if __name__ == "__main__":
app.run(host='0.0.0.0', port=os.environ.get("FLASK_SERVER_PORT"), debug=True)