Add external file to payara micro application classpath - docker

I'm using payara micro to run my war application. Because one of the services I need to access requires metro ws, I need to provide a wsit client file to the application.
When I add it inside the war, it works fine, but since I need this file to be different depending on the environment I'm deploying, I need to inject the correct one as an external dependency to the server and I only know the right one at deployment stage. Meanwhile I already created all the artifacts and the docker image.
How can I add this file to the application without opening the war adding it manually and re build the war? I'm looking for a solution like the external modules for wildly.
I tried the --addLibs but it requires a jar.

This problem was solved by putting the right file inside the image during the deploy stage. This way we use always the same filename, but different files for each environment.

Related

What is the best way to change application configurations in a CI environment

I am currently doing a POC on Jenkins pipeline to figure out how to configure my product in a CI environment. The requirements of the pipeline are:
Checkout code from SVN
Compile the program
Deploy to a predefined location on the server
Change DB configurations (& maybe even other configs not identified yet) to point to the appropriate DB
Execute the program
Execute QA process to validate the output
I am currently having difficulty in achieving Point 4 above. All DB-related configurations reside in a database.xml file per program & a program can connect to 1 or more DBs.
Given that developers are free to check-in any DB configurations, I would still like my CI environment to point to a predefined DB to test against. I am unsure on how to dynamically change these configuration files to achieve this.
Please let me know if there are standard methods that others are also using to achieve the same.
TIA
Some approaches:
Properties using Advanced Platforms
Use some web platform like :
zookeeper
http://www.therore.net/java/2015/05/03/distributed-configuration-with-zookeeper-curator-and-spring-cloud-config.html
Spring Cloud
https://www.baeldung.com/spring-cloud-configuration
This is a java spring framework functionality in wich you can create properties file with configurations and configure your applications to read them.
magi-properties-management
This is a java web system in which you can create environments and any key:value in each one. You just need configure your application in any language to read this values.
cyber-properties-management
This is a nodejs application that allows you to store properties files (.properties .yml or .json) and then just consume them as rest endpoint from your applications.
With this approaches , when a change of configurations is required, you just need update the value in the system and restart your application. It is even possible a hot reload in java applications.
Properties from Environment variables
You can export your key:value properties as environment vars before starting the application :
export DATABASE_HOST=10.100.200.300
export LOG_DIR_LOCATION=/logs
And read it after after the application has started:
Java >> System.getEnv("DATABASE_HOST");
node.js >> process.evn.LOG_DIR_LOCATION
php >> getenv('DATABASE_HOST')
Properties from SCM
Create some svn repositoty called development-configurations
Upload your database.xml with development values
In your application, put a database.xml with dummy values : localhost, etc
Create a jenkins job and put the environment as an argument.
In the same job download svn source code of your application.
download svn repository called $environment-configurations. $environment will be your argument
replace the database.xml inside of your application with database.xml of $environment-configurations repository.
Just create another repositories for testing, uat and production. Job must be receive environment as an argument to choose the right database.xml
Properties from Database
Modify your applications to read configurations from some database instead of xml file
Properties from File System
Modify your application to read an external database.xml instead of the database.xml inside of your source code. With this approach you just need put the database.xml in some path of your server and delete it from your application source code.
Note
You can use these approaches not only for backend apps. You can use them for frontends applications:
Devops Variable Substitution for Frontend js applications

Obtain the artifact directory path as a relative path for the Release process

We are working on the configuration process for the Continuous Integration for some projects, we are using TFS and now we have a problem with some releases definitions. We want to use the Web Deploy package created in the Build process for the Deployment.
So far the build definition that we have is following:
enter image description here
The path for the creation of the package is the default, so we are able to find it inside the artifact directory. But the problem is when we nee extract the files in the target folder for the website in the server.
The Release definition that we are using is:
enter image description here
In this part in the Download artifact phase the agent doing the release has access to the published files in the build process, so here we know where the .zip package is, and we can have the path using $(System.ArtifactsDirectory), but if we use Deploy IIS App task, as you can see we are connecting to the servers where we are doing the release and $(System.ArtifactsDirectory) give us the local address for the artifacts where the agents are configured, and the variable give the path like C:\agent_work\r1\a, where C is local for the agent, and the .zip file doesn't exist in that address. And we can't build a new path like \Myserver\$(System.ArtifactsDirectory).... , because $(System.ArtifactsDirectory) is an absolute path and as a result the whole path it is : \Myserver\C:\Myfolder....
We need other solution, we have considered in the build process create the package in a different folder, and in this case we always know where is the package, we aren't depending on the agent folders, and in this way we can use as Web Deploy Package path: \Myserver\packagefolder\file.zip, but we would like to use a different solution.
Is there any way to have the artifact folder with a relative path or something like this????
You could use Windows Machine File Copy task to copy the package file from agent to the servers where you are doing the release.
Use this task to copy application files and other artifacts such as
PowerShell scripts and PowerShell-DSC modules that are required to
install the application on Windows Machines. It uses RoboCopy, the
command-line utility built for fast copying of data.
You could use a temporary folder handling the package file on the agent. Such as Build.StagingDirectory. Build variables
Add a packagelocation such as /p:PackageLocation="$(Build.StagingDirectory)\\ in your MSbuild Arguments. Then copy the files from StagingDirectory to your local folder in remote server by using Windows Machine File Copy task.

Jar file or classes better for WAR file access

Our application is JSF2 deployed in weblogic10.3.4 as war , In Prod environment , in a war file which would be better , to keep our application files as "class" files or packaged it as jar file.
Thanks
Vijay
If you keep your classes in jar files within /WEB-INF/lib there would be no difference.
Your question is not much clear. I understood you are not sure about deploying your entire application (including its dependencies) in a WAR file versus deploying your application as a WAR plus a JAR containing some of your dependencies. Right?
If you follow the second approach (using a JAR), you have an additional advantage (or burden) of being able to deploy them separately. It is a tradeoff, you should take into account which approach is better for you: deploying a single file gives you a "one-step" deployment, but makes you deploy your web app every time you need to deploy changes only to one of your dependencies.

Grails + Tomcat6 + Multiple Instances + Shared Lib Folder

I've got a Tomcat6 server that runs multiple Instances for two separate grail apps.
When I compile my WAR file for deployment normally
run-app -Dgrails.env=production war test.war
It deploys correctly and everything works as it is suppose too.
The problem is, I don't want the JAR files included in my WAR.
So I use the following command line instead
run-app -Dgrails.env=production war test.war --nojars
Now when my grails app deploys (it doesn't) I get a java.lang.NoSuchMethodError
I have copied the lib folder (from my initial test.war) to the following locations
${catalina.base}/shared/lib
${catalina.home}/shared/lib
${catalina.home}/lib
None of these work.
My catalina.properties all point to the correct locations.
Any ideas?
A few ideas:
BuildConfig.groovy has inherits global, which has the app inherit all of the grails/plugins dependencies. If you change this, it may affect both your build and packaging - plus I have yet to encounter any documentation on what type of other things you can do with the inherits DSL
Grails deployment documentation suggests there is a way to customize which dependencies make it into the war file: http://grails.org/doc/latest/guide/17.%20Deployment.html
Event hooks give you access to provide a closure routine into various stages of the grails lifecycle. Can it strip out framework jars from the final war? Haven't tried that either - only using it to re-write various config files for additional envrionment configuration. However it does look like packaging events are exposed to this API:
http://grails.org/doc/latest/guide/4.%20The%20Command%20Line.html

Change Configurations after War Build

I have two configurations I need to change after building a prod war with grails 1.3.2. I know the project can be setup in ways to do this externally in the first place, but that's not an option at this moment.
1) Need to change environments.production.hibernate.default_schema defined in DataSource.groovy
2) Need to change environments.production.grails.serverURL defined in Config.groovy
Is there any way to edit the war or pass overriding arguments when running the war in JBoss?
If you want to change these properties in a production application with out redeployment your out of luck. Your only option is using external properties files which will require a rebuild and redeployment of the app. See the following link. http://www.comitservices.com/wp/?p=133

Resources