feat: 正式环境构建

This commit is contained in:
liulujian 2026-05-05 20:13:35 +08:00
parent 01e92a5be0
commit e016eb7e11
15 changed files with 205 additions and 39 deletions

View File

@ -1,10 +1,16 @@
# ============================================================ # ============================================================
# 碳信网 - 统一后端构建镜像 # 碳信网 - 统一后端构建镜像
# 支持多平台构建: docker buildx build --platform linux/arm64,linux/amd64
# 使用方式: docker run -e SERVICE_NAME=gateway txw-all:latest # 使用方式: docker run -e SERVICE_NAME=gateway txw-all:latest
# ============================================================ # ============================================================
# Stage 1: Build # Stage 1: Build
FROM maven:3.6.3-openjdk-8 AS builder # 使用多架构 Maven 镜像,自动选择对应平台版本
FROM --platform=$BUILDPLATFORM maven:3.6.3-openjdk-8 AS builder
# Maven 构建参数
ARG TARGETARCH
ARG BUILDARCH
WORKDIR /build WORKDIR /build
@ -47,6 +53,8 @@ COPY txw-yygl/txw-yygl-service-biz/src yygl/txw-yygl-service-biz/src
# ------------------------------------------- # -------------------------------------------
# Step 2: 复制 Maven 本地仓库(离线构建) # Step 2: 复制 Maven 本地仓库(离线构建)
# 注意:若本地仓库中有编译好的二进制 native 库(非 Java byte code
# 需要确保这些库是跨平台的,或在 ARM64 上重新构建
# ------------------------------------------- # -------------------------------------------
COPY script/.m2/repository /root/.m2/repository COPY script/.m2/repository /root/.m2/repository
@ -83,17 +91,23 @@ WORKDIR /build/gateway
RUN mvn clean package -DskipTests -s settings.xml -o || mvn clean package -DskipTests RUN mvn clean package -DskipTests -s settings.xml -o || mvn clean package -DskipTests
# Stage 2: Package # Stage 2: Package
FROM eclipse-temurin:8-jre # 使用多架构 JRE 镜像,指定目标平台
FROM --platform=$TARGETARCH eclipse-temurin:8-jre
WORKDIR /app WORKDIR /app
# 安装字体(用于验证码 Captcha # 安装字体(用于验证码 Captcha
RUN apt-get update && apt-get install -y \ # 使用中科大镜像加速
fonts-noto-cjk \ RUN echo 'deb http://mirrors.ustc.edu.cn/ubuntu-ports/ noble main restricted universe multiverse' > /etc/apt/sources.list && \
echo 'deb http://mirrors.ustc.edu.cn/ubuntu-ports/ noble-updates main restricted universe multiverse' >> /etc/apt/sources.list && \
echo 'deb http://mirrors.ustc.edu.cn/ubuntu-ports/ noble-backports main restricted universe multiverse' >> /etc/apt/sources.list && \
apt-get update && apt-get install -y --no-install-recommends \
fontconfig \ fontconfig \
fonts-noto-cjk \
&& fc-cache -f -v \ && fc-cache -f -v \
&& apt-get clean -y \ && apt-get clean -y \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
COPY devops/start.sh /app/start.sh COPY devops/start.sh /app/start.sh
RUN chmod +x /app/start.sh RUN chmod +x /app/start.sh

View File

@ -43,13 +43,26 @@ bash build.sh 1.0.0-BETA
docker build -t txw-all:1.0.0-BETA -t txw-all:latest -f devops/Dockerfile . docker build -t txw-all:1.0.0-BETA -t txw-all:latest -f devops/Dockerfile .
``` ```
仅构建前端 仅构建前端
``` ```
docker build -t txw-web:1.0.0-BETA -t txw-web:latest -f devops/web/Dockerfile . docker build -t txw-web:1.0.0-BETA -t txw-web:latest -f devops/web/Dockerfile .
``` ```
构建arm64架构
构建前端
```bash
docker buildx build --platform linux/arm64 -t txw-web:1.0.0 -f devops/web/Dockerfile . --load
```
构建后端
```bash
docker buildx build --platform linux/arm64 -t txw-all:1.0.0 -f devops/Dockerfile . --load
```
### 更新镜像 ### 更新镜像
代码变更后,重新构建并启动: 代码变更后,重新构建并启动:

View File

@ -0,0 +1,107 @@
version: '3.8'
# ============================================================
# 碳信网 - 基础设施服务
# 使用方式:
# 启动基础设施: docker-compose up -d
# ============================================================
services:
nacos:
image: nacos/nacos-server:v3.0.2
container_name: txw-nacos
expose:
- "8848"
- "9848"
- "9849"
environment:
- MODE=standalone
- PREFER_HOST_MODE=hostname
- JVM_XMS=512m
- JVM_XMX=512m
- JVM_XMN=256m
- NACOS_AUTH_ENABLE=true
- NACOS_AUTH_IDENTITY_KEY=1qazXSW@3edcVFR$
- NACOS_AUTH_IDENTITY_VALUE=7ygvBHU*9ijnMKO)
- NACOS_AUTH_TOKEN=TmFjb3NBdXRoVG9rZW5TZWNyZXRLZXkyMDI0Rm9yRGV2RW52aXJvbm1lbnQ=
- NACOS_CORE_AUTH_SERVER_IDENTITY_KEY=nacos
- NACOS_CORE_AUTH_SERVER_IDENTITY_VALUE=nacos2024
volumes:
- ./nacos/data:/home/nacos/data
- ./nacos/logs:/home/nacos/logs
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8848/nacos"]
interval: 30s
timeout: 10s
retries: 5
networks:
- txw-network
redis:
image: redis:latest
container_name: txw-redis
expose:
- "6379"
command: redis-server --ignore-warnings ARM64-COW-BUG --requirepass redis_password
volumes:
- redis-data:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 30s
timeout: 10s
retries: 5
networks:
- txw-network
minio:
image: minio/minio:latest
container_name: txw-minio
expose:
- "9000"
- "9001"
environment:
- MINIO_ROOT_USER=minioadmin
- MINIO_ROOT_PASSWORD=minioadmin123
command: server /data --console-address ":9001"
volumes:
- ./minio-data:/data
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
interval: 30s
timeout: 10s
retries: 5
networks:
- txw-network
mysql:
image: biarms/mysql:5.7
container_name: txw-mysql
expose:
- "3306"
environment:
- MYSQL_ROOT_PASSWORD=MysqlRootPwd@2024#Secure
- MYSQL_DATABASE=txw_db
volumes:
- ./mysql-data:/var/lib/mysql
- ./mysql-init:/docker-entrypoint-initdb.d
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-pMysqlRootPwd@2024#Secure"]
interval: 30s
timeout: 10s
retries: 5
networks:
- txw-network
networks:
txw-network:
name: txw-network
driver: bridge
external: true
volumes:
nacos-data:
redis-data:
minio-data:
mysql-data:

View File

@ -9,7 +9,7 @@ version: '3.8'
services: services:
nacos: nacos:
image: nacos/nacos-server:v2.3.2 image: nacos/nacos-server:v3.0.2
container_name: txw-nacos container_name: txw-nacos
ports: ports:
- "8848:8848" - "8848:8848"

View File

@ -17,7 +17,7 @@ services:
- SPRING_PROFILES_ACTIVE=prod - SPRING_PROFILES_ACTIVE=prod
- NACOS_SERVER_ADDR=nacos:8848 - NACOS_SERVER_ADDR=nacos:8848
ports: ports:
- "9300:9300" - ":9300"
networks: networks:
- txw-network - txw-network
@ -32,7 +32,7 @@ services:
- SPRING_REDIS_PORT=6379 - SPRING_REDIS_PORT=6379
- SPRING_REDIS_PASSWORD=redis_password - SPRING_REDIS_PASSWORD=redis_password
ports: ports:
- "9301:9301" - ":9301"
networks: networks:
- txw-network - txw-network
@ -47,7 +47,7 @@ services:
- SPRING_REDIS_PORT=6379 - SPRING_REDIS_PORT=6379
- SPRING_REDIS_PASSWORD=redis_password - SPRING_REDIS_PASSWORD=redis_password
ports: ports:
- "9302:9302" - ":9302"
networks: networks:
- txw-network - txw-network
@ -62,7 +62,7 @@ services:
- SPRING_REDIS_PORT=6379 - SPRING_REDIS_PORT=6379
- SPRING_REDIS_PASSWORD=redis_password - SPRING_REDIS_PASSWORD=redis_password
ports: ports:
- "20010:20010" - ":20010"
networks: networks:
- txw-network - txw-network

View File

@ -10,14 +10,16 @@ version: '3.8'
services: services:
web: web:
image: txw-web:1.0.0-BETA image: txw-web:1.0.0
container_name: txw-web container_name: txw-web
environment: environment:
- SERVICE_NAME=gateway - SERVICE_NAME=gateway
- SPRING_PROFILES_ACTIVE=test - SPRING_PROFILES_ACTIVE=test
- NACOS_SERVER_ADDR=nacos:8848 - NACOS_SERVER_ADDR=txw-nacos:8848
ports: ports:
- "30090:80" - "30090:80"
volumes:
- ./web/nginx.conf:/etc/nginx/nginx.conf
deploy: deploy:
replicas: 1 replicas: 1
resources: resources:

View File

@ -14,7 +14,7 @@ services:
# ============================================ # ============================================
nacos: nacos:
image: nacos/nacos-server:v2.3.2 # Nacos 官方镜像指定稳定版本避免latest image: nacos/nacos-server:v3.0.2 # Nacos 官方镜像指定稳定版本避免latest
container_name: txw-nacos # 容器名称,方便管理 container_name: txw-nacos # 容器名称,方便管理
ports: ports:
- "8848:8848" # Nacos 核心端口Web控制台+API - "8848:8848" # Nacos 核心端口Web控制台+API

View File

@ -0,0 +1,4 @@
-- 创建 txw 用户并授权
CREATE USER IF NOT EXISTS 'txw'@'%' IDENTIFIED BY 'txwKXTXXW123@!';
GRANT ALL PRIVILEGES ON txw_db.* TO 'txw'@'%';
FLUSH PRIVILEGES;

View File

@ -5,7 +5,7 @@ set -e
# 碳信网 - 镜像打包脚本 # 碳信网 - 镜像打包脚本
# 用法: bash devops/pack-image.sh <txw-web|txw-all> [VERSION] [SERVER_USER] [SERVER_HOST] # 用法: bash devops/pack-image.sh <txw-web|txw-all> [VERSION] [SERVER_USER] [SERVER_HOST]
# 示例: # 示例:
# bash devops/pack-image.sh txw-web 1.0.0 root 192.168.1.100 # bash ./devops/pack-image.sh txw-web 1.0.0 root 192.168.1.100
# bash devops/pack-image.sh txw-all # bash devops/pack-image.sh txw-all
# ============================================================ # ============================================================

View File

@ -81,6 +81,11 @@ http {
proxy_pass http://txw-gateway:9300; proxy_pass http://txw-gateway:9300;
} }
# Nacos 代理
location ~ ^/nacos(/.*)?$ {
proxy_pass http://txw-nacos:8848$1;
}
# 百度验证 # 百度验证
location = /baidu_verify_codeva-5rH3psCeMQ.html { location = /baidu_verify_codeva-5rH3psCeMQ.html {
alias /etc/nginx/verify/baidu_verify_codeva-5rH3psCeMQ.html; alias /etc/nginx/verify/baidu_verify_codeva-5rH3psCeMQ.html;

View File

@ -4,10 +4,10 @@ spring:
cloud: cloud:
nacos: nacos:
server-addr: txw-nacos:8848 server-addr: txw-nacos:8848
username: qyddev username: nacos
password: "9!1%Sw#QydNacosDev" password: "nacos2024"
discovery: discovery:
namespace: bcf8de57-7215-4934-aced-ab382d504aff # 命名空间。这里使用本地开发环境 namespace: 79f610cd-f637-4c0c-9faa-fd0ca688aa02 # 命名空间。这里使用本地开发环境
metadata: metadata:
version: 1.0.0-SNAPSHOT # 服务实例的版本号,可用于灰度发布 version: 1.0.0-SNAPSHOT # 服务实例的版本号,可用于灰度发布
@ -19,9 +19,9 @@ spring:
# Nacos Config 配置项,对应 NacosConfigProperties 配置属性类 # Nacos Config 配置项,对应 NacosConfigProperties 配置属性类
config: config:
server-addr: txw-nacos:8848 # Nacos 服务器地址(本地开发环境) server-addr: txw-nacos:8848 # Nacos 服务器地址(本地开发环境)
username: qyddev username: nacos
password: "9!1%Sw#QydNacosDev" password: "nacos2024"
namespace: bcf8de57-7215-4934-aced-ab382d504aff # 命名空间。这里使用本地开发环境 namespace: 79f610cd-f637-4c0c-9faa-fd0ca688aa02 # 命名空间。这里使用本地开发环境
group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
name: ${spring.application.name} # 使用的 Nacos 配置集的 dataId默认为 spring.application.name name: ${spring.application.name} # 使用的 Nacos 配置集的 dataId默认为 spring.application.name
file-extension: yaml # 使用的 Nacos 配置集的 dataId 的文件拓展名,同时也是 Nacos 配置集的配置格式,默认为 properties file-extension: yaml # 使用的 Nacos 配置集的 dataId 的文件拓展名,同时也是 Nacos 配置集的配置格式,默认为 properties

View File

@ -128,6 +128,7 @@ export default {
name: 'tzzx', name: 'tzzx',
title: '碳证中心', title: '碳证中心',
iframeUrl: 'https://ctn-web-pre.lingshu.net/carbon-index', iframeUrl: 'https://ctn-web-pre.lingshu.net/carbon-index',
path:'/carbon-index',
needLogin: true, needLogin: true,
clientId: 'client_id_tfwzx',//txw_sso_client clientId: 'client_id_tfwzx',//txw_sso_client
child: [ child: [
@ -140,6 +141,7 @@ export default {
needLogin: true, //访 needLogin: true, //访
clientId: 'client_id_tfwzx', clientId: 'client_id_tfwzx',
iframeUrl: 'https://ctn-web-pre.lingshu.net/trustedCarbonQuery/index', // iframeUrl: 'https://ctn-web-pre.lingshu.net/trustedCarbonQuery/index', //
path: '/trustedCarbonQuery/index',
// iframeUrl: 'https://ctn-web-pre.lingshu.net/trustedCarbonQuery/list?type=carbon-query', // // iframeUrl: 'https://ctn-web-pre.lingshu.net/trustedCarbonQuery/list?type=carbon-query', //
}, },
{ {
@ -151,6 +153,7 @@ export default {
needLogin: true, needLogin: true,
clientId: 'client_id_tfwzx', clientId: 'client_id_tfwzx',
iframeUrl: 'https://ctn-web-pre.lingshu.net/carbon-protection', iframeUrl: 'https://ctn-web-pre.lingshu.net/carbon-protection',
path: '/carbon-protection'
}, },
{ {
name: 'tzhy', name: 'tzhy',
@ -161,6 +164,7 @@ export default {
needLogin: true, needLogin: true,
clientId: 'client_id_tfwzx', clientId: 'client_id_tfwzx',
iframeUrl: 'https://ctn-web-pre.lingshu.net/carbon-verify', iframeUrl: 'https://ctn-web-pre.lingshu.net/carbon-verify',
path: '/carbon-verify'
}, },
{ {
name: 'tgbcz', name: 'tgbcz',
@ -171,6 +175,7 @@ export default {
needLogin: true, needLogin: true,
clientId: 'client_id_tfwzx', clientId: 'client_id_tfwzx',
iframeUrl: 'https://ctn-web-pre.lingshu.net/carbon-report-cert', iframeUrl: 'https://ctn-web-pre.lingshu.net/carbon-report-cert',
path: '/carbon-report-cert'
}, },
{ {
name: 'tbgtg', name: 'tbgtg',
@ -181,6 +186,7 @@ export default {
needLogin: true, needLogin: true,
clientId: 'client_id_tfwzx', clientId: 'client_id_tfwzx',
iframeUrl: 'https://ctn-web-pre.lingshu.net/carbon-report-hosting', iframeUrl: 'https://ctn-web-pre.lingshu.net/carbon-report-hosting',
path: '/carbon-report-hosting'
} }
] ]
}, },
@ -246,7 +252,7 @@ export default {
}, },
created() { created() {
// this.gettfwzxurl(); this.gettfwzxurl();
}, },
mounted() { mounted() {
// this.gettfwzxurl(); // this.gettfwzxurl();
@ -387,11 +393,26 @@ export default {
// const res = await getMxjbxx(prame); // const res = await getMxjbxx(prame);
const { data } = await api.tfwzxurl(); const { data } = await api.tfwzxurl();
this.kxurl = data.kxtfwzx; this.kxurl = data.kxtfwzx;
// menuOptions iframe iframeUrl
this.updateIframeUrl(this.menuOptions);
console.log('res', data); console.log('res', data);
} catch (error) { } catch (error) {
console.error('数据加载失败', error); console.error('数据加载失败', error);
} }
}, },
updateIframeUrl(menus) {
if (!menus || !this.kxurl) return;
menus.forEach(menu => {
if (menu.path) {
menu.iframeUrl = `${this.kxurl}${menu.path}`;
}
if (menu.child && menu.child.length > 0) {
this.updateIframeUrl(menu.child);
}
});
},
gologin() { gologin() {
this.closeMobileMenu(); this.closeMobileMenu();
this.$router.push("/login") this.$router.push("/login")

View File

@ -4,10 +4,10 @@ spring:
cloud: cloud:
nacos: nacos:
server-addr: txw-nacos:8848 server-addr: txw-nacos:8848
username: qyddev username: nacos
password: "9!1%Sw#QydNacosDev" password: "nacos2024"
discovery: discovery:
namespace: bcf8de57-7215-4934-aced-ab382d504aff # 命名空间。这里使用本地开发环境 namespace: 79f610cd-f637-4c0c-9faa-fd0ca688aa02 # 命名空间。这里使用本地开发环境
--- #################### 配置中心相关配置 #################### --- #################### 配置中心相关配置 ####################
@ -17,9 +17,9 @@ spring:
# Nacos Config 配置项,对应 NacosConfigProperties 配置属性类 # Nacos Config 配置项,对应 NacosConfigProperties 配置属性类
config: config:
server-addr: txw-nacos:8848 # Nacos 服务器地址(本地开发环境) server-addr: txw-nacos:8848 # Nacos 服务器地址(本地开发环境)
username: qyddev username: nacos
password: "9!1%Sw#QydNacosDev" password: "nacos2024"
namespace: bcf8de57-7215-4934-aced-ab382d504aff # 命名空间。这里使用本地开发环境 namespace: 79f610cd-f637-4c0c-9faa-fd0ca688aa02 # 命名空间。这里使用本地开发环境
group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
name: ${spring.application.name} # 使用的 Nacos 配置集的 dataId默认为 spring.application.name name: ${spring.application.name} # 使用的 Nacos 配置集的 dataId默认为 spring.application.name
file-extension: yaml # 使用的 Nacos 配置集的 dataId 的文件拓展名,同时也是 Nacos 配置集的配置格式,默认为 properties file-extension: yaml # 使用的 Nacos 配置集的 dataId 的文件拓展名,同时也是 Nacos 配置集的配置格式,默认为 properties

View File

@ -4,10 +4,10 @@ spring:
cloud: cloud:
nacos: nacos:
server-addr: txw-nacos:8848 server-addr: txw-nacos:8848
username: qyddev username: nacos
password: "9!1%Sw#QydNacosDev" password: "nacos2024"
discovery: discovery:
namespace: bcf8de57-7215-4934-aced-ab382d504aff # 命名空间。这里使用本地开发环境 namespace: 79f610cd-f637-4c0c-9faa-fd0ca688aa02 # 命名空间。这里使用本地开发环境
metadata: metadata:
version: 1.0.0-SNAPSHOT # 服务实例的版本号,可用于灰度发布 version: 1.0.0-SNAPSHOT # 服务实例的版本号,可用于灰度发布
@ -19,9 +19,9 @@ spring:
# Nacos Config 配置项,对应 NacosConfigProperties 配置属性类 # Nacos Config 配置项,对应 NacosConfigProperties 配置属性类
config: config:
server-addr: txw-nacos:8848 # Nacos 服务器地址(本地开发环境) server-addr: txw-nacos:8848 # Nacos 服务器地址(本地开发环境)
username: qyddev username: nacos
password: "9!1%Sw#QydNacosDev" password: "nacos2024"
namespace: bcf8de57-7215-4934-aced-ab382d504aff # 命名空间。这里使用本地开发环境 namespace: 79f610cd-f637-4c0c-9faa-fd0ca688aa02 # 命名空间。这里使用本地开发环境
group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
name: ${spring.application.name} # 使用的 Nacos 配置集的 dataId默认为 spring.application.name name: ${spring.application.name} # 使用的 Nacos 配置集的 dataId默认为 spring.application.name
file-extension: yaml # 使用的 Nacos 配置集的 dataId 的文件拓展名,同时也是 Nacos 配置集的配置格式,默认为 properties file-extension: yaml # 使用的 Nacos 配置集的 dataId 的文件拓展名,同时也是 Nacos 配置集的配置格式,默认为 properties

View File

@ -4,10 +4,10 @@ spring:
cloud: cloud:
nacos: nacos:
server-addr: txw-nacos:8848 server-addr: txw-nacos:8848
username: qyddev username: nacos
password: 9!1%Sw#QydNacosDev password: "nacos2024"
discovery: discovery:
namespace: bcf8de57-7215-4934-aced-ab382d504aff # 命名空间。这里使用本地开发环境 namespace: 79f610cd-f637-4c0c-9faa-fd0ca688aa02 # 命名空间。这里使用本地开发环境
metadata: metadata:
version: 1.0.0-SNAPSHOT # 服务实例的版本号,可用于灰度发布 version: 1.0.0-SNAPSHOT # 服务实例的版本号,可用于灰度发布
@ -19,9 +19,9 @@ spring:
# Nacos Config 配置项,对应 NacosConfigProperties 配置属性类 # Nacos Config 配置项,对应 NacosConfigProperties 配置属性类
config: config:
server-addr: txw-nacos:8848 # Nacos 服务器地址(本地开发环境) server-addr: txw-nacos:8848 # Nacos 服务器地址(本地开发环境)
username: qyddev username: nacos
password: 9!1%Sw#QydNacosDev password: "nacos2024"
namespace: bcf8de57-7215-4934-aced-ab382d504aff # 命名空间。这里使用本地开发环境 namespace: 79f610cd-f637-4c0c-9faa-fd0ca688aa02 # 命名空间。这里使用本地开发环境
group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
name: ${spring.application.name} # 使用的 Nacos 配置集的 dataId默认为 spring.application.name name: ${spring.application.name} # 使用的 Nacos 配置集的 dataId默认为 spring.application.name
file-extension: yaml # 使用的 Nacos 配置集的 dataId 的文件拓展名,同时也是 Nacos 配置集的配置格式,默认为 properties file-extension: yaml # 使用的 Nacos 配置集的 dataId 的文件拓展名,同时也是 Nacos 配置集的配置格式,默认为 properties