fix(deploy): bound infrastructure container logs

This commit is contained in:
2026-09-02 15:30:29 +08:00
parent 9e0d2f6cdb
commit 25c4dd50b3
3 changed files with 39 additions and 0 deletions
+9
View File
@@ -1,10 +1,17 @@
name: firstleg-${DEPLOY_ENV:-test}-rocketmq name: firstleg-${DEPLOY_ENV:-test}-rocketmq
x-bounded-logging: &bounded-logging
driver: local
options:
max-size: ${DOCKER_LOG_MAX_SIZE:-50m}
max-file: "${DOCKER_LOG_MAX_FILE:-3}"
services: services:
rocketmq-namesrv: rocketmq-namesrv:
image: apache/rocketmq:5.3.1 image: apache/rocketmq:5.3.1
restart: unless-stopped restart: unless-stopped
command: sh mqnamesrv command: sh mqnamesrv
logging: *bounded-logging
networks: [infra-network] networks: [infra-network]
rocketmq-broker: rocketmq-broker:
@@ -17,6 +24,7 @@ services:
- ./rocketmq:/config:ro - ./rocketmq:/config:ro
- ${ROCKETMQ_DATA_DIR:-/data/firstleg/rocketmq/store}:/home/rocketmq/store - ${ROCKETMQ_DATA_DIR:-/data/firstleg/rocketmq/store}:/home/rocketmq/store
command: sh /config/render-broker-config.sh command: sh /config/render-broker-config.sh
logging: *bounded-logging
networks: [infra-network] networks: [infra-network]
rocketmq-topic-init: rocketmq-topic-init:
@@ -46,6 +54,7 @@ services:
-t "%DLQ%$${MQ_TOPIC_PREFIX}baiyue-audit-consumer-v1" -r 1 -w 1 -p 6' -t "%DLQ%$${MQ_TOPIC_PREFIX}baiyue-audit-consumer-v1" -r 1 -w 1 -p 6'
# Broker 注册较慢或任一初始化命令失败时整组重试;所有命令均幂等。 # Broker 注册较慢或任一初始化命令失败时整组重试;所有命令均幂等。
restart: on-failure restart: on-failure
logging: *bounded-logging
networks: [infra-network] networks: [infra-network]
networks: networks:
+9
View File
@@ -1,5 +1,11 @@
name: firstleg-test-infra name: firstleg-test-infra
x-bounded-logging: &bounded-logging
driver: local
options:
max-size: ${DOCKER_LOG_MAX_SIZE:-50m}
max-file: "${DOCKER_LOG_MAX_FILE:-3}"
services: services:
nacos: nacos:
image: docker.m.daocloud.io/nacos/nacos-server:v2.3.2 image: docker.m.daocloud.io/nacos/nacos-server:v2.3.2
@@ -22,6 +28,7 @@ services:
retries: 20 retries: 20
start_period: 30s start_period: 30s
restart: unless-stopped restart: unless-stopped
logging: *bounded-logging
networks: [baiyue] networks: [baiyue]
mysql: mysql:
@@ -46,6 +53,7 @@ services:
retries: 20 retries: 20
start_period: 30s start_period: 30s
restart: unless-stopped restart: unless-stopped
logging: *bounded-logging
networks: [baiyue] networks: [baiyue]
redis: redis:
@@ -62,6 +70,7 @@ services:
timeout: 5s timeout: 5s
retries: 10 retries: 10
restart: unless-stopped restart: unless-stopped
logging: *bounded-logging
networks: [baiyue] networks: [baiyue]
volumes: volumes:
@@ -28,6 +28,11 @@ const composeFiles = [
'deploy/docker-compose.overseas.yml', 'deploy/docker-compose.overseas.yml',
]; ];
const infrastructureComposeFiles = [
['deploy/docker-compose.rocketmq.yml', 3],
['docker-compose-infra.yml', 3],
];
test('deployable applications log only to stdout and stderr', () => { test('deployable applications log only to stdout and stderr', () => {
for (const path of applicationConfigs) { for (const path of applicationConfigs) {
const source = readFileSync(path, 'utf8'); const source = readFileSync(path, 'utf8');
@@ -52,3 +57,19 @@ test('runtime image does not prepare an application log directory', () => {
const dockerfile = readFileSync('deploy/docker/Dockerfile', 'utf8'); const dockerfile = readFileSync('deploy/docker/Dockerfile', 'utf8');
assert.doesNotMatch(dockerfile, /\/app\/logs/); assert.doesNotMatch(dockerfile, /\/app\/logs/);
}); });
test('infrastructure containers also use bounded local logs', () => {
for (const [path, expectedServiceCount] of infrastructureComposeFiles) {
const source = readFileSync(path, 'utf8');
assert.match(source, /x-bounded-logging:\s+&bounded-logging/, path);
assert.match(source, /driver:\s+local/, path);
assert.match(source, /DOCKER_LOG_MAX_SIZE/, path);
assert.match(source, /DOCKER_LOG_MAX_FILE/, path);
assert.equal(
source.match(/logging:\s+\*bounded-logging/g)?.length,
expectedServiceCount,
path,
);
assert.doesNotMatch(source, /driver:\s+json-file/, path);
}
});