chore: 补充部署编排配置

- 增加 Docker Compose、共享服务初始化脚本与 Nginx 配置

- 补充部署环境应用配置与数据库初始化脚本
This commit is contained in:
2026-03-20 12:45:00 +08:00
parent 9605384edc
commit 425d8dd455
7 changed files with 270 additions and 0 deletions

86
deploy/application.yml Normal file
View File

@@ -0,0 +1,86 @@
spring:
application:
name: easycard-backend
profiles:
active: docker
servlet:
multipart:
max-file-size: 8MB
max-request-size: 8MB
datasource:
url: jdbc:mysql://mysql-shared:3306/easycard?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai&useSSL=false&allowPublicKeyRetrieval=true
username: root
password: root
driver-class-name: com.mysql.cj.jdbc.Driver
data:
redis:
host: redis-shared
port: 6379
database: 0
password: 123456
flyway:
enabled: true
locations: classpath:db/migration/mysql
baseline-on-migrate: true
encoding: UTF-8
connect-retries: 30
jackson:
time-zone: Asia/Shanghai
server:
port: 8112
forward-headers-strategy: framework
servlet:
context-path: /
management:
endpoints:
web:
exposure:
include: health,info
endpoint:
health:
show-details: always
springdoc:
api-docs:
enabled: true
swagger-ui:
path: /swagger-ui.html
mybatis-plus:
configuration:
map-underscore-to-camel-case: true
global-config:
db-config:
id-type: auto
logic-delete-field: deleted
logic-delete-value: 1
logic-not-delete-value: 0
easycard:
security:
jwt-secret: change-me-in-production
jwt-expire-hours: 24
web:
cors:
allowed-origins: http://localhost:5173,http://127.0.0.1:5173,http://localhost:8081,http://127.0.0.1:8081
allowed-origin-patterns: ""
allowed-methods: GET,POST,PUT,PATCH,DELETE,OPTIONS
allowed-headers: "*"
exposed-headers: Authorization
allow-credentials: true
max-age: 1800
storage:
endpoint: http://minio-shared:9000
public-endpoint: http://127.0.0.1:39000
access-key: easyflowadmin
secret-key: easyflowadmin123
bucket: easycard
logging:
file:
path: /app/logs
level:
root: INFO
com.easycard: INFO

1
deploy/data/.gitkeep Normal file
View File

@@ -0,0 +1 @@

80
deploy/docker-compose.yml Normal file
View File

@@ -0,0 +1,80 @@
services:
mysql-init:
image: ${MYSQL_IMAGE:-mysql:8.0.36}
restart: "no"
environment:
TZ: ${TZ:-Asia/Shanghai}
MYSQL_HOST: ${MYSQL_SHARED_HOST:-mysql-shared}
MYSQL_PORT: ${MYSQL_SHARED_PORT:-3306}
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-root}
MYSQL_INIT_SQL_FILE: /tmp/scripts/sql/easycard_init.sql
volumes:
- ./scripts/init-shared-mysql.sh:/tmp/init-shared-mysql.sh:ro
- ./scripts/sql/easycard_init.sql:/tmp/scripts/sql/easycard_init.sql:ro
entrypoint: ["/bin/sh", "/tmp/init-shared-mysql.sh"]
networks:
- middleware-net
minio-init:
image: ${MINIO_MC_IMAGE:-quay.io/minio/aistor/mc:RELEASE.2025-08-21T03-14-05Z}
restart: "no"
environment:
MINIO_ALIAS: ${MINIO_ALIAS:-easycard}
MINIO_ENDPOINT: ${MINIO_SHARED_ENDPOINT:-http://minio-shared:9000}
MINIO_ROOT_USER: ${MINIO_ROOT_USER:-easyflowadmin}
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD:-easyflowadmin123}
MINIO_BUCKET: ${MINIO_BUCKET:-easycard}
MINIO_PUBLIC_BUCKET: ${MINIO_PUBLIC_BUCKET:-true}
volumes:
- ./scripts/init-shared-minio.sh:/tmp/init-shared-minio.sh:ro
entrypoint: ["/bin/sh", "/tmp/init-shared-minio.sh"]
networks:
- middleware-net
backend:
image: easycard-backend:0.3
container_name: easycard-backend
restart: unless-stopped
depends_on:
mysql-init:
condition: service_completed_successfully
minio-init:
condition: service_completed_successfully
environment:
TZ: ${TZ:-Asia/Shanghai}
SPRING_PROFILES_ACTIVE: docker
SPRING_CONFIG_ADDITIONAL_LOCATION: file:/app/
SERVER_PORT: 8112
DB_HOST: ${MYSQL_SHARED_HOST:-mysql-shared}
DB_PORT: ${MYSQL_SHARED_PORT:-3306}
DB_NAME: ${DB_NAME:-easycard}
DB_USERNAME: ${DB_USERNAME:-root}
DB_PASSWORD: ${MYSQL_ROOT_PASSWORD:-root}
REDIS_HOST: ${REDIS_SHARED_HOST:-redis-shared}
REDIS_PORT: ${REDIS_SHARED_PORT:-6379}
REDIS_DATABASE: ${REDIS_DATABASE:-0}
REDIS_PASSWORD: ${REDIS_PASSWORD:-123456}
JWT_SECRET: ${JWT_SECRET:-change-me-in-docker}
MINIO_ENDPOINT: ${MINIO_SHARED_ENDPOINT:-http://minio-shared:9000}
MINIO_PUBLIC_ENDPOINT: ${MINIO_PUBLIC_ENDPOINT:-http://127.0.0.1:39000}
MINIO_ACCESS_KEY: ${MINIO_ROOT_USER:-easyflowadmin}
MINIO_SECRET_KEY: ${MINIO_ROOT_PASSWORD:-easyflowadmin123}
MINIO_BUCKET: ${MINIO_BUCKET:-easycard}
LOG_PATH: /app/logs
JAVA_OPTS: ${JAVA_OPTS:--Xms256m -Xmx512m}
ports:
- "8112:8112"
volumes:
- ./application.yml:/app/application.yml:ro
- ./data/backend/logs:/app/logs
networks:
- easycard_net
- middleware-net
networks:
easycard_net:
name: ${APP_NETWORK_NAME:-easycard-app-net}
driver: bridge
middleware-net:
external: true
name: ${MIDDLEWARE_NETWORK_NAME:-shared-middleware-net}

View File

@@ -0,0 +1,40 @@
upstream easycard_backend {
server 127.0.0.1:8112;
keepalive 32;
}
server {
listen 80;
server_name _;
client_max_body_size 20m;
location = /card {
return 301 /card/;
}
# 按服务器实际路径替换为前端 dist 目录。
root /root/easycard/dist;
index index.html;
# 仅将 /card/api 前缀映射到后端 8112 服务。
# 例如:/card/api/v1/system/ping -> /api/v1/system/ping
location ^~ /card/api/ {
rewrite ^/card(/.*)$ $1 break;
proxy_pass http://easycard_backend;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Prefix /card;
proxy_redirect off;
}
# 托管前端静态资源与 history 路由。
location ^~ /card/ {
rewrite ^/card/(.*)$ /$1 break;
try_files $uri $uri/ /index.html;
}
}

View File

@@ -0,0 +1,23 @@
#!/bin/sh
set -eu
minio_alias="${MINIO_ALIAS:-easycard}"
minio_endpoint="${MINIO_ENDPOINT:-http://minio-shared:9000}"
minio_root_user="${MINIO_ROOT_USER:-easyflowadmin}"
minio_root_password="${MINIO_ROOT_PASSWORD:-easyflowadmin123}"
minio_bucket="${MINIO_BUCKET:-easycard}"
minio_public_bucket="${MINIO_PUBLIC_BUCKET:-true}"
echo "waiting for shared minio at ${minio_endpoint} ..."
until mc alias set "${minio_alias}" "${minio_endpoint}" "${minio_root_user}" "${minio_root_password}"; do
sleep 2
done
mc mb -p "${minio_alias}/${minio_bucket}" || true
if [ "${minio_public_bucket}" = "true" ]; then
mc anonymous set download "${minio_alias}/${minio_bucket}" || true
fi
echo "shared minio bucket initialization completed"

View File

@@ -0,0 +1,28 @@
#!/bin/sh
set -eu
mysql_host="${MYSQL_HOST:-mysql-shared}"
mysql_port="${MYSQL_PORT:-3306}"
mysql_root_password="${MYSQL_ROOT_PASSWORD:-root}"
mysql_init_sql_file="${MYSQL_INIT_SQL_FILE:-/tmp/scripts/sql/easycard_init.sql}"
echo "waiting for shared mysql at ${mysql_host}:${mysql_port} ..."
until mysqladmin ping \
-h "${mysql_host}" \
-P "${mysql_port}" \
-uroot \
-p"${mysql_root_password}" \
--silent; do
sleep 2
done
echo "initializing database from ${mysql_init_sql_file} ..."
mysql \
-h "${mysql_host}" \
-P "${mysql_port}" \
-uroot \
-p"${mysql_root_password}" \
< "${mysql_init_sql_file}"
echo "shared mysql initialization completed"

View File

@@ -0,0 +1,12 @@
SET NAMES utf8mb4;
CREATE DATABASE IF NOT EXISTS `easycard`
DEFAULT CHARACTER SET utf8mb4
DEFAULT COLLATE utf8mb4_0900_ai_ci;
USE `easycard`;
-- 当前阶段收敛为:
-- 1. MySQL 初始化脚本只负责建库
-- 2. 表结构、基础平台数据、演示数据全部由 Flyway 管理
-- 3. 避免脚本目录与 Flyway 目录重复维护两套结构脚本