deploy: add portainer readiness healthchecks

This commit is contained in:
lingniu
2026-07-01 12:14:45 +08:00
parent 5ff7cfb9bb
commit bc60017c30
3 changed files with 58 additions and 0 deletions

View File

@@ -7,6 +7,10 @@ ENV APP_NAME=${APP_NAME}
ENV APP_VERSION=${APP_VERSION} ENV APP_VERSION=${APP_VERSION}
ENV JAVA_OPTS="--sun-misc-unsafe-memory-access=allow" ENV JAVA_OPTS="--sun-misc-unsafe-memory-access=allow"
RUN apt-get update \
&& apt-get install -y --no-install-recommends curl \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app WORKDIR /app
COPY modules/apps/${APP_NAME}/target/${APP_NAME}.jar /app/app.jar COPY modules/apps/${APP_NAME}/target/${APP_NAME}.jar /app/app.jar

View File

@@ -76,6 +76,12 @@ services:
- gb32960-ingest-data:/data - gb32960-ingest-data:/data
networks: networks:
- vehicle-ingest - vehicle-ingest
healthcheck:
test: ["CMD-SHELL", "curl -fsS http://127.0.0.1:20100/actuator/health/readiness >/dev/null"]
interval: 30s
timeout: 5s
retries: 3
start_period: 60s
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: crpi-85r4m0ackrm3qpje.cn-shanghai.personal.cr.aliyuncs.com/oneos/jt808-ingest-app:${LINGNIU_IMAGE_VERSION:?set LINGNIU_IMAGE_VERSION}
@@ -99,6 +105,12 @@ services:
- jt808-ingest-data:/data - jt808-ingest-data:/data
networks: networks:
- vehicle-ingest - vehicle-ingest
healthcheck:
test: ["CMD-SHELL", "curl -fsS http://127.0.0.1:20400/actuator/health/readiness >/dev/null"]
interval: 30s
timeout: 5s
retries: 3
start_period: 60s
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: crpi-85r4m0ackrm3qpje.cn-shanghai.personal.cr.aliyuncs.com/oneos/yutong-mqtt-app:${LINGNIU_IMAGE_VERSION:?set LINGNIU_IMAGE_VERSION}
@@ -129,6 +141,12 @@ services:
- yutong-mqtt-data:/data - yutong-mqtt-data:/data
networks: networks:
- vehicle-ingest - vehicle-ingest
healthcheck:
test: ["CMD-SHELL", "curl -fsS http://127.0.0.1:20500/actuator/health/readiness >/dev/null"]
interval: 30s
timeout: 5s
retries: 3
start_period: 60s
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: crpi-85r4m0ackrm3qpje.cn-shanghai.personal.cr.aliyuncs.com/oneos/vehicle-history-app:${LINGNIU_IMAGE_VERSION:?set LINGNIU_IMAGE_VERSION}
@@ -164,6 +182,12 @@ services:
- "${VEHICLE_HISTORY_HTTP_PORT:-20200}:20200" - "${VEHICLE_HISTORY_HTTP_PORT:-20200}:20200"
networks: networks:
- vehicle-ingest - vehicle-ingest
healthcheck:
test: ["CMD-SHELL", "curl -fsS http://127.0.0.1:20200/actuator/health/readiness >/dev/null"]
interval: 30s
timeout: 5s
retries: 3
start_period: 60s
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: crpi-85r4m0ackrm3qpje.cn-shanghai.personal.cr.aliyuncs.com/oneos/vehicle-analytics-app:${LINGNIU_IMAGE_VERSION:?set LINGNIU_IMAGE_VERSION}
@@ -188,6 +212,12 @@ services:
- "${VEHICLE_ANALYTICS_HTTP_PORT:-20300}:20300" - "${VEHICLE_ANALYTICS_HTTP_PORT:-20300}:20300"
networks: networks:
- vehicle-ingest - vehicle-ingest
healthcheck:
test: ["CMD-SHELL", "curl -fsS http://127.0.0.1:20300/actuator/health/readiness >/dev/null"]
interval: 30s
timeout: 5s
retries: 3
start_period: 60s
networks: networks:
vehicle-ingest: vehicle-ingest:

View File

@@ -39,6 +39,19 @@ class PortainerComposeResourceLimitsTest {
assertServiceMemoryLimit(compose, "vehicle-analytics-app", "VEHICLE_ANALYTICS_MEM_LIMIT", "1024m"); assertServiceMemoryLimit(compose, "vehicle-analytics-app", "VEHICLE_ANALYTICS_MEM_LIMIT", "1024m");
} }
@Test
void portainerServicesUseContainerReadinessHealthchecks() throws IOException {
String compose = Files.readString(repositoryRoot().resolve("deploy/portainer/docker-compose.yml"));
String dockerfile = Files.readString(repositoryRoot().resolve("Dockerfile"));
assertThat(dockerfile).contains("apt-get install -y --no-install-recommends curl");
assertServiceReadinessHealthcheck(compose, "gb32960-ingest-app", "20100");
assertServiceReadinessHealthcheck(compose, "jt808-ingest-app", "20400");
assertServiceReadinessHealthcheck(compose, "yutong-mqtt-app", "20500");
assertServiceReadinessHealthcheck(compose, "vehicle-history-app", "20200");
assertServiceReadinessHealthcheck(compose, "vehicle-analytics-app", "20300");
}
@Test @Test
void containerDefaultsIncludeJava25UnsafeCompatibilityFlag() throws IOException { void containerDefaultsIncludeJava25UnsafeCompatibilityFlag() throws IOException {
String compose = Files.readString(repositoryRoot().resolve("deploy/portainer/docker-compose.yml")); String compose = Files.readString(repositoryRoot().resolve("deploy/portainer/docker-compose.yml"));
@@ -382,6 +395,17 @@ class PortainerComposeResourceLimitsTest {
.contains(" mem_limit: ${" + envName + ":-" + defaultLimit + "}"); .contains(" mem_limit: ${" + envName + ":-" + defaultLimit + "}");
} }
private static void assertServiceReadinessHealthcheck(String compose, String serviceName, String httpPort) {
assertThat(serviceBlock(compose, serviceName))
.contains(" healthcheck:\n")
.contains(" test: [\"CMD-SHELL\", \"curl -fsS http://127.0.0.1:"
+ httpPort + "/actuator/health/readiness >/dev/null\"]")
.contains(" interval: 30s\n")
.contains(" timeout: 5s\n")
.contains(" retries: 3\n")
.contains(" start_period: 60s\n");
}
private static String serviceBlock(String compose, String serviceName) { private static String serviceBlock(String compose, String serviceName) {
String marker = "\n " + serviceName + ":\n"; String marker = "\n " + serviceName + ":\n";
int start = compose.indexOf(marker); int start = compose.indexOf(marker);