Centralized versionning, and web server ressources cache fooling
This commit is contained in:
@@ -7,7 +7,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.jeudego.pairgoth</groupId>
|
<groupId>org.jeudego.pairgoth</groupId>
|
||||||
<artifactId>engine-parent</artifactId>
|
<artifactId>engine-parent</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>0.2-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>api-webapp</artifactId>
|
<artifactId>api-webapp</artifactId>
|
||||||
|
|
||||||
@@ -67,7 +67,7 @@
|
|||||||
</httpConnector>
|
</httpConnector>
|
||||||
<systemProperties>
|
<systemProperties>
|
||||||
<pairgoth.env>${pairgoth.env}</pairgoth.env>
|
<pairgoth.env>${pairgoth.env}</pairgoth.env>
|
||||||
<pairgoth.version>${project.version}</pairgoth.version>
|
<pairgoth.version>${pairgoth.version}</pairgoth.version>
|
||||||
<pairgoth.api.external.url>${pairgoth.api.external.url}</pairgoth.api.external.url>
|
<pairgoth.api.external.url>${pairgoth.api.external.url}</pairgoth.api.external.url>
|
||||||
<pairgoth.webapp.external.url>${pairgoth.webapp.external.url}</pairgoth.webapp.external.url>
|
<pairgoth.webapp.external.url>${pairgoth.webapp.external.url}</pairgoth.webapp.external.url>
|
||||||
<pairgoth.store>${pairgoth.store}</pairgoth.store>
|
<pairgoth.store>${pairgoth.store}</pairgoth.store>
|
||||||
|
@@ -62,8 +62,7 @@ class WebappManager : ServletContextListener, ServletContextAttributeListener, H
|
|||||||
properties[(key as String).removePrefix(PAIRGOTH_PROPERTIES_PREFIX)] = value
|
properties[(key as String).removePrefix(PAIRGOTH_PROPERTIES_PREFIX)] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
val env = properties.getProperty("env")
|
logger.info("pairgoth server ${properties["version"]} with profile ${properties["env"]}")
|
||||||
logger.info("Using profile $env", )
|
|
||||||
|
|
||||||
// set system user agent string to empty string
|
// set system user agent string to empty string
|
||||||
System.setProperty("http.agent", "")
|
System.setProperty("http.agent", "")
|
||||||
|
@@ -4,7 +4,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.jeudego.pairgoth</groupId>
|
<groupId>org.jeudego.pairgoth</groupId>
|
||||||
<artifactId>engine-parent</artifactId>
|
<artifactId>engine-parent</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>0.2-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>application</artifactId>
|
<artifactId>application</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
3
pom.xml
3
pom.xml
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
<groupId>org.jeudego.pairgoth</groupId>
|
<groupId>org.jeudego.pairgoth</groupId>
|
||||||
<artifactId>engine-parent</artifactId>
|
<artifactId>engine-parent</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>0.2-SNAPSHOT</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<!-- CB: Temporary add my repository, while waiting for SSE Java server module author to incorporate my PR or for me to fork it -->
|
<!-- CB: Temporary add my repository, while waiting for SSE Java server module author to incorporate my PR or for me to fork it -->
|
||||||
@@ -66,6 +66,7 @@
|
|||||||
|
|
||||||
<!-- pairgoth default properties -->
|
<!-- pairgoth default properties -->
|
||||||
<pairgoth.env>dev</pairgoth.env>
|
<pairgoth.env>dev</pairgoth.env>
|
||||||
|
<pairgoth.version>${project.version}</pairgoth.version>
|
||||||
<pairgoth.webapp.protocol>http</pairgoth.webapp.protocol>
|
<pairgoth.webapp.protocol>http</pairgoth.webapp.protocol>
|
||||||
<pairgoth.webapp.host>localhost</pairgoth.webapp.host>
|
<pairgoth.webapp.host>localhost</pairgoth.webapp.host>
|
||||||
<pairgoth.webapp.port>8080</pairgoth.webapp.port>
|
<pairgoth.webapp.port>8080</pairgoth.webapp.port>
|
||||||
|
@@ -7,7 +7,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.jeudego.pairgoth</groupId>
|
<groupId>org.jeudego.pairgoth</groupId>
|
||||||
<artifactId>engine-parent</artifactId>
|
<artifactId>engine-parent</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>0.2-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>view-webapp</artifactId>
|
<artifactId>view-webapp</artifactId>
|
||||||
|
|
||||||
@@ -84,6 +84,7 @@
|
|||||||
</httpConnector>
|
</httpConnector>
|
||||||
<systemProperties>
|
<systemProperties>
|
||||||
<pairgoth.env>${pairgoth.env}</pairgoth.env>
|
<pairgoth.env>${pairgoth.env}</pairgoth.env>
|
||||||
|
<pairgoth.version>${pairgoth.version}</pairgoth.version>
|
||||||
<pairgoth.api.external.url>${pairgoth.api.external.url}</pairgoth.api.external.url>
|
<pairgoth.api.external.url>${pairgoth.api.external.url}</pairgoth.api.external.url>
|
||||||
<pairgoth.webapp.external.url>${pairgoth.webapp.external.url}</pairgoth.webapp.external.url>
|
<pairgoth.webapp.external.url>${pairgoth.webapp.external.url}</pairgoth.webapp.external.url>
|
||||||
<pairgoth.store>${pairgoth.store}</pairgoth.store>
|
<pairgoth.store>${pairgoth.store}</pairgoth.store>
|
||||||
|
@@ -64,11 +64,11 @@ class WebappManager : ServletContextListener, ServletContextAttributeListener, H
|
|||||||
properties[(key as String).removePrefix(PAIRGOTH_PROPERTIES_PREFIX)] = value
|
properties[(key as String).removePrefix(PAIRGOTH_PROPERTIES_PREFIX)] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
val env = properties.getProperty("env")
|
logger.info("pairgoth server ${properties["version"]} with profile ${properties["env"]}")
|
||||||
logger.info("Using profile {}", )
|
|
||||||
|
|
||||||
// let the view be aware of the environment
|
// publish some properties to the webapp context; for easy access from the template
|
||||||
context.setAttribute("env", env)
|
context.setAttribute("env", properties["env"])
|
||||||
|
context.setAttribute("version", properties["version"] ?: "?")
|
||||||
|
|
||||||
// set system user agent string to empty string
|
// set system user agent string to empty string
|
||||||
System.setProperty("http.agent", "")
|
System.setProperty("http.agent", "")
|
||||||
|
@@ -60,7 +60,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="footer" class="horz flex">
|
<div id="footer" class="horz flex">
|
||||||
<div id="version">pairgoth v0.1</div>
|
<div id="version">pairgoth v$version</div>
|
||||||
<div id="contact"><a href="mailto:pairgoth@jeudego.org">contact</a></div>
|
<div id="contact"><a href="mailto:pairgoth@jeudego.org">contact</a></div>
|
||||||
</div>
|
</div>
|
||||||
<div id="feedback">
|
<div id="feedback">
|
||||||
@@ -81,13 +81,13 @@
|
|||||||
<script type="text/javascript" src="/lib/tablesort-5.4.0/sorts/tablesort.number.min.js"></script>
|
<script type="text/javascript" src="/lib/tablesort-5.4.0/sorts/tablesort.number.min.js"></script>
|
||||||
<link rel="stylesheet" href="/lib/tablesort-5.4.0/tablesort.css"/>
|
<link rel="stylesheet" href="/lib/tablesort-5.4.0/tablesort.css"/>
|
||||||
<script type="text/javascript" src="/lib/imaskjs-7.1.3/imask.min.js"></script>
|
<script type="text/javascript" src="/lib/imaskjs-7.1.3/imask.min.js"></script>
|
||||||
<script type="text/javascript" src="/js/api.js"></script>
|
<script type="text/javascript" src="/js/api.js?v=$version"></script>
|
||||||
<script type="text/javascript" src="/js/main.js"></script>
|
<script type="text/javascript" src="/js/main.js?v=$version"></script>
|
||||||
<script type="text/javascript" src="/js/domhelper.js"></script>
|
<script type="text/javascript" src="/js/domhelper.js?v=$version"></script>
|
||||||
<link rel="stylesheet" href="/lib/fork-awesome-1.2.0/fork-awesome.min.css"/>
|
<link rel="stylesheet" href="/lib/fork-awesome-1.2.0/fork-awesome.min.css"/>
|
||||||
<link rel="stylesheet" href="/css/main.css"/>
|
<link rel="stylesheet" href="/css/main.css?v=$version"/>
|
||||||
#if($css)
|
#if($css)
|
||||||
<link rel="stylesheet" href="$css"/>
|
<link rel="stylesheet" href="${css}?v=$version"/>
|
||||||
#end
|
#end
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
const lang = '${request.lang}';
|
const lang = '${request.lang}';
|
||||||
|
@@ -4,7 +4,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.jeudego.pairgoth</groupId>
|
<groupId>org.jeudego.pairgoth</groupId>
|
||||||
<artifactId>engine-parent</artifactId>
|
<artifactId>engine-parent</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>0.2-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>webserver</artifactId>
|
<artifactId>webserver</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
@@ -43,6 +43,8 @@ fun main(vararg args: String) {
|
|||||||
readProperties()
|
readProperties()
|
||||||
// extract war files from main archive
|
// extract war files from main archive
|
||||||
extractWarFiles()
|
extractWarFiles()
|
||||||
|
// publish properties as system properties
|
||||||
|
publishProperties()
|
||||||
// launch web server
|
// launch web server
|
||||||
launchServer()
|
launchServer()
|
||||||
} catch (t: Throwable) {
|
} catch (t: Throwable) {
|
||||||
@@ -52,7 +54,6 @@ fun main(vararg args: String) {
|
|||||||
|
|
||||||
private val tmp = System.getProperty("java.io.tmpdir")
|
private val tmp = System.getProperty("java.io.tmpdir")
|
||||||
private val webapps = Path.of("${tmp}/pairgoth/webapps")
|
private val webapps = Path.of("${tmp}/pairgoth/webapps")
|
||||||
private val version = "1.0-SNAPSHOT" // TODO CB
|
|
||||||
|
|
||||||
private fun cleanup() {
|
private fun cleanup() {
|
||||||
FileUtils.deleteDirectory(webapps.toFile())
|
FileUtils.deleteDirectory(webapps.toFile())
|
||||||
@@ -67,6 +68,9 @@ private fun readProperties() {
|
|||||||
if (properties.exists()) {
|
if (properties.exists()) {
|
||||||
serverProps.load(FileReader(properties))
|
serverProps.load(FileReader(properties))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun publishProperties() {
|
||||||
serverProps.entries.forEach { entry ->
|
serverProps.entries.forEach { entry ->
|
||||||
val property = entry.key as String
|
val property = entry.key as String
|
||||||
val value = entry.value as String
|
val value = entry.value as String
|
||||||
@@ -92,12 +96,24 @@ private fun extractWarFiles() {
|
|||||||
val webappsFolderURL = getResource("/META-INF/webapps") ?: throw Error("webapps not found")
|
val webappsFolderURL = getResource("/META-INF/webapps") ?: throw Error("webapps not found")
|
||||||
val jarConnection = webappsFolderURL.openConnection() as JarURLConnection
|
val jarConnection = webappsFolderURL.openConnection() as JarURLConnection
|
||||||
val jarFile: JarFile = jarConnection.jarFile
|
val jarFile: JarFile = jarConnection.jarFile
|
||||||
|
val extractVersion = Regex(".*?-(\\d+\\.\\d+(?:-[^.-]+)?).war")
|
||||||
|
var version: String? = null
|
||||||
jarFile.entries().toList().filter { entry ->
|
jarFile.entries().toList().filter { entry ->
|
||||||
entry.name.startsWith(jarConnection.entryName)
|
entry.name.startsWith(jarConnection.entryName)
|
||||||
}.forEach { entry ->
|
}.forEach { entry ->
|
||||||
if (!entry.isDirectory) {
|
if (!entry.isDirectory) {
|
||||||
|
val filename = entry.name.removePrefix("META-INF/webapps/")
|
||||||
|
val versionMatch = extractVersion.matchEntire(filename)
|
||||||
|
?: throw Error("Could not extract version from filename: $filename")
|
||||||
|
val entryVersion = versionMatch.groupValues[1]
|
||||||
|
if (version == null) {
|
||||||
|
version = entryVersion
|
||||||
|
serverProps["version"] = version
|
||||||
|
} else if (version != entryVersion) {
|
||||||
|
throw Error("Inconsistent versions found: $version and $entryVersion")
|
||||||
|
}
|
||||||
jarFile.getInputStream(entry).use { entryInputStream ->
|
jarFile.getInputStream(entry).use { entryInputStream ->
|
||||||
Files.copy(entryInputStream, webapps.resolve(entry.name.removePrefix("META-INF/webapps/")))
|
Files.copy(entryInputStream, webapps.resolve(filename))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -158,6 +174,7 @@ private fun launchServer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun createContext(webapp: String, contextPath: String) = WebAppContext().also { context ->
|
private fun createContext(webapp: String, contextPath: String) = WebAppContext().also { context ->
|
||||||
|
val version = serverProps["version"] ?: throw Error("version not found")
|
||||||
context.war = "$tmp/pairgoth/webapps/$webapp-webapp-$version.war"
|
context.war = "$tmp/pairgoth/webapps/$webapp-webapp-$version.war"
|
||||||
context.contextPath = contextPath
|
context.contextPath = contextPath
|
||||||
if (webapp == "api") {
|
if (webapp == "api") {
|
||||||
|
Reference in New Issue
Block a user