dockergitlab-ciapache-karafapache-servicemix

How to run Servicemix commands inside docker in Karaf console using deploy script?


Colleagues, it so happened that I am now using the servicemix 7.0 technology in one old project. There are several commands that I run manually.

build image servicemix docker build --no-cache -t servicemix-http:latest .

start container and copy data from local folder source and folder .m docker run --rm -it -v %cd%:/source -v %USERPROFILE%/.m2:/root/.m2 servicemix-http

start console servicemix and run command feature:repo-add file:/../source/source/transport/feature/target/http-feature.xml

run command feature:install http-feature

copy deploy files from local folder to deploy folder into servicemix docker cp /configs/. :/deploy

update image servicemix docker commit servicemix-http

Now I describe the gitlab-ci.yml for deployment. And the question concerns the servicemix commands that were launched from the karaf console. feature:repo-add feature:install Is there any way to script them?


Solution

  • If all you need is to install features from specific feature repositories on startup you can add the features and feature-repositories to /etc/org.apache.karaf.features.cfg.

    You can use ssh with private-key to pass commands to Apache karaf.

    ssh karaf@localhost -p 8101 -i ~/.ssh/karaf_private_key -- bundle:list
    

    You can also try running commands through Karaf_home/bin/client, albeit had no luck using it with Windows 10 ServiceMix 7.0.1 when I tried. It kept throwing me NullReferenceException so guessing my java installation is missing some security related configuration.

    Works well when running newer Karaf installations on docker though and can be used through docker exec as well.

    # Using password - (doesn't seem to be an option for servicemix)
    docker exec -it  karaf /opt/apache-karaf/bin/client -u karaf -p karaf -- bundle:list
    
    # Using private-key
    docker exec -it  karaf /opt/apache-karaf/bin/client -u karaf -k /keys/karaf_key -- bundle:list