chore: use test host database and redis in dev compose

This commit is contained in:
hajimi
2026-08-01 17:09:24 +08:00
parent 40619e2335
commit b4c212f68f
5 changed files with 43 additions and 50 deletions
+1
View File
@@ -32,3 +32,4 @@ qa/
./vscode/
.tmp*
.codex/
docker/.env.server
+6 -49
View File
@@ -11,13 +11,11 @@ services:
<<: *php-image
working_dir: /likeadmin_php/server
restart: unless-stopped
depends_on:
mysql:
condition: service_healthy
redis:
condition: service_healthy
volumes:
- ../server:/likeadmin_php/server
- ./.env.server:/likeadmin_php/server/.env:ro
extra_hosts:
- "host.docker.internal:host-gateway"
networks:
- sport-era-dev
@@ -25,15 +23,13 @@ services:
<<: *php-image
working_dir: /likeadmin_php/server
restart: unless-stopped
depends_on:
mysql:
condition: service_healthy
redis:
condition: service_healthy
command: >-
sh -c "while true; do php think crontab; sleep 60; done"
volumes:
- ../server:/likeadmin_php/server
- ./.env.server:/likeadmin_php/server/.env:ro
extra_hosts:
- "host.docker.internal:host-gateway"
networks:
- sport-era-dev
@@ -85,45 +81,6 @@ services:
networks:
- sport-era-dev
mysql:
image: mysql:8.2
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: ${SPORT_ERA_MYSQL_ROOT_PASSWORD:-root}
MYSQL_DATABASE: ${SPORT_ERA_MYSQL_DATABASE:-sbnews}
MYSQL_USER: ${SPORT_ERA_MYSQL_USER:-sbnews}
MYSQL_PASSWORD: ${SPORT_ERA_MYSQL_PASSWORD:-sbnews}
TZ: Asia/Shanghai
ports:
- "${SPORT_ERA_MYSQL_PORT:-3307}:3306"
volumes:
- ./data/mysql:/var/lib/mysql
healthcheck:
test: ["CMD-SHELL", "mysqladmin ping -h 127.0.0.1 -uroot -p$$MYSQL_ROOT_PASSWORD --silent"]
interval: 10s
timeout: 5s
retries: 10
start_period: 30s
networks:
- sport-era-dev
redis:
image: registry.cn-guangzhou.aliyuncs.com/likeadmin/redis:7.4.0
restart: unless-stopped
command: redis-server --appendonly yes
ports:
- "${SPORT_ERA_REDIS_PORT:-6379}:6379"
volumes:
- ./data/redis:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 5s
retries: 10
start_period: 10s
networks:
- sport-era-dev
volumes:
admin-node-modules:
uniapp-node-modules:
+18
View File
@@ -13,6 +13,24 @@
## 一、已完成事项
### 93. Docker 测试环境改用宿主机 MySQL 与 Redis
- 状态:代码已修改,待部署测试服验证 - 时间:2026-08-01
完成内容:
- `docker/docker-compose.dev.yml` 移除本地 MySQL、Redis 服务及后端对它们的启动依赖。
- Docker 后端和定时任务通过独立的 `docker/.env.server` 连接测试服宿主机上的 MySQL `test_sbnews` 与 Redis `6377/DB4`
- `docker/.env.server` 作为私有运行配置,不进入 Git 或服务器代码部署包;容器通过 `host.docker.internal` 访问宿主机服务。
涉及模块:
- `docker/docker-compose.dev.yml`
- `.gitignore`
- `scripts/deploy-server.ps1`
- `qa/backend/test_local_docker_php_performance_static.php`
验证说明:
- 已先执行静态检查,确认旧 compose 仍包含 MySQL/Redis 服务并按预期失败;修改完成后需重新执行静态检查、Compose 配置检查和测试服容器启动验证。
### 92. 本地 Docker PHP 接口性能修复
- 状态:代码已修改,待重新构建容器并验证 - 时间:2026-08-01
@@ -24,6 +24,8 @@ $uniappConfig = file_get_contents($files['uniapp_config']);
$expectations = [
[$compose, 'sport-era-dev-php:local', 'server 和 scheduler 应使用本地 PHP 镜像'],
[$compose, 'docker/Dockerfile.php', '本地 PHP 镜像应由 Dockerfile 构建'],
[$compose, './.env.server:/likeadmin_php/server/.env:ro', 'Docker 后端应使用独立的服务器环境文件'],
[$compose, 'host.docker.internal:host-gateway', 'Docker 后端应能访问宿主机上的数据库与 Redis'],
[$dockerfile, 'docker-php-ext-install', '本地 PHP 镜像必须安装 OPcache'],
[$dockerfile, 'opcache', '本地 PHP 镜像必须安装 OPcache'],
[$dockerfile, 'zz-opcache.ini', '本地 PHP 镜像必须载入 OPcache 配置'],
@@ -33,6 +35,20 @@ $expectations = [
[$uniappConfig, 'http://127.0.0.1:8000', 'H5 本地 API 应使用 IPv4 回环地址'],
];
foreach (['mysql:', 'redis:'] as $removedService) {
if (preg_match('/^ ' . preg_quote(rtrim($removedService, ':'), '/') . ':\s*$/m', $compose)) {
fwrite(STDERR, "本地 compose 不应再启动 {$removedService} 服务\n");
exit(1);
}
}
foreach (['depends_on:\n mysql:', 'depends_on:\n redis:'] as $removedDependency) {
if (strpos($compose, $removedDependency) !== false) {
fwrite(STDERR, "后端服务不应依赖已移除的本地服务\n");
exit(1);
}
}
foreach ($expectations as [$haystack, $needle, $message]) {
if (strpos($haystack, $needle) === false) {
fwrite(STDERR, $message . "\n");
+2 -1
View File
@@ -260,7 +260,8 @@ function Get-ArchiveExcludePatterns {
$patterns += @(
"server/.env",
"docker/.env",
"docker/.env.docker"
"docker/.env.docker",
"docker/.env.server"
)
}
if (-not $IncludeVendor) {