Added healthcheck

pom.xml: Bump version, update dependencies
Dockerfile: Added build step, Added healthcheck
SnowflakeService.java: added endpoint for health check
This commit is contained in:
2024-06-23 00:29:24 +02:00
parent 627315ede9
commit b4510b30f5
3 changed files with 27 additions and 7 deletions

View File

@@ -1,9 +1,24 @@
#
# Build
#
FROM maven:3.9.7-eclipse-temurin-21-alpine AS build
ENV HOME=/usr/app
RUN mkdir -p $HOME
WORKDIR $HOME
ADD . $HOME
RUN mvn -f $HOME/pom.xml clean compile assembly:single
#
# Package
#
FROM eclipse-temurin:21-jre-alpine
LABEL authors="B00tLoad_"
ARG JAR_FILE=/usr/app/target/*.jar
RUN apk --no-cache add curl
RUN mkdir -p /opt/app
RUN mkdir -p /data/b00tload-tools/snowflake
COPY target/SnowflakeService-jar-with-dependencies.jar /opt/app
HEALTHCHECK CMD curl -f http://localhost:9567/health || exit 1
COPY --from=build $JAR_FILE /opt/app
CMD ["java", "-jar", "/opt/app/SnowflakeService-jar-with-dependencies.jar", "--docker"]

View File

@@ -6,7 +6,7 @@
<groupId>space.b00tload.services</groupId>
<artifactId>SnowflakeService</artifactId>
<version>1.0.0</version>
<version>1.1.0</version>
<name>SnowflakeService</name>
<description>A tool/microservice to centrally generate snowflake IDs.</description>
@@ -76,7 +76,7 @@
<dependency>
<groupId>io.javalin</groupId>
<artifactId>javalin</artifactId>
<version>6.1.3</version>
<version>6.1.6</version>
</dependency>
<dependency>
<groupId>com.aayushatharva.brotli4j</groupId>
@@ -86,7 +86,7 @@
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10.1</version>
<version>2.11.0</version>
</dependency>
</dependencies>
@@ -108,7 +108,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.6.3</version>
<version>3.7.0</version>
<configuration>
<tags>
<tag>

View File

@@ -72,6 +72,11 @@ public class SnowflakeService {
LoggerFactory.getLogger(config.getClass()).info("{} served in {}ms to {}(UA: \"{}\")", ctx.fullUrl(), executionTimeMs, ctx.req().getRemoteAddr(), ctx.userAgent());
});
});
endpointServer.addEndpoint(new Endpoint(HandlerType.GET, "health", ctx -> {
JsonObject ret = new JsonObject();
ret.addProperty("status", "UP");
ctx.status(200).result(ret.toString()).contentType(ContentType.APPLICATION_JSON);
}));
endpointServer.addEndpoint(new Endpoint(HandlerType.GET, "generate", ctx -> {
JsonObject ret = new JsonObject();
ret.addProperty("id", SnowflakeIDGenerator.getInstance().generateID());