lmstack 3 years ago
parent
commit
4a95d19182

+ 0 - 0
LIB/MIDDLE/AlgoTest/Algo1/V_1_0_0/core.py → LIB/MIDDLE/AlgoTest/Algo1/V_1_0_0/CoreAlgo/core.py


+ 36 - 0
LIB/MIDDLE/AlgoTest/Algo1/V_1_0_0/Main/Dockerfile

@@ -0,0 +1,36 @@
+# 基础镜像
+FROM python:3.8
+
+# 作者,版本
+LABEL author="lm"  
+LABEL version="1.0.0"
+
+# 环境变量参数
+ENV TZ="Asia/Shanghai"
+ENV PYTHONPATH="/"
+
+# 安装用到的python 第三方库
+RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple \
+    sqlalchemy \
+    pandas==1.3.4 \
+    pymysql apscheduler \
+    scipy \
+    cryptography \
+    numpy==1.20.3 \
+    requests
+
+#RUN rm -r /usr/bin
+#RUN rm -r /bin
+
+# 配置算法路径
+ARG ALGO_PATH=LIB/MIDDLE/AlgoTest/Algo1/V_1_0_0/
+# 配置版本路径
+ARG ALGO_VERSION=V_1_0_0
+
+# 复制文件文件到 容器
+ADD LIB/BACKEND/ /LIB/BACKEND
+ADD ${ALGO_PATH}/ /${ALGO_PATH}/
+ADD ${ALGO_PATH}/main.py /main.py
+WORKDIR ${ALGO_PATH}/Main/
+
+CMD ["python", "main.py"]

+ 13 - 0
LIB/MIDDLE/AlgoTest/Algo1/V_1_0_0/Main/config-dev.ini

@@ -0,0 +1,13 @@
+[Mysql-1]
+host = localhost
+port = 3306
+db = test
+user = root
+password = Qx123456
+
+[Mysql-2]
+host = localhost
+port = 3306
+db = test
+user = root
+password = Qx123456

+ 0 - 0
LIB/MIDDLE/AlgoTest/Algo1/V_1_0_0/Main/config-pro.ini


+ 0 - 0
LIB/MIDDLE/AlgoTest/Algo1/V_1_0_0/Main/config-test.ini


+ 41 - 13
LIB/MIDDLE/AlgoTest/Algo1/main.py → LIB/MIDDLE/AlgoTest/Algo1/V_1_0_0/Main/main.py

@@ -4,29 +4,57 @@ import pandas as pd
 import time
 from sqlalchemy import create_engine
 import os
+import configparser
 import pymysql
 import traceback
 import datetime
-from LIB.BACKEND import DBManager,Log # 以相对路径的方式引入!!!!!
-from V_1_0_0 import core # 以相对路径的方式引入!!!!!
+from LIB.BACKEND import DBManager,Log # 以相对路径的方式从LIB开始引入!!!!!
+from LIB.MIDDLE.AlgoTest.Algo1.V_1_0_0.CoreAlgo import core # 以相对路径的方式从LIB开始引入!!!!!
 from LIB.BACKEND.OPENAPI import OpenApi
 
 if __name__ == '__main__':
     
     
-    # 环境变量配置(通过环境变量接收数据库等相关配置参数
+    # 环境变量配置(通过环境变量确定当前程序运行在开发、测试、生产环境
     env_dist = os.environ
-    host1 = env_dist.get("HOST1", '127.0.0.1')
-    port1 = int(env_dist.get("PORT1", '3306'))
-    db1 = env_dist.get("DB1", 'test')
-    user1 = env_dist.get("USER1", 'root')
-    password1 = env_dist.get("PASSWORD1", 'Qx123456')
+    cur_env = env_dist.get("CURENV", 'dev') # 默认为开发环境
     
-    host2 = env_dist.get("HOST2", '127.0.0.1')
-    port2 = int(env_dist.get("PORT2", '3306'))
-    db2 = env_dist.get("DB2", 'test')
-    user2 = env_dist.get("USER2", 'root')
-    password2 = env_dist.get("PASSWORD2", 'Qx123456')
+    # 读取配置文件
+    cf = configparser.ConfigParser()
+    if cur_env == 'dev':
+        cf.read("config-dev.ini")
+    elif cur_env == 'test':
+        cf.read("config-test.ini")
+    elif cur_env == 'pro':
+        cf.read("config-pro.ini")
+        
+    options = cf.options("Mysql-1")
+    items = cf.items("Mysql-1")
+    print(options)
+    print(items)
+    
+    host1 = cf.get("Mysql-1", 'host')
+    port1 = int(cf.get("Mysql-1", 'port'))
+    db1 = cf.get("Mysql-1", 'db')
+    user1 = cf.get("Mysql-1", 'user')
+    password1 = cf.get("Mysql-1", 'password')
+    
+    host2 = cf.get("Mysql-2", 'host')
+    port2 = int(cf.get("Mysql-2", 'port'))
+    db2 = cf.get("Mysql-2", 'db')
+    user2 = cf.get("Mysql-2", 'user')
+    password2 = cf.get("Mysql-2", 'password')
+    # host1 = env_dist.get("HOST1", '127.0.0.1')
+    # port1 = int(env_dist.get("PORT1", '3306'))
+    # db1 = env_dist.get("DB1", 'test')
+    # user1 = env_dist.get("USER1", 'root')
+    # password1 = env_dist.get("PASSWORD1", 'Qx123456')
+    
+    # host2 = env_dist.get("HOST2", '127.0.0.1')
+    # port2 = int(env_dist.get("PORT2", '3306'))
+    # db2 = env_dist.get("DB2", 'test')
+    # user2 = env_dist.get("USER2", 'root')
+    # password2 = env_dist.get("PASSWORD2", 'Qx123456')
     
     # 日志配置(按照该配置,每次运行时可自动生成运行日期的文件夹, 会在与main同级的)
     now_str = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()).replace(":","_")