David 1 month ago
parent
commit
898c89d6b0

+ 64 - 3
Dockerfile

@@ -1,4 +1,65 @@
-FROM ubuntu:latest
-LABEL authors="Administrator"
+# ===================== 第一阶段:构建 Python 3.12 环境 =====================
+FROM centos:xnyV1.3 AS python-builder
 
-ENTRYPOINT ["top", "-b"]
+# 配置阿里云 yum 源(确保容器内 yum 可用)
+RUN curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo && \
+    sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo && \
+    yum clean all && yum makecache
+
+# 安装 Python 编译依赖
+RUN yum install -y \
+    gcc make openssl-devel bzip2-devel libffi-devel zlib-devel \
+    sqlite-devel readline-devel xz-devel tk-devel libnsl-devel \
+    libtirpc-devel wget
+
+# 下载并编译 Python 3.12(直接使用官方源,避免校验失败)
+RUN cd /tmp && \
+    wget https://mirrors.huaweicloud.com/python/3.12.0/Python-3.12.0.tgz && \
+    echo "51412956d86a61d1a7d227873d2b3697e1fccc16d7b3b5e2b6a8cd372d74edb9 Python-3.12.0.tgz" | sha256sum -c - && \
+    tar xzf Python-3.12.0.tgz && \
+    cd Python-3.12.0 && \
+    ./configure \
+        --enable-optimizations \
+        --with-lto=no \
+        --enable-shared \
+        --with-system-expat \
+        --with-system-ffi \
+        --with-ensurepip=yes \
+        --enable-ipv6 && \
+    make -j$(($(nproc)-1)) altinstall && \
+    ldconfig && \
+    ln -sf /usr/local/bin/python3.12 /usr/local/bin/python3 && \
+    ln -sf /usr/local/bin/pip3.12 /usr/local/bin/pip3
+
+# ===================== 第二阶段:构建最终应用镜像 =====================
+FROM centos:xnyV1.3
+
+# 1. 从 Python 构建阶段复制环境
+COPY --from=python-builder /usr/local/ /usr/local/
+
+# 2. 修复共享库链接
+RUN ldconfig && \
+    ln -sf /usr/local/bin/python3.12 /usr/local/bin/python3 && \
+    ln -sf /usr/local/bin/pip3.12 /usr/local/bin/pip3
+
+# 3. 安装 MongoDB
+RUN echo -e "[mongodb-org-6.0]\n\
+name=MongoDB Repository\n\
+baseurl=https://repo.mongodb.org/yum/redhat/7/mongodb-org/6.0/x86_64/\n\
+gpgcheck=1\n\
+enabled=1\n\
+gpgkey=https://www.mongodb.org/static/pgp/server-6.0.asc" \
+    > /etc/yum.repos.d/mongodb-org-6.0.repo && \
+    yum install -y mongodb-org && \
+    mkdir -p /data/db && chown mongod:mongod /data/db
+
+# 4. 设置工作目录并复制应用代码
+WORKDIR /app
+COPY ./app/ .
+
+# 5. 安装 Python 依赖
+COPY app/requirements.txt .
+RUN pip3 install --no-cache-dir -r requirements.txt
+
+# 6. 启动脚本(同时启动 MongoDB 和 Python 应用)
+CMD ["sh", "-c", "mongod --fork --logpath /var/log/mongodb.log"]

+ 1 - 24
Dockerfile2

@@ -1,28 +1,5 @@
 # 基础镜像
-FROM centos:xnyV1.3
-
-# 配置阿里云yum源
-RUN curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo && \
-    sed -i \
-        -e '/mirrors.cloud.aliyuncs.com/d' \
-        -e '/mirrors.aliyuncs.com/d' \
-        /etc/yum.repos.d/CentOS-Base.repo && \
-    yum clean all && \
-    yum makecache
-
-# 使用官方 Python 镜像作为基础镜像
-FROM 192.168.1.36:5000/python:3.12
-
-# 安装MongoDB
-RUN echo -e "[mongodb-org-6.0]\n\
-name=MongoDB Repository\n\
-baseurl=https://repo.mongodb.org/yum/redhat/7/mongodb-org/6.0/x86_64/\n\
-gpgcheck=1\n\
-enabled=1\n\
-gpgkey=https://www.mongodb.org/static/pgp/server-6.0.asc" \
-> /etc/yum.repos.d/mongodb-org-6.0.repo && \
-    yum -y install mongodb-org && \
-    install -d -o mongod -g mongod -m 755 /data/db
+FROM centos:syjyV1.0
 
 # 设置工作目录
 WORKDIR /home/app

+ 0 - 0
app/logs/2025-03-26/south-forecast.2025-03-26.0.log


+ 0 - 0
app/logs/2025-03-27/south-forecast.2025-03-27.0.log


+ 2 - 2
app/model/main.py

@@ -42,14 +42,14 @@ def material(input_file, isDq=True):
         if args['switch_nwp_owner']:
             nwp_v, nwp_v_h = nwp_own, nwp_own_h
         # 如果是风电
-        if plant_type < 2:
+        if plant_type == 0:
             station_info = pd.read_csv(input_file / station_info_w, sep='\s+', header=0)
             station_info_d = pd.read_csv(input_file / station_info_d_w, sep='\s+', header=0)
             nwp = pd.read_csv(input_file / nwp_w, sep='\s+', header=0)
             nwp_h = pd.read_csv(input_file / nwp_w_h, sep='\s+', header=0)
             return station_info, station_info_d, nwp, nwp_h, power, nwp_v, nwp_v_h
         # 如果是光伏
-        elif plant_type == 2:
+        elif plant_type == 1:
             station_info = pd.read_csv(input_file / station_info_s, sep='\s+', header=0)
             station_info_d = pd.read_csv(input_file / station_info_d_s, sep='\s+', header=0)
             nwp = pd.read_csv(input_file / nwp_s, sep='\s+', header=0)

+ 0 - 1
app/requirements.txt

@@ -2,7 +2,6 @@ pymongo==4.7.3
 pandas==2.2.3
 SQLAlchemy==2.0.39
 PyMySQL==1.1.1
-Flask==3.0.2
 waitress==2.1.2
 requests==2.31.0
 numpy== 1.26.0