chore: scope mysql env in portainer stack

This commit is contained in:
lingniu
2026-07-01 15:03:59 +08:00
parent 3161e98eff
commit a6d0236fc4
2 changed files with 41 additions and 3 deletions

View File

@@ -26,9 +26,6 @@ x-common-env: &common-env
KAFKA_TOPIC_YUTONG_MQTT_EVENT: ${KAFKA_TOPIC_YUTONG_MQTT_EVENT:-vehicle.event.mqtt-yutong.v1} KAFKA_TOPIC_YUTONG_MQTT_EVENT: ${KAFKA_TOPIC_YUTONG_MQTT_EVENT:-vehicle.event.mqtt-yutong.v1}
KAFKA_TOPIC_YUTONG_MQTT_RAW: ${KAFKA_TOPIC_YUTONG_MQTT_RAW:-vehicle.raw.mqtt-yutong.v1} KAFKA_TOPIC_YUTONG_MQTT_RAW: ${KAFKA_TOPIC_YUTONG_MQTT_RAW:-vehicle.raw.mqtt-yutong.v1}
KAFKA_TOPIC_YUTONG_MQTT_DLQ: ${KAFKA_TOPIC_YUTONG_MQTT_DLQ:-vehicle.dlq.mqtt-yutong.v1} KAFKA_TOPIC_YUTONG_MQTT_DLQ: ${KAFKA_TOPIC_YUTONG_MQTT_DLQ:-vehicle.dlq.mqtt-yutong.v1}
MYSQL_JDBC_URL: ${MYSQL_JDBC_URL:-}
MYSQL_USERNAME: ${MYSQL_USERNAME:-}
MYSQL_PASSWORD: ${MYSQL_PASSWORD:-}
x-identity-mysql-env: &identity-mysql-env x-identity-mysql-env: &identity-mysql-env
VEHICLE_IDENTITY_MYSQL_JDBC_URL: ${MYSQL_JDBC_URL:-} VEHICLE_IDENTITY_MYSQL_JDBC_URL: ${MYSQL_JDBC_URL:-}

View File

@@ -577,6 +577,35 @@ class PortainerComposeResourceLimitsTest {
.doesNotContain("REDIS_PASSWORD"); .doesNotContain("REDIS_PASSWORD");
} }
@Test
void mysqlEnvironmentIsScopedToIdentityAndAnalyticsOnly() throws IOException {
String compose = Files.readString(repositoryRoot().resolve("deploy/portainer/docker-compose.yml"));
String commonEnv = commonEnvBlock(compose);
String identityEnv = blockBetween(compose, "x-identity-mysql-env: &identity-mysql-env\n",
"\nx-redis-session-env:");
String ingestServices = serviceBlock(compose, "gb32960-ingest-app")
+ serviceBlock(compose, "jt808-ingest-app")
+ serviceBlock(compose, "yutong-mqtt-app");
String analyticsService = serviceBlock(compose, "vehicle-analytics-app");
assertThat(commonEnv)
.doesNotContain("MYSQL_JDBC_URL")
.doesNotContain("MYSQL_USERNAME")
.doesNotContain("MYSQL_PASSWORD");
assertThat(identityEnv)
.contains("VEHICLE_IDENTITY_MYSQL_JDBC_URL: ${MYSQL_JDBC_URL:-}")
.contains("VEHICLE_IDENTITY_MYSQL_USERNAME: ${MYSQL_USERNAME:-}")
.contains("VEHICLE_IDENTITY_MYSQL_PASSWORD: ${MYSQL_PASSWORD:-}");
assertThat(ingestServices)
.doesNotContain("\n MYSQL_JDBC_URL:")
.doesNotContain("\n MYSQL_USERNAME:")
.doesNotContain("\n MYSQL_PASSWORD:");
assertThat(analyticsService)
.contains("MYSQL_JDBC_URL: ${MYSQL_JDBC_URL:-}")
.contains("MYSQL_USERNAME: ${MYSQL_USERNAME:-}")
.contains("MYSQL_PASSWORD: ${MYSQL_PASSWORD:-}");
}
@Test @Test
void ingestAppsReuseSharedIdentityAndRedisEnvironmentAnchors() throws IOException { void ingestAppsReuseSharedIdentityAndRedisEnvironmentAnchors() throws IOException {
String compose = Files.readString(repositoryRoot().resolve("deploy/portainer/docker-compose.yml")); String compose = Files.readString(repositoryRoot().resolve("deploy/portainer/docker-compose.yml"));
@@ -700,6 +729,18 @@ class PortainerComposeResourceLimitsTest {
return compose.substring(start, end); return compose.substring(start, end);
} }
private static String blockBetween(String text, String startMarker, String endMarker) {
int start = text.indexOf(startMarker);
if (start < 0) {
throw new IllegalArgumentException("block start not found: " + startMarker);
}
int end = text.indexOf(endMarker, start + startMarker.length());
if (end < 0) {
throw new IllegalArgumentException("block end not found: " + endMarker);
}
return text.substring(start, end);
}
private static int countOccurrences(String text, String needle) { private static int countOccurrences(String text, String needle) {
int count = 0; int count = 0;
int index = 0; int index = 0;