RE: Using Klaros with Jenkins Pipeline | nginx reverse proxy problems

Maximilian Schumann, modified 2 Months ago.

Using Klaros with Jenkins Pipeline | nginx reverse proxy problems

Youngling Posts: 3 Join Date: 9/30/22 Recent Posts
Hello, I am currently evaluating, through the free version, whether Klaros TMS is a good fit for us. I encountered two roadblocks.

We do import projects from Gitea through this Jenkins plugin https://plugins.jenkins.io/gitea/, which means we either have our projcts in Organization folders or Multibranch Pipelines. I could only find information on how to use the Jenkins plugin with freestyle projects (which is rather easy), but this does not suit our workflow.

​​​​​​​Is it possible to either use specific commands (which your plugin may offer) in a pipeline script or do we need to resort to curl (https://www.klaros-testmanagement.com/files/4.12.7/doc/html/User-Manual.Import-Export.html#User-Manual.Import-Export.TestResultImport 12.5.2), to upload test results from Jenkins to Klaros? Just for clarity, using curl should not be a problem, but I am curious.

Also, I have some problems with my reverse proxy setup. Both the reverse proxy (nginx) and Klaros run in a Docker container and are in the same virtual network (they can see each other). I have set the root URL of Klaros to http://nginx/tms/, however, Klaros always redirects to wrong pages, starting on the login page, to http://localhost/pages/login.seam instead of http://localhost/tms/pages/login.seam when connecing to http://localhost/tms/.
​​​​​​​I set Klaros to http://nginx/tms/ instead of http://localhost/tms/, because Klaros, as it is running in a container, has the 'wrong' localhost and nginx is exposed to port 80 on the host machine. When using Klaros normally with an exposed port, it works as it should.
This is my nginx config (in http):
​​​​​​​      location /tms/ {
          proxy_set_header Host $host;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection "upgrade";
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Scheme $scheme;
 
          proxy_pass http://tms:18080/;
      }

​​​​​​​When setting the new root URL, why does Klaros even need to be able to connect to the new server? Why isn't it possible to just set it (as other services, such as gitea and Jenkins do it) without this check?
thumbnail
Torsten Stolpmann, modified 2 Months ago.

RE: Using Klaros with Jenkins Pipeline | nginx reverse proxy problems

Jedi Council Member Posts: 731 Join Date: 2/12/09 Recent Posts
Hello Maximilian,

Your assumption is correct, the Jenkins plugin is currently not supporting pipeline scripts.

We are  aware that this is a nice addition to the plugin, but as said you can always fall back to curl invocation.

Please feel free to add a feature request at https://www.jenkins.io/participate/report-issue/redirect/#16030 to let others know.
If you plan to work on implementing this feature, we gladly accept well tested pull requests at https://github.com/jenkinsci/klaros-testmanagement-plugin and will support you if you get stuck.

Regarding the reverse proxy, there are three points to consider:

Firstly, being a JavaEE Web-Archive the Klaros application is expecting to be running under a fixed context path inside the Tomcat application server.
Per default this is the Root context (/). This is currently not configurable in the Dockerfile (see https://github.com/klaros-testmanagement/klaros-docker/blob/master/ApacheDerby/Dockerfile, line 63).

If you like to see this configurable, please raise a feature request at https://github.com/klaros-testmanagement/klaros-docker/issues. Again a pull request is welcome.

Secondly, you will not be able to map a non-root context (/tms) to a root context or vice versa via a reverse proxy. There are many entries on StackOverflow explaining this problem, e.g. https://stackoverflow.com/questions/71126553/removing-tomcat-application-context-from-url-using-apache-httpd-reverse-proxy.

Thirdly, if using a reverse proxy, please do not forget to set a correct application URL on the Configure / System / Miscellaneous page in Klaros (See https://www.klaros-testmanagement.com/files/doc/html/User-Manual.Configure.Main-GeneralSettings.html#User-Manual.Configure.Main-GeneralSettings.Miscellaneous).

So I think  the easiest solution for you would be to configure Klaros at the root context in your Nginx configuration.

Please let me know if that works for you. We gladly provide additional information if required.

Regards,

Torsten
Maximilian Schumann, modified 2 Months ago.

RE: Using Klaros with Jenkins Pipeline | nginx reverse proxy problems

Youngling Posts: 3 Join Date: 9/30/22 Recent Posts
Hello Torsten,

thank you for your fast answer.

Since curl works fine and additions to the Jenkins plugin would just be some sugar, I wouldn't deem it necessary to add it. I was just being curious.

Regarding, nginx, I am sorry, but I do not quite understand what you are saying.
My (wish) setup is as follows:
​​​​​​​https://localhost -> nginx itself
https://locahost/tms/ -> Klaros TMS
https://localhost/jenkins/ -> Jenkins (which works)
... etc.

I don't understand your first two points. The person in your Stackoverflow thread wanted to map <proxy domain>/app1/ to 92.168.1.123:9101/app1/. That is not what I want (I suppose).

Since I want to access Klaros via the reverse proxy and Klaros should not be accessible through the same network in which nginx is accessible through (meaning nginx has two virtual interfaces; one to the host and another to the network for services such as Jenkins and Klaros), I cannot set Klaros' application URL to the real URL, as that would be https://localhost/tms/ and Klaros cannot access nginx at localhost, since both Klaros and nginx run in Docker containers.
Other services just 'believe' the set URL is correct and do not check themselves whether there is a host with this URL, which is how I made other services work. Setting the appliation URL to http://nginx/tms (as Klaros' container can access this URL) does not work.

Regards,
Maximilian
thumbnail
Torsten Stolpmann, modified 2 Months ago.

RE: Using Klaros with Jenkins Pipeline | nginx reverse proxy problems

Jedi Council Member Posts: 731 Join Date: 2/12/09 Recent Posts
Hello Maximilian,

ok, let me add some context to the nginx related answers:

The Klaros docker image is designed to run the application at the root context (/), without the 'tms' path you are trying to map it to.
If you want a reverse proxy setup to 'tms', your Klaros docker container must support the application at that path. This can be done by changing the line

&& mv /root/klaros-testmanagement/webapps/klaros-web.war \
/root/klaros-testmanagement/webapps/ROOT.war

to 

&& mv /root/klaros-testmanagement/webapps/klaros-web.war \
/root/klaros-testmanagement/webapps/tms.war

in your docker file. After this change, the Klaros Application will be reachable at /tms in the Klaros container. Thus your nginx can map https://localhost/tms/ to the /tms context in the klaros container.

Of course it would be better to control the context path via a Docker environment setting instead of hardcoding it to ROOT.war as it currently is implemented.

Does that answer your question fully?

Regards,

Torsten
Maximilian Schumann, modified 2 Months ago.

RE: Using Klaros with Jenkins Pipeline | nginx reverse proxy problems

Youngling Posts: 3 Join Date: 9/30/22 Recent Posts
Hello Torsten,

again, thank you very much for your fast and helpful answers.

​​​​​​​I changed the path in the Dockerfile, made slight adjustments to my nginx config, and it is working now. Again, thank you very much.

Regards,
​​​​​​​Maximilian