diff --git a/Dockerfile b/Dockerfile index 8ed08d18..2470f430 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,14 @@ -FROM eclipse-temurin:21.0.3_9-jre +FROM eclipse-temurin:21.0.4_7-jre + +ENV PATH_TO_JAR=/application/pogues-bo.jar WORKDIR application RUN rm -rf /application -ADD ./target/pogues-bo.jar /application/pogues-bo.jar -ENTRYPOINT ["java", "-jar", "/application/pogues-bo.jar"] +ADD ./target/pogues-bo.jar $PATH_TO_JAR + +ENV JAVA_TOOL_OPTIONS_DEFAULT \ + -XX:MaxRAMPercentage=75 \ + -XX:+UseParallelGC + +ENTRYPOINT [ "/bin/sh", "-c", \ + "export JAVA_TOOL_OPTIONS=\"$JAVA_TOOL_OPTIONS_DEFAULT $JAVA_TOOL_OPTIONS\"; \ + exec java -jar $PATH_TO_JAR" ] diff --git a/pom.xml b/pom.xml index e8d724b1..b5108c11 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.springframework.boot spring-boot-starter-parent - 3.3.1 + 3.3.2 @@ -13,7 +13,7 @@ fr.insee Pogues-BO jar - 4.7.5 + 4.7.6 Pogues-Back-Office @@ -24,7 +24,7 @@ 2.9 2.6.0 0.8.12 - 12.4 + 12.5 4.28.0 3.1.8 diff --git a/src/main/java/fr/insee/pogues/Pogues.java b/src/main/java/fr/insee/pogues/Pogues.java index 543ef03f..80f20a2b 100644 --- a/src/main/java/fr/insee/pogues/Pogues.java +++ b/src/main/java/fr/insee/pogues/Pogues.java @@ -1,23 +1,33 @@ package fr.insee.pogues; +import fr.insee.pogues.configuration.PropertiesLogger; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.boot.context.properties.ConfigurationPropertiesScan; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; +import org.springframework.context.event.EventListener; import org.springframework.transaction.annotation.EnableTransactionManagement; @SpringBootApplication(scanBasePackages = "fr.insee.pogues") @EnableTransactionManagement @ConfigurationPropertiesScan +@Slf4j public class Pogues extends SpringBootServletInitializer { - @Override - protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { - return application.sources(Pogues.class); + public static SpringApplicationBuilder configureApplicationBuilder(SpringApplicationBuilder springApplicationBuilder){ + return springApplicationBuilder.sources(Pogues.class).listeners(new PropertiesLogger()); } public static void main(String[] args) { - SpringApplication.run(Pogues.class, args); + configureApplicationBuilder(new SpringApplicationBuilder()).build().run(args); + } + + @EventListener + public void handleApplicationReady(ApplicationReadyEvent event) { + log.info("=============== Pogues Back-Office has successfully started. ==============="); } } diff --git a/src/main/java/fr/insee/pogues/configuration/PropertiesLogger.java b/src/main/java/fr/insee/pogues/configuration/PropertiesLogger.java index dd7afada..ad30c175 100644 --- a/src/main/java/fr/insee/pogues/configuration/PropertiesLogger.java +++ b/src/main/java/fr/insee/pogues/configuration/PropertiesLogger.java @@ -1,12 +1,18 @@ package fr.insee.pogues.configuration; -import lombok.NonNull; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent; +import org.springframework.boot.context.event.ApplicationPreparedEvent; +import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.boot.context.event.ApplicationStartingEvent; import org.springframework.context.ApplicationListener; +import org.springframework.context.event.ContextRefreshedEvent; +import org.springframework.context.event.ContextStartedEvent; +import org.springframework.context.event.EventListener; import org.springframework.core.env.AbstractEnvironment; import org.springframework.core.env.EnumerablePropertySource; import org.springframework.core.env.Environment; +import org.springframework.stereotype.Component; import java.util.Arrays; import java.util.Objects; @@ -23,14 +29,40 @@ public class PropertiesLogger implements ApplicationListener hiddenWords = Set.of("password", "pwd", "jeton", "token", "secret"); - @Override - public void onApplicationEvent(@NonNull ApplicationEnvironmentPreparedEvent event) { + @EventListener + public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) { + log.info(" Logging environment variables started"); + log.info("============================================================================"); + log.info(" Hardware"); + log.info("============================================================================"); + log.info(" ----> Java memory"); + Runtime runtime = Runtime.getRuntime(); + final long mb = 1024 * 1024; + final long maxMemoryInMb = runtime.maxMemory() / mb; + final long allocatedMemoryInMb = runtime.totalMemory() / mb; + final long freeMemoryInMb = runtime.freeMemory() / mb; + int maxStrLength = String.valueOf(maxMemoryInMb).length(); + log.info("+--------------------------------+-----{}+", "-".repeat(maxStrLength)); + log.info("| Type of memory | Size{}|", " ".repeat(maxStrLength)); + log.info("|--------------------------------|-----{}|", "-".repeat(maxStrLength)); + log.info("| Current Free memory | {}{} MB |", + " ".repeat(maxStrLength-String.valueOf(freeMemoryInMb).length()), + freeMemoryInMb); + log.info("| Current Allocated memory | {}{} MB |", + " ".repeat(maxStrLength-String.valueOf(allocatedMemoryInMb).length()), + allocatedMemoryInMb); + log.info("| Current total Free memory | {}{} MB |", + " ".repeat(maxStrLength-String.valueOf(freeMemoryInMb + (maxMemoryInMb - allocatedMemoryInMb)).length()), + freeMemoryInMb + (maxMemoryInMb - allocatedMemoryInMb)); + log.info("| Max available memory for JVM | {} MB |", maxMemoryInMb); + log.info("+--------------------------------+-----{}+", "-".repeat(maxStrLength)); + log.info(" ----> CPU"); + log.info(" Available CPUs : {}", runtime.availableProcessors()); + log.info("============================================================================"); + log.info(" Properties"); + log.info("============================================================================"); Environment environment = event.getEnvironment(); - log.info("==============================================================================================="); - log.info(" Properties "); - log.info("==============================================================================================="); - ((AbstractEnvironment) environment).getPropertySources().stream() .map(propertySource -> { if (propertySource instanceof EnumerablePropertySource) { @@ -45,7 +77,7 @@ public void onApplicationEvent(@NonNull ApplicationEnvironmentPreparedEvent even .filter(Objects::nonNull) .forEach(key -> log.info(key + " = " + resolveValueWithSecretAttribute(key, environment))); log.info("============================================================================"); - + log.info(" Logging environment variables ended "); } private static Object resolveValueWithSecretAttribute(String key, Environment environment) { @@ -55,5 +87,4 @@ private static Object resolveValueWithSecretAttribute(String key, Environment en return environment.getProperty(key); } - }