diff --git a/.gitignore b/.gitignore index 4f5a7c0..e38d609 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ *.tar docker-compose.yml yz_project.csv +test \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 143557f..6c8a825 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM dockerproxy.com/library/ubuntu:22.04 ADD dotnet-runtime-3.1.32-linux-x64.tar.gz /root/dotnet COPY libssl1.0.0_1.0.2g-1ubuntu4.20_amd64.deb /tmp -RUN apt update;dpkg --add-architecture i386;apt update;apt install -y --no-install-recommends libstdc++6 lib32stdc++6 libc6:i386 libc6 libgcc-s1 libicu70 liblttng-ust1 zlib1g vim zip unzip wget openssh-server inetutils-ping inetutils-telnet jq wine wine32 smbclient;\ +RUN apt update;dpkg --add-architecture i386;apt update;apt install -y --no-install-recommends libstdc++6 lib32stdc++6 libc6:i386 libc6 libgcc-s1 libicu70 liblttng-ust1 zlib1g vim zip unzip wget openssh-server inetutils-ping inetutils-telnet jq wine wine32 xvfb smbclient;\ dpkg -i /tmp/libssl1.0.0_1.0.2g-1ubuntu4.20_amd64.deb;\ echo "PermitRootLogin yes\nPasswordAuthentication yes\n" >> /etc/ssh/sshd_config;\ echo root:123456 |chpasswd;\ @@ -12,7 +12,7 @@ RUN apt update;dpkg --add-architecture i386;apt update;apt install -y --no-insta COPY localtime /etc COPY nats-server /usr/bin/ COPY checksum /usr/bin/ -COPY yuzhen_iot /yuzhen_iot/ +COPY yuzhen_iot /yuzhen_iot_default/ COPY start.sh /home/ WORKDIR /home diff --git a/generate_files.py b/generate_files.py index 74a22a3..4f6e3aa 100644 --- a/generate_files.py +++ b/generate_files.py @@ -16,18 +16,16 @@ def generate_files(start_sn, count): csv_content = [] docker_services = [] - # docker-compose 头部定义 + # docker-compose 头部定义(移除了公共 volumes,改在下方服务中动态生成) docker_header = """version: '3' x-service-common: &service-common - image: swr.cn-north-4.myhuaweicloud.com/cloud-yuzhen/yuzhen_base:v1.0.11 + image: swr.cn-north-4.myhuaweicloud.com/cloud-yuzhen/yuzhen_base:v1.0.12 restart: always - volumes: - - ./yz_project.csv:/home/yz_project.csv services:""" print(f"正在生成 {count} 个序列号,起始于: {start_sn}...") - + server_ip = "192.168.1.244" # 替换为实际的服务器 IP for i in range(count): # 计算当前数字并补零至4位 (例如: 1 -> 0001) current_num = start_num + i @@ -37,23 +35,25 @@ services:""" # 格式: ${device_SN},Horseman-A21,H21.0.0.1,121.36.13.175,1883,mxpoty5rco1jhwde|${device_SN}|2,pykqg5qpzspfce3w,0,121.36.13.175,http://121.36.13.175/dlp/v1/device/backupAndRestore?sn=${device_SN},, csv_line = ( - f"{current_sn},Horseman-A21,H21.0.0.1,121.36.13.175,1885,mxpoty5rco1jhwde|{current_sn}|2,pykqg5qpzspfce3w,0,121.36.13.175" + f"{current_sn},Horseman-A21,H21.0.0.1,{server_ip},1883,mxpoty5rco1jhwde|{current_sn}|2,pykqg5qpzspfce3w,0,{server_ip},http://{server_ip}/dlp/v1/device/backupAndRestore?sn={current_sn}" ) csv_content.append(csv_line) # --- 生成 Docker Compose 服务块 --- - # 注意 YAML 缩进 + # 1. 保持原有的 csv 挂载 + # 2. 新增宿主机当前目录下以容器名(序列号)命名的文件夹,映射到容器内 /yuzhen_iot service_block = f""" {current_sn}: <<: *service-common - command: [ "/home/start.sh", "{current_sn}" ]""" + command: [ "/home/start.sh", "{current_sn}" ] + volumes: + - ./yz_project.csv:/home/yz_project.csv + - ./{current_sn}:/yuzhen_iot""" docker_services.append(service_block) # 2. 写入 CSV 文件 with open(csv_filename, 'w', encoding='utf-8') as f: f.write("\n".join(csv_content)) - # 如果文件末尾需要换行符,取消下面注释 - # f.write("\n") print(f"已创建: {csv_filename}") # 3. 写入 Docker Compose 文件 @@ -64,8 +64,8 @@ services:""" if __name__ == "__main__": # --- 配置区域 --- - START_SN = "YZXHRAX86NN2604030001" # 起始序列号 - COUNT = 2 # 需要生成的个数 + START_SN = "YZXHRAX86NN2511250001" # 起始序列号 + COUNT = 166 # 需要生成的个数 # ---------------- - generate_files(START_SN, COUNT) + generate_files(START_SN, COUNT) \ No newline at end of file diff --git a/start.sh b/start.sh index 8b77def..59fb852 100755 --- a/start.sh +++ b/start.sh @@ -1,4 +1,12 @@ #!/bin/sh + +# 如果映射目录里没有初始化标记文件,说明是初次启动 +if [ ! -f "/yuzhen_iot/.initialized" ]; then + echo "检测到初次启动,正在释放默认文件..." + cp -r /yuzhen_iot_default/. /yuzhen_iot/ + touch /yuzhen_iot/.initialized +fi + echo "start ssh" service ssh start