Deploying environment-dependant configuration to Apache Karaf - osgi

Is there a standard way of deploying environment-dependant cfg files to karaf? Let's say I have xyz.cfg file in 2 versions for Dev and QA. Do I need to create separate features for Dev and QA in this case?
Thanks!

Maybe there is a way with features. But I don't know how. We use the karaf-maven-plugin to build a customized karaf. In this case you may build one for Dev and one for QA. Here is a full description.
So hopefully this helps you a bit.

I think I found the solution for what I am looking for.
Karaf features support the provisioning of configuration files. See "Features configurations" and "Feature configuration files" section here:
https://karaf.apache.org/manual/latest/provisioning
All I had to do is to add a feature for each environment where I include only the configuration files required for that environment. Then for the deployment, I deploy both my bundles and the feature containing the configuration for the environment I am trying to deploy to.
Example:
<feature name="dev">
<configfile ...>
</feature>
<feature name="qa">
<configfile ...>
</feature>
Then, to install in dev:
repo-add my-repo
feature:install some-feature-containing-bundles
feature:install dev

Related

TeamCity docker registry " Cannot find the Docker Connection referenced from the Docker build feature"

I am trying to setup TeamCity 2019.2.2 for my home projects. The configuration works perfectly but at the beginning of every build it prints a error:
Cannot find the Docker Connection referenced from the Docker build feature, probably it was removed. Please update Docker build feature settings. Build will continue without logging in to Docker Registry
Project configurations
I have created a build template in the Root Project and that is the default configuration for the project. Connection to docker registry is configured also in Root Project. All the build steps and build features are also being configured in the template.
Solution attemps
I have reconfigured docker registry in the template and also reconfigured the build feature in specific projects - with no luck :(
Now I configured all the repository projects to use this configuration. everything works, building docker image and pushing the docker image.
Any help is appreciated.
I am answering my own question as I found the problem and solution. This may help others in future.
What happened: I had configured docker registry connection in project, then created the template. After that I found that I had login problem in old docker registry connection so I removed it and created a new connection. But the template configuration was not able to remove that config. So the template's build feature had 2 different docker registry one of which is non existent.
Solution: There is not straight forward solution. I had the go to the configuration folder of the teamcity server and update the template configuration manually. I just removed the reference of PROJECT_EXT_3 from the following configuration.
<parameters>
<param name="login2registry" value="PROJECT_EXT_3,PROJECT_EXT_5" />
<param name="loginCheckbox" value="on" />
</parameters>

Share Maven run configurations with other developers using Intellij IDEA

We have the following project setup: Maven, Eclipse, Subversion. Eclipse Launch configurations are in a separate docs folder next to the pom.xml. The launch configurations run something like mvn clean install -Pdev or mvn tomee:run -pl something-ear
The good thing is that a shared run configuration is picked up by the IDE and shown in the External Tools run commands. This way, every developer that checks out this project immediately has access to run the build.
We would like to have something similar using IntelliJ IDEA, but I haven't found a good equivalent. What I have considered so far:
Share run scripts
My first idea was to replace the launch configurations with run scripts. I just could not figure out how to have those run scripts run inside IntelliJ IDEA just the way a Maven goal would be executed.
Share IDEA project configuration
The IDEA project configuration (specifically .idea/runConfigurations) inside the checked out directory is not a good solution. We have (speaking one IDEA project with different IDEA modules depending on the task at hand: as a developer you might need multiple IDEA modules (and sub-modules) in the same IDEA project
An IDEA project consisting of the following modules is not something unusal
projectA/trunk
projectB/tags/1.2
projectC/branches/some-change
My preferred solution would remove all IDE-specific configuration from the repository and have some kind of run definitions either in the project folder or a folder next to the pom.xml that a developer can run from the command line or from her IDE of choice.
The optimal solution would let me define something like this in the pom:
<runConfigs>
<default>clean install</default>
<container>tomee:run -pl something-ear</container>
</runConfigs>
This configuration would then be picked up by the IDE and provided as a run or launch configuration to the developer.
Any ideas or suggestions?
Thank you very much!
My current approach is a hybrid solution:
No configuration in the separate modules
One IDEA project configuration with run configurations managed in VCS
The .idea/runConfigurations directory is versioned separately from the project sources. It contains commands with a working directory set relative to the PROJECT_DIR:
<MavenRunnerParameters>
…
<option name="workingDirPath" value="$PROJECT_DIR$/path/to/submodule" />
</MavenRunnerParameters>
When setting up a new project, the developer also checks out this folder and has a set of pre-configured launch configurations for all projects. The downsides are
All launch configurations are managed centrally instead of with the module
The IDEA project directory has a fixed location relative to the modules. If you set up another project, you will have to change the run configurations
The setup does not clearly state how changes to the launch configurations are shared with other developers

spring profile not activated on STS tc Server

I have a project with Spring profile
In my web.xml, i have
<context-param>
<param-name>spring.profiles.default</param-name>
<param-value>dev</param-value>
</context-param>
to set the default spring profile.
I build the maven project with
clean install -Dspring.profiles.active="prod"
Then, I choose the option Run As -> Run on Server to deploy the maven project to tc Server.
However, the active profile is still dev.
What is the correct way to activate a spring profile on tc Server
If you are running your app from with STS and the tc Server that comes with it, you can put the system property definition into the launch configuration of tc Server. Once you started up tc Server once, you can modify the lauch config via "Run Configurations...", select the one for Pivotal tc Server, go to the VM arguments and add the -Dspring.profiles.active=prod setting.
Since this is a runtime option, it doesn't have any effect while building the app via Maven (the clean install way you tried).
Configuring Tomcat
defining context param in web.xml – that breaks “one package for all environments” statement. I don’t recommend that
defining system property -Dspring.profiles.active=your-active-profile
I believe that defining system property is much better approach. So how to define system property for Tomcat? Over the internet i could find a lot of advices like “modify catalina.sh” because you will not find any configuration file for doing stuff like that. Modifying catalina.sh is a dirty unmaintable solution. There is a better way to do that.
Just create file setenv.sh in Tomcat’s bin directory with content:
JAVA_OPTS="$JAVA_OPTS -Dspring.profiles.active="prod"
and it will be loaded automatically during running catalina.sh start or run.
I don't know why the JAVA_OPTS method didn't work for me.
What does is adding spring.profiles.active=dev in /conf/catalina.properties

What is the correct URL to make available the FAB feature in karafe?

At http://fuse.fusesource.org/bundle/faq.html#How_do_I_enable_FAB_support_in_my_OSGi_container_, we are instructed to do:
features:addUrl mvn:org.fusesource.fuse/fuse-fuse/7.0.1.fuse-084/xml/features
features:install fuse-bundle
in karafe to enable FAB. This results in:
Could not add Feature Repository:
java.lang.RuntimeException: URL [mvn:org.fusesource.fuse/fuse-fuse/7.0.1.fuse-084/xml/features] could not be resolved.
Please verify that the feature repository URL is correct and that your network connection works fine.
Can anybody advise us as to what URL we should use and where to find such information on an ongoing basis? Also, where, more generally, is the official place to look for such documentation. I have not found RedHat's stewardship terribly helpful in that regard.
thanks
You need to add the maven repository to your Apache Karaf configuration file. See the etc directory, there is a file org.ops4j.pax.url.mvn.cfg where you add the fusesource repo where the FAB distribution is.
Notice that its much easier to use JBoss Fuse or Fuse ESB Enterprise, as they have FAB enabled out of the box.
The repo url is: http://repo.fusesource.com/nexus/content/repositories/releases
So in etc/org.ops4j.pax.url.mvn.cfg file you add this line to the repos in the bottom of the file:
http://repo.fusesource.com/nexus/content/repositories/releases#id=fusesource.release.repo, \

Generate a equinox environment and config by script (Ant or something) of deployed OSGI bundles

I am searching for a way to generate a run able equinox configuration of deployed OSGI bundles.
A build server deploys our OSGI bundles via maven and tycho-plugin and placed them in the m2 directory.
Now, the next step is to collect the bundles from the deployment directory and put them together in a equinox configuration and start up the container.
Collect the bundles and configure the equinox container manually is not the way I prefer so now I looking for a way to do this automatically via script.
There are solutions like ANT script?
Hoping for Help
Build a "product" (i.e. a fully self-contained OSGi runtime).
See the tycho docs in general [1] and esp. exercise 5 of the tycho tutorial [2] with solution [3]
[1] http://eclipse.org/tycho/documentation.php
[2] http://eclipsecon.org/sessions/building-eclipse-plugins-and-rcp-applications-tycho
[3] https://github.com/jsievers/tycho-demo/tree/master/exercises/Exercise_06_Solution
One thing you could do is generate an config.ini file which you can put in your configuration/ directory. The osgi.bundles entry in there allows you to specify what bundles to install and start, e.g.:
config.ini content:
osgi.bundles=org.eclipse.osgi.services#start, ../mydirectory/mybundle.jar#start
You may need to specify the configuration directory when launching equinox to ensure the config.ini is picked up, e.g.
java -jar plugins/org.eclipse.osgi_3.7.1.R37x_v20110808-1106.jar -configuration configuration
You can use https://github.com/sarod/equinox-config-builder to easily generate a config.ini from a plugins directory.

Resources