-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(runtime-env): remove dependency on dockerize for cross-plattform …
…support
- Loading branch information
1 parent
b982af4
commit 6a7408a
Showing
10 changed files
with
224 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,16 @@ | ||
FROM scratch | ||
FROM alpine AS dockerize | ||
ENV DOCKERIZE_VERSION=v0.6.1 | ||
RUN apk add --no-cache wget ca-certificates && \ | ||
cd /tmp && \ | ||
wget -q https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz && \ | ||
tar -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz && \ | ||
rm -f dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz | ||
|
||
FROM maven:3.6.3-jdk-13 as java-entrypoint | ||
FROM maven:3.9.6-eclipse-temurin-17 as java-entrypoint | ||
WORKDIR /root | ||
COPY entrypoint ./ | ||
RUN mvn -T 1C package | ||
|
||
FROM tomcat:9.0.33-jdk13-openjdk-oracle | ||
FROM tomcat:10.1.19-jdk17-temurin-jammy | ||
LABEL maintainer="Neoskop DevOps <[email protected]>" | ||
|
||
# Setup dockerize | ||
COPY --from=dockerize /tmp/dockerize /usr/local/bin | ||
|
||
# Setup custom entrypoint | ||
COPY --from=java-entrypoint /root/target/docker-entrypoint.jar /usr/local/bin | ||
|
||
# Setup Tomcat config template | ||
RUN mkdir -p $CATALINA_HOME/conf/Catalina/localhost | ||
COPY context.xml.tmpl $CATALINA_HOME/conf/Catalina/localhost/ROOT.xml.tmpl | ||
|
||
# Overwrite server.xml | ||
COPY server.xml $CATALINA_HOME/conf/ | ||
|
@@ -52,9 +39,8 @@ RUN mkdir -p /home/tomcat/light-modules | |
# Set workdir | ||
WORKDIR /home/tomcat | ||
|
||
# Expose port 8080 for http access and 5005 for debugging | ||
# Expose port 8080 for http access and 5005 for debugging | ||
EXPOSE 8080 5005 | ||
|
||
CMD ["/usr/local/bin/run.sh"] | ||
VOLUME [ "/home/tomcat/magnolia_tmp/repositories" ] | ||
ENTRYPOINT ["dockerize", "-template", "/usr/local/tomcat/conf/Catalina/localhost/ROOT.xml.tmpl:/usr/local/tomcat/conf/Catalina/localhost/ROOT.xml"] | ||
VOLUME [ "/home/tomcat/magnolia_tmp/repositories" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
2 changes: 2 additions & 0 deletions
2
images/runtime-env/build/entrypoint/src/main/java/de/neoskop/DockerEntrypoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
package de.neoskop; | ||
|
||
import de.neoskop.service.ContextSetupService; | ||
import de.neoskop.service.WaitOnMySQLService; | ||
|
||
public class DockerEntrypoint { | ||
public static void main(String[] args) { | ||
ContextSetupService.setupContext(); | ||
WaitOnMySQLService.waitForAllConnections(); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
images/runtime-env/build/entrypoint/src/main/java/de/neoskop/model/Datasource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package de.neoskop.model; | ||
|
||
import org.apache.logging.log4j.Logger; | ||
import org.apache.logging.log4j.LogManager; | ||
|
||
public class Datasource { | ||
private static final Logger logger = LogManager.getLogger(Datasource.class); | ||
|
||
public final String name; | ||
public final String host; | ||
public final String username; | ||
public final String password; | ||
public final String database; | ||
public final String port; | ||
public final boolean useSsl; | ||
public final String trustStore; | ||
public final String trustStorePassword; | ||
public final String enabledTLSProtocols; | ||
|
||
public Datasource(String name, String host, String username, String password, String database, String port, | ||
boolean useSsl, | ||
String trustStore, String trustStorePassword, String enabledTLSProtocols) { | ||
this.name = name; | ||
this.host = host; | ||
this.username = username; | ||
this.password = password; | ||
this.database = database; | ||
this.port = port; | ||
this.useSsl = useSsl; | ||
this.trustStore = trustStore; | ||
this.trustStorePassword = trustStorePassword; | ||
this.enabledTLSProtocols = enabledTLSProtocols; | ||
} | ||
|
||
public String getConnectionUrl() { | ||
final StringBuilder sb = new StringBuilder("jdbc:mysql://"); | ||
sb.append(host); | ||
sb.append(":"); | ||
sb.append(port); | ||
sb.append("/"); | ||
sb.append(database); | ||
sb.append("?user="); | ||
sb.append(username); | ||
sb.append("&password="); | ||
sb.append(password); | ||
sb.append("&useSSL="); | ||
sb.append(useSsl); | ||
|
||
if (trustStore != null) { | ||
sb.append("&trustCertificateKeyStoreUrl=file://"); | ||
sb.append(trustStore); | ||
sb.append("&trustCertificateKeyStorePassword="); | ||
sb.append(trustStorePassword); | ||
} | ||
|
||
if (enabledTLSProtocols != null) { | ||
sb.append("&enabledTLSProtocols="); | ||
sb.append(enabledTLSProtocols); | ||
} | ||
|
||
logger.debug("Connection URL: " + sb.toString()); | ||
return sb.toString(); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...es/runtime-env/build/entrypoint/src/main/java/de/neoskop/service/ContextSetupService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package de.neoskop.service; | ||
|
||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
import java.util.List; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
import de.neoskop.model.Datasource; | ||
|
||
public class ContextSetupService { | ||
private static final Logger LOGGER = LogManager.getLogger(ContextSetupService.class); | ||
private static final String CATALINA_HOME = System.getenv("CATALINA_HOME"); | ||
private static final String MAGNOLIA_CONFIG = System.getenv("MAGNOLIA_CONFIG"); | ||
|
||
public static void setupContext() { | ||
File contextFile = new File(CATALINA_HOME + "/conf/Catalina/localhost/ROOT.xml"); | ||
try (PrintWriter writer = new PrintWriter(new FileWriter(contextFile))) { | ||
writer.println("<?xml version='1.0' encoding='utf-8'?>"); | ||
writer.println("<Context>"); | ||
|
||
writer.println(" <Manager pathname=\"\" />"); | ||
writer.println(" <WatchedResource>WEB-INF/web.xml</WatchedResource>"); | ||
writer.println(" <Resources cachingAllowed=\"true\" cacheMaxSize=\"100000\" />"); | ||
writer.println(" <CookieProcessor sameSiteCookies=\"strict\" />"); | ||
writer.println(" <JarScanner scanClassPath=\"false\" />"); | ||
|
||
if (MAGNOLIA_CONFIG != null) { | ||
writer.printf( | ||
" <Parameter name=\"magnolia.initialization.file\" value=\"WEB-INF/config/%s/magnolia.properties,WEB-INF/config/default/magnolia.properties,WEB-INF/config/magnolia.properties\" override=\"false\" />\n", | ||
MAGNOLIA_CONFIG); | ||
} | ||
|
||
final List<Datasource> datasources = DatasourceParserService.getDatasources(); | ||
|
||
if (datasources != null) { | ||
datasources.stream().forEach(datasource -> { | ||
writer.printf( | ||
" <Resource name=\"jdbc/%s\" auth=\"Container\" type=\"javax.sql.DataSource\" maxTotal=\"100\" maxIdle=\"30\" maxWaitMillis=\"10000\" url=\"%s", | ||
datasource.name, datasource.getConnectionUrl()); | ||
writer.println( | ||
"\" driverClassName=\"com.mysql.cj.jdbc.Driver\" validationQuery=\"SELECT 1\" testOnBorrow=\"true\" />"); | ||
}); | ||
} | ||
|
||
writer.println("</Context>"); | ||
} catch (IOException e) { | ||
LOGGER.error(e.getMessage()); | ||
} | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...untime-env/build/entrypoint/src/main/java/de/neoskop/service/DatasourceParserService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package de.neoskop.service; | ||
|
||
import com.google.gson.JsonArray; | ||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonParser; | ||
import de.neoskop.model.Datasource; | ||
|
||
import java.net.URLEncoder; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.List; | ||
import java.util.stream.StreamSupport; | ||
|
||
class DatasourceParserService { | ||
public static List<Datasource> getDatasources() { | ||
final String json = System.getenv("DATASOURCES"); | ||
|
||
if (json == null || json.equals("")) { | ||
return null; | ||
} | ||
|
||
final JsonObject jsonObject = JsonParser.parseString(json).getAsJsonObject(); | ||
final JsonArray datasources = jsonObject.get("datasources").getAsJsonArray(); | ||
|
||
return StreamSupport.stream(datasources.spliterator(), false).map(JsonElement::getAsJsonObject) | ||
.map(datasource -> { | ||
final String name = getStringWithDefault(datasource, "name", ""); | ||
final String host = getStringWithDefault(datasource, "host", ""); | ||
final String username = getStringWithDefault(datasource, "username", "root"); | ||
final String password = getStringWithDefault(datasource, "password", ""); | ||
final String database = getStringWithDefault(datasource, "database", "mysql"); | ||
final String port = getStringWithDefault(datasource, "port", "3306"); | ||
final boolean useSsl = getBooleanWithDefault(datasource, "useSsl", false); | ||
final String trustStore = getStringWithDefault(datasource, "trustStore", null, false); | ||
final String trustStorePassword = getStringWithDefault(datasource, "trustStorePassword", | ||
"changeit"); | ||
final String enabledTLSProtocols = getStringWithDefault(datasource, "enabledTLSProtocols", null); | ||
return new Datasource(name, host, username, password, database, port, useSsl, trustStore, | ||
trustStorePassword, enabledTLSProtocols); | ||
}).toList(); | ||
} | ||
|
||
private static String getStringWithDefault(JsonObject object, String property, String defaultValue) { | ||
return getStringWithDefault(object, property, defaultValue, true); | ||
} | ||
|
||
private static String getStringWithDefault(JsonObject object, String property, String defaultValue, | ||
boolean urlEncode) { | ||
if (object.has(property)) { | ||
final String value = object.get(property).getAsString(); | ||
|
||
if (urlEncode) { | ||
return URLEncoder.encode(value, StandardCharsets.UTF_8); | ||
} else { | ||
return value; | ||
} | ||
} | ||
|
||
return defaultValue; | ||
} | ||
|
||
private static boolean getBooleanWithDefault(JsonObject object, String property, boolean defaultValue) { | ||
if (object.has(property)) { | ||
return object.get(property).getAsBoolean(); | ||
} | ||
|
||
return defaultValue; | ||
} | ||
} |
Oops, something went wrong.