diff --git a/.gitignore b/.gitignore index dd775881e..e041fa529 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ data/ .env .env.* !.env.example +!.env.*.example application-local.yml bootstrap-local.yml *.hprof diff --git a/Jenkinsfile b/Jenkinsfile index 3520312a9..a2454fb6b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -73,6 +73,8 @@ pipeline { environment { REGISTRY_CREDENTIALS = 'gitlab-registry-credentials' + MAVEN_SETTINGS = 'deploy/maven/settings-cn.xml' + MAVEN_OPTS = '-Dfile.encoding=UTF-8 -Dmaven.wagon.http.retryHandler.count=3' } stages { @@ -128,7 +130,7 @@ pipeline { steps { script { String testOption = params.SKIP_TESTS ? '-DskipTests' : '' - sh "mvn --batch-mode --errors --fail-at-end -pl ${env.SELECTED_SERVICES} -am clean package ${testOption}" + sh "mvn --settings ${env.MAVEN_SETTINGS} --batch-mode --errors --fail-at-end -pl ${env.SELECTED_SERVICES} -am clean package ${testOption}" } } post { diff --git a/deploy/docker-compose.yml b/deploy/docker-compose.yml index e11104038..2082db646 100644 --- a/deploy/docker-compose.yml +++ b/deploy/docker-compose.yml @@ -2,7 +2,7 @@ name: firstleg-${DEPLOY_ENV:-test} x-common: &common restart: unless-stopped - networks: [firstleg-network] + networks: [firstleg-network, infra-network] environment: &common-environment SPRING_PROFILES_ACTIVE: ${SPRING_PROFILES_ACTIVE:-cn} NACOS_SERVER_ADDR: ${NACOS_SERVER_ADDR} @@ -30,7 +30,7 @@ services: gateway: <<: *common image: ${IMAGE_REPOSITORY}/gateway:${IMAGE_TAG} - container_name: firstleg-gateway + container_name: firstleg-${DEPLOY_ENV:-test}-gateway ports: ["${GATEWAY_PORT:-9000}:9000"] environment: <<: *common-environment @@ -42,7 +42,7 @@ services: auth: <<: *common image: ${IMAGE_REPOSITORY}/auth:${IMAGE_TAG} - container_name: firstleg-auth + container_name: firstleg-${DEPLOY_ENV:-test}-auth ports: ["${AUTH_PORT:-9100}:9100"] environment: <<: *common-environment @@ -54,7 +54,7 @@ services: iam: <<: *common image: ${IMAGE_REPOSITORY}/iam:${IMAGE_TAG} - container_name: firstleg-iam + container_name: firstleg-${DEPLOY_ENV:-test}-iam ports: ["${IAM_PORT:-9201}:9201"] environment: <<: *common-environment @@ -66,7 +66,7 @@ services: firstleg: <<: *common image: ${IMAGE_REPOSITORY}/firstleg:${IMAGE_TAG} - container_name: firstleg-business + container_name: firstleg-${DEPLOY_ENV:-test}-business ports: ["${FIRSTLEG_PORT:-9202}:9202"] environment: <<: *common-environment @@ -78,7 +78,7 @@ services: order: <<: *common image: ${IMAGE_REPOSITORY}/order:${IMAGE_TAG} - container_name: firstleg-order + container_name: firstleg-${DEPLOY_ENV:-test}-order ports: ["${ORDER_PORT:-9204}:9204"] environment: <<: *common-environment @@ -90,7 +90,7 @@ services: warehouse: <<: *common image: ${IMAGE_REPOSITORY}/warehouse:${IMAGE_TAG} - container_name: firstleg-warehouse + container_name: firstleg-${DEPLOY_ENV:-test}-warehouse ports: ["${WAREHOUSE_PORT:-9205}:9205"] environment: <<: *common-environment @@ -102,7 +102,7 @@ services: file: <<: *common image: ${IMAGE_REPOSITORY}/file:${IMAGE_TAG} - container_name: firstleg-file + container_name: firstleg-${DEPLOY_ENV:-test}-file ports: ["${FILE_PORT:-9206}:9206"] volumes: ["firstleg-file-data:/data/files"] environment: @@ -116,7 +116,7 @@ services: print: <<: *common image: ${IMAGE_REPOSITORY}/print:${IMAGE_TAG} - container_name: firstleg-print + container_name: firstleg-${DEPLOY_ENV:-test}-print ports: ["${PRINT_PORT:-9207}:9207"] environment: <<: *common-environment @@ -128,7 +128,7 @@ services: integration-service: <<: *common image: ${IMAGE_REPOSITORY}/integration-service:${IMAGE_TAG} - container_name: firstleg-integration + container_name: firstleg-${DEPLOY_ENV:-test}-integration ports: ["${INTEGRATION_PORT:-9210}:9210"] environment: <<: *common-environment @@ -147,7 +147,7 @@ services: event-bridge-service: <<: *common image: ${IMAGE_REPOSITORY}/event-bridge-service:${IMAGE_TAG} - container_name: firstleg-event-bridge + container_name: firstleg-${DEPLOY_ENV:-test}-event-bridge ports: ["${EVENT_BRIDGE_PORT:-9300}:9300"] environment: <<: *common-environment @@ -159,7 +159,7 @@ services: audit-service: <<: *common image: ${IMAGE_REPOSITORY}/audit-service:${IMAGE_TAG} - container_name: firstleg-audit + container_name: firstleg-${DEPLOY_ENV:-test}-audit ports: ["${AUDIT_PORT:-9700}:9700"] environment: <<: *common-environment @@ -171,6 +171,9 @@ services: networks: firstleg-network: name: firstleg-${DEPLOY_ENV:-test}-network + infra-network: + external: true + name: ${INFRA_NETWORK:-firstleg-test-infra-network} volumes: firstleg-file-data: diff --git a/deploy/scripts/deploy-services.sh b/deploy/scripts/deploy-services.sh index 465be68c3..37a41301e 100644 --- a/deploy/scripts/deploy-services.sh +++ b/deploy/scripts/deploy-services.sh @@ -18,10 +18,6 @@ if [ ! -f "$ENV_FILE" ]; then fi SERVICES=$(printf '%s' "$SERVICE_CSV" | tr ',' ' ') -case " $SERVICES " in - *" gateway "*) SERVICES="$SERVICES" ;; - *) SERVICES="$SERVICES gateway" ;; -esac export DEPLOY_ENV IMAGE_REPOSITORY IMAGE_TAG docker compose \ diff --git a/docker-compose-infra.yml b/docker-compose-infra.yml index b8cfe398c..bc83b8b6e 100644 --- a/docker-compose-infra.yml +++ b/docker-compose-infra.yml @@ -1,9 +1,9 @@ -name: baiyue-infra +name: firstleg-test-infra services: nacos: - image: nacos/nacos-server:v2.3.2 - container_name: baiyue-nacos + image: docker.m.daocloud.io/nacos/nacos-server:v2.3.2 + container_name: firstleg-test-nacos environment: MODE: standalone PREFER_HOST_MODE: hostname @@ -25,21 +25,20 @@ services: networks: [baiyue] mysql: - image: mysql:8.0.39 - container_name: baiyue-mysql - profiles: [database] + image: docker.m.daocloud.io/library/mysql:8.0.39 + container_name: firstleg-test-mysql environment: TZ: Asia/Shanghai - MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-change-me-before-use} + MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:?请在.env中设置MYSQL_ROOT_PASSWORD} MYSQL_DATABASE: ${MYSQL_DATABASE:-baiyue} MYSQL_USER: ${MYSQL_USER:-baiyue} - MYSQL_PASSWORD: ${MYSQL_PASSWORD:-change-me-before-use} + MYSQL_PASSWORD: ${MYSQL_PASSWORD:?请在.env中设置MYSQL_PASSWORD} command: - --character-set-server=utf8mb4 - --collation-server=utf8mb4_0900_ai_ci - --default-time-zone=+08:00 ports: ["3306:3306"] - volumes: [baiyue-mysql-data:/var/lib/mysql] + volumes: [firstleg-test-mysql-data:/var/lib/mysql] healthcheck: test: ["CMD-SHELL", "mysqladmin ping -h 127.0.0.1 -u root -p$$MYSQL_ROOT_PASSWORD --silent"] interval: 10s @@ -50,14 +49,15 @@ services: networks: [baiyue] redis: - image: redis:7.2.5-alpine - container_name: baiyue-redis - profiles: [cache] - command: ["redis-server", "--appendonly", "yes"] + image: docker.m.daocloud.io/library/redis:7.2.5-alpine + container_name: firstleg-test-redis + command: ["sh", "-c", "exec redis-server --appendonly yes --requirepass \"$${REDIS_PASSWORD}\""] + environment: + REDIS_PASSWORD: ${REDIS_PASSWORD:?请在.env中设置REDIS_PASSWORD} ports: ["6379:6379"] - volumes: [baiyue-redis-data:/data] + volumes: [firstleg-test-redis-data:/data] healthcheck: - test: ["CMD", "redis-cli", "ping"] + test: ["CMD-SHELL", "redis-cli -a \"$$REDIS_PASSWORD\" ping | grep PONG"] interval: 10s timeout: 5s retries: 10 @@ -65,9 +65,11 @@ services: networks: [baiyue] volumes: - baiyue-mysql-data: - baiyue-redis-data: + firstleg-test-mysql-data: + name: firstleg-test-mysql-data + firstleg-test-redis-data: + name: firstleg-test-redis-data networks: baiyue: - name: baiyue-network + name: ${INFRA_NETWORK:-firstleg-test-infra-network} diff --git a/docs/jenkins-multi-service-deployment.md b/docs/jenkins-multi-service-deployment.md index 1805ed062..1cbab027a 100644 --- a/docs/jenkins-multi-service-deployment.md +++ b/docs/jenkins-multi-service-deployment.md @@ -12,6 +12,7 @@ MySQL、Redis、Nacos 是外部基础设施,不包含在业务 Compose 文件 | --- | --- | | `Jenkinsfile` | 自动识别变更、测试、打包、构建镜像、推送和部署 | | `deploy/docker/Dockerfile` | 11 个服务共用的 Java 17 非 root 镜像模板 | +| `deploy/maven/settings-cn.xml` | Jenkins 构建使用的阿里云 Maven 公共仓库配置 | | `deploy/service-map.yml` | 模块、JAR 和端口的唯一映射清单 | | `deploy/docker-compose.yml` | 11 个业务服务的统一编排文件 | | `deploy/env/.env.test.example` | 测试环境变量模板,不含真实密码 |