Fabric maven plugin offers a wide variety of deployment
options for Jboss Fuse. This article explores the deployment method pertaining
to modifying the profiles on the Fuse profile GIT.
The two commands which we use to deploy the code in this
article are fabric8:zip and fabric8: branch. Documentation on the plugin’s can
be found here
.
Scenario:
An enterprise project has the below bundles divided in to
two profiles.
Common : DBCP bundle and MQSql Connector
Web Module : Has Business Related bundles, for e.g., Let us
say
·
mvn:com.sundar.fabric8/webbackend/0.0.1-SNAPSHOT
·
mvn:com.sundar.fabric8/webfrontend/0.0.1-SNAPSHOT
·
mvn:com.sundar.fabric8/soapservices/0.0.1-SNAPSHOT
The goal is to generate a profile using fabric8:zip such
that all the bundles from common are written to a profile common and the three
bundles under the web module are written to web module profile.
Creating Profile Zips
- Create two modules common and web module with any packaging mode you wish (except pom), the main goal here is to generate profile zip files.
- Modify the parent pom as below.
- The distribution management section of the pom is needed. I have used a local repository for the example sake , it can be modified accordingly to the needs of the project.
- In traditional fabric8:zip usage , the fabric8:zip plugin will be associated in the actual bundle builds and thus create a one-one to mapping for a profile and a bundle.
- In this example the project which defines the fabric8:zip goal is marked to be ignore using the <includeArtifact> tag of the fabric8:zip goal which will then not write the project in to the profile created.
- Now edit the common module pom to reflect as below.
- Profile tag in the properties will be used to create the name of the profile.
- ParentProfiles are mentioned if there is any associated parents for the profiles needed. (common examples are CXF projects might need to be associated with feature-cxf profile).
- Bundles tag is where all the maven co-ordinates for the bundles and packages which go in to this project are mentioned separated by a space. The common profile in our example needed to have DBCP And MYSQL connectors, so these are added under the bundles tag.
- Features tag is a place-holder in case any feature need to be added to the tag separated by spaces.
- Edit the web module pom to reflect as below
- Now run the fabric8:zip command on the parent project , you should see that the project zips are created individually and aggregated in to the parent target directory
- You can run the mvn install command to automatically zip the profiles and deploy them to the locations specified in the distributionManagement part of the pom.
The generated profile will look as below
Creating the
Project to Deploy the profile to the Git
Once the
profiles are created and installed to a accessible repository, we can now
create the fabric8:branch plugin based
project to push these profiles to the repository.
- Create a project camel-fabric-deployment and edit the pom as below
- The distribution management section needs to point to the same repository where the profile zip files have been installed for the dependencies to be picked up properly.
- Add all the profiles, created in the earlier step as dependencies to the project. Observe the classifier and type fields provided to specify the profiles.
- Provide the branch name as the latest version .
- Provide the oldBranchName as the current version in the git.
- PushOnSuccess will determine if the repository needs to be updated on the successful compile or if it has not to be pushed.
We can add the configuration files to the profile within this framework by adding the profileConfigDir to the fabric8:zip goal configurations. The default value for this property is src/main/fabric8 , where in all the configuration files stored in this directory will be copied in to the zip file and subsequently pushed on to the profile via fabric8:branch goal.
We can even
have environment wise files created in each directory and over-ride the value
of the profileConfigDir using the system variables. E.g.,
src/main/fabric8/${environment} and then run the command
Mvn –Denvironment=dev install
To generate the profile zip with only the files under the
directory dev to move to the profile. This gives us a cleaner way of managing
the property values from environment to environment.
Conclusion: Using the configuration properties provided by
the fabric8 maven plugin we can tweak this deployment approach as needed by our
environment. This approach has a pit-fall that the json file which describes
the dependencies of each project (bundle), which generally gets created by the
fabric8: zip goal will not be created. The ignoreArtifact property set to true
will over-ride this functionality. Generally depending upon the setup of your project,
this way can be safely adopted in to projects running fuse on ensemble in a
common set-up.
References: Thanks to Richard Stroop ,for clarifying my queries while working on the project.
No comments:
Post a Comment