From 32249bff321a33f05611c0de979def6244f7b18b Mon Sep 17 00:00:00 2001 From: Igor Artamonov Date: Wed, 18 Mar 2020 21:09:59 -0400 Subject: [PATCH] solution: banner on run --- build.gradle | 21 +++++++++++++++++++ .../dshackle/DshackleEnvironment.kt | 5 +++-- .../kotlin/io/emeraldpay/dshackle/Starter.kt | 3 +++ src/main/resources/banner.txt | 9 ++++++++ 4 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 src/main/resources/banner.txt diff --git a/build.gradle b/build.gradle index c1e7daff..15cd2de3 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,7 @@ import java.time.Instant import java.time.ZoneId import java.time.format.DateTimeFormatter +import java.time.temporal.ChronoUnit buildscript { repositories { @@ -23,6 +24,7 @@ plugins { id "com.google.cloud.tools.jib" version "1.3.0" id 'org.springframework.boot' version '2.1.4.RELEASE' id 'io.spring.dependency-management' version '1.0.6.RELEASE' + id 'com.palantir.git-version' version '0.12.2' } @@ -161,4 +163,23 @@ jar { afterEvaluate { distZip.dependsOn(jar) + compileKotlin.dependsOn(generateVersion) +} + +task generateVersion() { + group = 'Build' + description = 'Generate project version' + + doLast { + def version = versionDetails() + def resourcesDir = sourceSets.main.output.resourcesDir + new File(resourcesDir, "version.properties").text = [ + "# AUTOMATICALLY GENERATED", + "version.app=$project.version", + "version.commit=${version.gitHash}", + "version.tag=${version.lastTag}", + "version.date=${DateTimeFormatter.ISO_LOCAL_DATE_TIME.withZone(ZoneId.of('UTC')).format(Instant.now().truncatedTo(ChronoUnit.SECONDS))} UTC" + ].join("\n") + + } } \ No newline at end of file diff --git a/src/main/kotlin/io/emeraldpay/dshackle/DshackleEnvironment.kt b/src/main/kotlin/io/emeraldpay/dshackle/DshackleEnvironment.kt index c8d6b200..a5d782a3 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/DshackleEnvironment.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/DshackleEnvironment.kt @@ -20,8 +20,10 @@ import org.springframework.beans.factory.config.YamlPropertiesFactoryBean import org.springframework.core.env.* import org.springframework.core.io.FileSystemResource import org.springframework.core.io.Resource +import org.springframework.core.io.support.ResourcePropertySource import java.io.File import java.util.* +import javax.annotation.PostConstruct const val DEFAULT_CONFIG = "/etc/dshackle/dshackle.yaml" const val LOCAL_CONFIG = "./dshackle.yaml" @@ -32,10 +34,10 @@ open class DshackleEnvironment: StandardEnvironment() { private val log = LoggerFactory.getLogger(DshackleEnvironment::class.java) } - override fun customizePropertySources(propertySources: MutablePropertySources) { super.customizePropertySources(propertySources) propertySources.addLast(mainConfig()) + propertySources.addLast(ResourcePropertySource("version.properties")) } open fun mainConfig(): PropertySource<*> { @@ -48,7 +50,6 @@ open class DshackleEnvironment: StandardEnvironment() { } } target = target.normalize() - log.info("Load configuration from: ${target.absolutePath}") val loadedProperties = this.loadYaml(FileSystemResource(target)) loadedProperties["configPath"] = target.absolutePath return PropertiesPropertySource("mainConfig", loadedProperties) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/Starter.kt b/src/main/kotlin/io/emeraldpay/dshackle/Starter.kt index 525d6eaf..90ea7b9c 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/Starter.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/Starter.kt @@ -16,9 +16,11 @@ package io.emeraldpay.dshackle import org.slf4j.LoggerFactory +import org.springframework.boot.ResourceBanner import org.springframework.boot.SpringApplication import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.context.annotation.Import +import org.springframework.core.io.ClassPathResource @SpringBootApplication(scanBasePackages = [ "io.emeraldpay.dshackle" ]) @Import(Config::class) @@ -29,5 +31,6 @@ private val log = LoggerFactory.getLogger(Starter::class.java) fun main(args: Array) { val app = SpringApplication(Starter::class.java) app.setEnvironment(DshackleEnvironment()) + app.setBanner(ResourceBanner(ClassPathResource("banner.txt"))) app.run(*args) } \ No newline at end of file diff --git a/src/main/resources/banner.txt b/src/main/resources/banner.txt new file mode 100644 index 00000000..a52dbfaa --- /dev/null +++ b/src/main/resources/banner.txt @@ -0,0 +1,9 @@ + _ _ __ _ _ _ _ + | | | | / /| | | | | | | | + ___ _ __ ___ ___ _ __ __ _| | __| | / /_| |___| |__ __ _ ___| | _| | ___ + / _ \ '_ ` _ \ / _ \ '__/ _` | |/ _` | / / _` / __| '_ \ / _` |/ __| |/ / |/ _ \ + | __/ | | | | | __/ | | (_| | | (_| |/ / (_| \__ \ | | | (_| | (__| <| | __/ + \___|_| |_| |_|\___|_| \__,_|_|\__,_/_/ \__,_|___/_| |_|\__,_|\___|_|\_\_|\___| + Emerald Dshackle - Smart Load Balancer for Blockchain API + https://github.com/emeraldpay/dshackle + v${version.app} built from ${version.commit} on ${version.date}