deploy: parameterize portainer image prefix

This commit is contained in:
lingniu
2026-07-01 12:40:25 +08:00
parent afed6cd4f3
commit 9fb77a1aa2
2 changed files with 37 additions and 5 deletions

View File

@@ -4,6 +4,7 @@ version: "3.8"
# Legacy and optional services stay outside this compose file. # Legacy and optional services stay outside this compose file.
# Set LINGNIU_IMAGE_VERSION in Portainer Stack env, for example: # Set LINGNIU_IMAGE_VERSION in Portainer Stack env, for example:
# main-0.1.0-SNAPSHOT-22468e7 # main-0.1.0-SNAPSHOT-22468e7
# Override LINGNIU_IMAGE_REGISTRY / LINGNIU_IMAGE_NAMESPACE only when publishing to another registry.
x-common-env: &common-env x-common-env: &common-env
TZ: Asia/Shanghai TZ: Asia/Shanghai
JAVA_OPTS: ${JAVA_OPTS:---sun-misc-unsafe-memory-access=allow -XX:+UseZGC -XX:MaxRAMPercentage=75} JAVA_OPTS: ${JAVA_OPTS:---sun-misc-unsafe-memory-access=allow -XX:+UseZGC -XX:MaxRAMPercentage=75}
@@ -53,7 +54,7 @@ x-readiness-healthcheck: &readiness-healthcheck
services: services:
gb32960-ingest-app: gb32960-ingest-app:
image: crpi-85r4m0ackrm3qpje.cn-shanghai.personal.cr.aliyuncs.com/oneos/gb32960-ingest-app:${LINGNIU_IMAGE_VERSION:?set LINGNIU_IMAGE_VERSION} image: ${LINGNIU_IMAGE_REGISTRY:-crpi-85r4m0ackrm3qpje.cn-shanghai.personal.cr.aliyuncs.com}/${LINGNIU_IMAGE_NAMESPACE:-oneos}/gb32960-ingest-app:${LINGNIU_IMAGE_VERSION:?set LINGNIU_IMAGE_VERSION}
container_name: gb32960-ingest-app container_name: gb32960-ingest-app
restart: unless-stopped restart: unless-stopped
mem_limit: ${GB32960_MEM_LIMIT:-768m} mem_limit: ${GB32960_MEM_LIMIT:-768m}
@@ -87,7 +88,7 @@ services:
test: ["CMD-SHELL", "curl -fsS http://127.0.0.1:20100/actuator/health/readiness >/dev/null"] test: ["CMD-SHELL", "curl -fsS http://127.0.0.1:20100/actuator/health/readiness >/dev/null"]
jt808-ingest-app: jt808-ingest-app:
image: crpi-85r4m0ackrm3qpje.cn-shanghai.personal.cr.aliyuncs.com/oneos/jt808-ingest-app:${LINGNIU_IMAGE_VERSION:?set LINGNIU_IMAGE_VERSION} image: ${LINGNIU_IMAGE_REGISTRY:-crpi-85r4m0ackrm3qpje.cn-shanghai.personal.cr.aliyuncs.com}/${LINGNIU_IMAGE_NAMESPACE:-oneos}/jt808-ingest-app:${LINGNIU_IMAGE_VERSION:?set LINGNIU_IMAGE_VERSION}
container_name: jt808-ingest-app container_name: jt808-ingest-app
restart: unless-stopped restart: unless-stopped
mem_limit: ${JT808_MEM_LIMIT:-768m} mem_limit: ${JT808_MEM_LIMIT:-768m}
@@ -113,7 +114,7 @@ services:
test: ["CMD-SHELL", "curl -fsS http://127.0.0.1:20400/actuator/health/readiness >/dev/null"] test: ["CMD-SHELL", "curl -fsS http://127.0.0.1:20400/actuator/health/readiness >/dev/null"]
yutong-mqtt-app: yutong-mqtt-app:
image: crpi-85r4m0ackrm3qpje.cn-shanghai.personal.cr.aliyuncs.com/oneos/yutong-mqtt-app:${LINGNIU_IMAGE_VERSION:?set LINGNIU_IMAGE_VERSION} image: ${LINGNIU_IMAGE_REGISTRY:-crpi-85r4m0ackrm3qpje.cn-shanghai.personal.cr.aliyuncs.com}/${LINGNIU_IMAGE_NAMESPACE:-oneos}/yutong-mqtt-app:${LINGNIU_IMAGE_VERSION:?set LINGNIU_IMAGE_VERSION}
container_name: yutong-mqtt-app container_name: yutong-mqtt-app
restart: unless-stopped restart: unless-stopped
mem_limit: ${YUTONG_MQTT_MEM_LIMIT:-512m} mem_limit: ${YUTONG_MQTT_MEM_LIMIT:-512m}
@@ -146,7 +147,7 @@ services:
test: ["CMD-SHELL", "curl -fsS http://127.0.0.1:20500/actuator/health/readiness >/dev/null"] test: ["CMD-SHELL", "curl -fsS http://127.0.0.1:20500/actuator/health/readiness >/dev/null"]
vehicle-history-app: vehicle-history-app:
image: crpi-85r4m0ackrm3qpje.cn-shanghai.personal.cr.aliyuncs.com/oneos/vehicle-history-app:${LINGNIU_IMAGE_VERSION:?set LINGNIU_IMAGE_VERSION} image: ${LINGNIU_IMAGE_REGISTRY:-crpi-85r4m0ackrm3qpje.cn-shanghai.personal.cr.aliyuncs.com}/${LINGNIU_IMAGE_NAMESPACE:-oneos}/vehicle-history-app:${LINGNIU_IMAGE_VERSION:?set LINGNIU_IMAGE_VERSION}
container_name: vehicle-history-app container_name: vehicle-history-app
restart: unless-stopped restart: unless-stopped
mem_limit: ${VEHICLE_HISTORY_MEM_LIMIT:-1536m} mem_limit: ${VEHICLE_HISTORY_MEM_LIMIT:-1536m}
@@ -184,7 +185,7 @@ services:
test: ["CMD-SHELL", "curl -fsS http://127.0.0.1:20200/actuator/health/readiness >/dev/null"] test: ["CMD-SHELL", "curl -fsS http://127.0.0.1:20200/actuator/health/readiness >/dev/null"]
vehicle-analytics-app: vehicle-analytics-app:
image: crpi-85r4m0ackrm3qpje.cn-shanghai.personal.cr.aliyuncs.com/oneos/vehicle-analytics-app:${LINGNIU_IMAGE_VERSION:?set LINGNIU_IMAGE_VERSION} image: ${LINGNIU_IMAGE_REGISTRY:-crpi-85r4m0ackrm3qpje.cn-shanghai.personal.cr.aliyuncs.com}/${LINGNIU_IMAGE_NAMESPACE:-oneos}/vehicle-analytics-app:${LINGNIU_IMAGE_VERSION:?set LINGNIU_IMAGE_VERSION}
container_name: vehicle-analytics-app container_name: vehicle-analytics-app
restart: unless-stopped restart: unless-stopped
mem_limit: ${VEHICLE_ANALYTICS_MEM_LIMIT:-1024m} mem_limit: ${VEHICLE_ANALYTICS_MEM_LIMIT:-1024m}

View File

@@ -39,6 +39,27 @@ class PortainerComposeResourceLimitsTest {
assertServiceMemoryLimit(compose, "vehicle-analytics-app", "VEHICLE_ANALYTICS_MEM_LIMIT", "1024m"); assertServiceMemoryLimit(compose, "vehicle-analytics-app", "VEHICLE_ANALYTICS_MEM_LIMIT", "1024m");
} }
@Test
void productionImagesShareOverridableRegistryAndNamespace() throws IOException {
String compose = Files.readString(repositoryRoot().resolve("deploy/portainer/docker-compose.yml"));
String registry = "${LINGNIU_IMAGE_REGISTRY:-crpi-85r4m0ackrm3qpje.cn-shanghai.personal.cr.aliyuncs.com}";
String namespace = "${LINGNIU_IMAGE_NAMESPACE:-oneos}";
for (String serviceName : List.of(
"gb32960-ingest-app",
"jt808-ingest-app",
"yutong-mqtt-app",
"vehicle-history-app",
"vehicle-analytics-app")) {
assertThat(serviceBlock(compose, serviceName))
.contains("image: " + registry + "/" + namespace + "/" + serviceName
+ ":${LINGNIU_IMAGE_VERSION:?set LINGNIU_IMAGE_VERSION}");
}
assertThat(countOccurrences(compose, "image: crpi-85r4m0ackrm3qpje"))
.isZero();
assertThat(countOccurrences(compose, "/oneos/")).isZero();
}
@Test @Test
void portainerServicesUseContainerReadinessHealthchecks() throws IOException { void portainerServicesUseContainerReadinessHealthchecks() throws IOException {
String compose = Files.readString(repositoryRoot().resolve("deploy/portainer/docker-compose.yml")); String compose = Files.readString(repositoryRoot().resolve("deploy/portainer/docker-compose.yml"));
@@ -490,6 +511,16 @@ class PortainerComposeResourceLimitsTest {
return compose.substring(start, end); return compose.substring(start, end);
} }
private static int countOccurrences(String text, String needle) {
int count = 0;
int index = 0;
while ((index = text.indexOf(needle, index)) >= 0) {
count++;
index += needle.length();
}
return count;
}
private static Properties yamlProperties(Path path) { private static Properties yamlProperties(Path path) {
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean(); YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
factory.setResources(new FileSystemResource(path)); factory.setResources(new FileSystemResource(path));