Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Externalize configurations Example #181

Open
hendratommy opened this issue Dec 29, 2020 · 9 comments
Open

Externalize configurations Example #181

hendratommy opened this issue Dec 29, 2020 · 9 comments

Comments

@hendratommy
Copy link

How to externalize configurations? Like for example, in persistence.xml, I need to set the jndi data source name and hibernate.hbm2ddl.auto differently in my local, staging and prod.

@jfdenise
Copy link
Collaborator

jfdenise commented Jan 5, 2021

@hendratommy , is it something that you are already achieving with WildFly (without using bootable JAR)?

It would be interesting to see how you are doing it. If that is based on custom JBoss modules (as we can see there: https://www.java2novice.com/jboss/external-property-in-classpath/), that is something that you could mimic with bootable JAR by defining different maven profiles and using the capability to copy extra content inside a bootable JAR.

Perhaps a simpler solution would be to have each maven profile to contain resources configured differently. So, for example, a different persistence.xml file per profile.

@hendratommy
Copy link
Author

hendratommy commented Jan 5, 2021

@jfdenise No, I haven't done it yet.
I was thinking to use environment variable since the datasource layer is also use environment variable. Looking at this link seems like this feasible in standard WildFly.

@jfdenise
Copy link
Collaborator

jfdenise commented Jan 5, 2021

That seems interesting, please keep us posted with your result. We could then create a new example to cover your use-case. Thank-you.

@hendratommy
Copy link
Author

hendratommy commented Jan 6, 2021

Hi,

It's working, I made small POC using bootable JAR to configure persistence.xml to use environment variables by adding ee layer and use cli to configure it.
Here is the repo hendratommy/wf-articles.

However it is not what I'm expecting when working bootable jar, I was expecting something similar to Spring Boot.

@jfdenise
Copy link
Collaborator

jfdenise commented Jan 6, 2021

@hendratommy , thank-you, could you point me to the workflow/approach you would have preferred? Thank-you.

@hendratommy
Copy link
Author

I think Spring-Boot configuration is great way to configure our application. Our configuration basically all reside in single file src/main/resources/application.yml which we can fill with default values. These configuration value is overridable at runtime either by supplying environment variables or by putting config/application.yml in the same folder with the jar file. And we can also have el expression inside the config explicitly to lookup the values.

@jfdenise
Copy link
Collaborator

jfdenise commented Jan 8, 2021

@hendratommy , thank-you. I added your use-case to the JIRA that tracks support for yaml config: https://issues.redhat.com/browse/WFLY-13978

@codylerum
Copy link

Currently I do this with maven profiles and then resource filtering

Maven Profile

<profile>
	<id>sandbox</id>
	<activation>
		<activeByDefault>false</activeByDefault>
	</activation>
	<properties>
		<applicationMode>SANDBOX</applicationMode>
		<applicationVersion>${project.version}</applicationVersion>
		<applicationRootPath>/var/sandbox/</applicationRootPath>
		<datasource_JNDI_Name>java:jboss/datasources/PORTAL_DS</datasource_JNDI_Name>
		<hibernate.dialect>MySQL57InnoDB</hibernate.dialect>
		<hibernate.ddl_mode>create</hibernate.ddl_mode>
	</properties>
</profile>

Persistence.xml

<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
		xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd" version="2.1">
	<persistence-unit name="primary" transaction-type="JTA">
		<jta-data-source>${datasource_JNDI_Name}</jta-data-source>
		<properties>
			<property name="hibernate.dialect" value="${hibernate.dialect}"/>
			<property name="hibernate.hbm2ddl.auto" value="${hibernate.ddl_mode}"/>
		</properties>
	</persistence-unit>
</persistence>

@jfdenise
Copy link
Collaborator

@codylerum @hendratommy , FYI, using WF23 you can excute CLI script to adjust your configuration at runtime.
We have an example that has been evolved to showcase the feature: https://github.com/wildfly-extras/wildfly-jar-maven-plugin/tree/master/examples/authentication
It could open new possibilities in your context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants