How to test Gitlab-ci Docker + Spring Boot + Testcontainers + Wkhtmltopdf - spring-boot

My question is regarding following problem:
I want to test the setup of my Wkhtmltopdf service structure
Therfore I want to use Gitlab-ci + Docker and Gitlab-Runners
The server framework I am using is Spring boot
I also have another Docker container which is also running a small web service making it accessible via REST to generate PDF files from urls.
For testing I want to use Testcontainers + DockerComposeContainer which is using a compose file defining my test database service and the PDF service.
My problem is the following:
I don't know which host to use for the url the PDF service is going to use for accessing the website on the spring boot service while running the test.
It perfectly works for the spring server to access database and and the PDF service. But I cannot make the PDF service request the provided web url for generating the PDF itself.
I've tried several approaches recommended on the web, like
Testcontainers.exposeHostPort
Domains
host.testcontainers.internal
And so on. Running the tests on my local machine don't seem to have any problems, since also docker default ips work as expected.
Please help, I cannot sleep, but I'll try now and I am willing to provide even more information when I'm back up again and at the computer.

Related

(How) Can I run more than one Spring Boot application on the same server and port?

I have a Spring Boot web application that I'd like to split up into about six separate applications; one would provide the homepage and login at endpoints under "/", and the others would each claim a subdirectory path ("/subsystem1", "/subsystem2", etc...). I have a pretty clear idea how I could use JWT to pass authentication/authorization from the login app to the others.
The main reason for this is so that each subsystem can be modified or updated without shutting down the others. And organizationally, so we don't have to subject the entire app to a QA process when only one subsystem is changed.
Is it possible to set up multiple Spring Boot instances to run on the same server at the same time and the same port, with different paths/directories to their endpoints? How?
I was unable to find any duplicate question, but here are two related questions that may offer clues:
From Is there a standard way to customize the deploy path in Spring Boot? I learned that I can set the application property server.servlet.context-path to prefix the whole application with a subdirectory name (e.g. "/subsystem1"). But I still can't run two apps at the same time, even if both claim different subdirectories. Spring Boot reports "Web server failed to start. Port 8080 was already in use."
There's Multiple Spring-boot applications running on one Tomcat
but I'd prefer to use standalone Spring applications with their embedded Tomcat instances rather than the less-recommended WAR packaging and deployment to an external Tomcat container.
This one looks promising -- Deploying Multiple Spring Boot Web Applications in Single Server -- but the answers focus on whether standalone or Tomcat container deployments are better, and doesn't touch on the "how-to" question.
Acceptable answers:
If, as ekalin suggests, it is impossible to have multiple Spring Boot apps listen to the same port, here are a couple of ideas I have brainstormed (but don't know how to accomplish):
Perhaps the instances could be running on different ports but the main app (the one with the login page) could "forward" or redirect to the other apps in some way that hides their true URLs? E.g. "localhost:8080/subsystem1" would be an alias for "localhost:8081/".
Perhaps the applications could each have their own Docker containers, all running within a shared Docker network, and we use Docker somehow to map each URL path to the right app? Could this be set up with docker-compose?
We set up a proxy server of some kind that remaps URL paths to the separate applications.
You can't have more than one application listening on a port. How would the kernel which application to send the packages to?
You could run an http server such as nginx listening on 8080, and each application in a different port, and then proxy the requests based on the URL to the desired application.

Deploy my spring boot application into google cloud computer engine

I got a query to ask you all. I am looking for guides that help me deploy my spring boot application on google cloud computer engine, I type in my instance IP address when I test my spring boot application I unable to access it in REST API.
May I know do you have any guides or steps for me to follow to deploy successfully in google cloud computing engine. Why do I need to deploy in computer engine is because I deployed my angular at it and I deploy it both it seems that my angular project being replaced by my spring boot application.
Codelabs GCP / Spring series has deployment tutorials:
https://codelabs.developers.google.com/spring/
GCP has some "Getting Started" tutorials you can use here:
https://cloud.google.com/java/docs/
where the specific one for deploying a java app to GCE is here:
https://cloud.google.com/java/docs/tutorials/bookshelf-on-compute-engine
But the basic steps are as follows:
Write your Spring app
Build your Spring app
Run / test your jar locally
Push your jar to a location in Storage
Create a startup script for your GCE instance
Create a new GCE VM which uses your startup script using Console, Deployment API, or gcloud tool
After that, you need to ensure you have the proper network rules in place to be able to access your API publicly. If you do not wish to learn how to use GCE, I would suggest you look into using App Engine instead because then you do not need to learn how to deploy and instead can concentrate on your api. Here is a guide to do that

Is it possible to deploy multiple Spring Boot applications to a server?

We can create restful API in spring boot jar file?
1)can we split multiple jar file in Apache server?
2) if we split multiple jar file how will identify which jar contain correct rest APIs
How spring boot jar file will work in server?
For Development Environment
You can configure ports via application.properties or via system properties.
Or with option to jvm --server.port=8081
So, there is no problem to run a few APIs on single machine with different ports.
You don't need Apache Server. Spring Boot has it's own embedded for you. So, you can easily use it.
Let's say you have two APIs.
localhost:8081 (Checkout Service)
localhost:8082 (Payment Service)
Hostname and port - it's your identification for each service.
When you trying to search something in Google.
You browser - it's a client.
And Google's servers - it's a server.
The same here. Checkout Service trying to delegate some job to Payment Service. So, Checkout Service - it's a client. And this client should know the address of Payment Service.
For Production Environment
You should think twice, how you will monitor performance, manage scalability and so on.

Angular2 application with springboot using maven

I am new to Springframework. I created a Springboot application and expose rest services. Now I want to consume my rest services in angular2. I am not sure how to create folder structure for my application. Should I create angular2 app in src/main/resources folder using angular cli? or as I am exposing rest services so should I create a separate angular project and consume the services? But if user this approach it will run on two different ports on localhost and I get CrosOrigin error.
In production I will deploy the application on same server. It will be a one website.
One more point I am using Maven and STS tool suit to create springboot application.
For a Spring-Boot novice using AngularJS you might be checking out JHipster (which actually is a combination of these two projects), which might serve you with some best practices.
Currently based on AngularJS 1 - it's not Angular2 yet - however they're busy porting it to version 2 (see progress, see this branch).
Alternatively there's also a guide on how to create a standalone Spring-Boot application with AngularJS (1).
I find some sample code but even in Springboot application you have to run spring and angular application on two different ports on local host. So the best way to solve the problem is to create two application expose services in spring boot and use in angular client side. While running on local use enable CORS.
Another way is to use JHipster. They recently release JHipster 4 which support angular 2.

How to deploy a spring integration component?

I've developed a spring integration component that is to sit on a server and process messages coming in over an inbound RMI channel do some processing/filtering and then send out some messages over a different RMI channel.
Currently, for testing, I've been running it using a Main class that just loads the context, which sets up the inbound RMI gateway and it's working fine. But I don't think that this is appropriate for a production environment.
What is the best way to deploy this type of project to a server?
If I were working in a .Net I'd be deploying this type of application as a windows service, is that what I should be doing here?
The application that is sending me data is hosted in Tomcat, would it be a good idea to also run this application within the same Tomcat container (Current requirements are for both components to be on the same machine this may change)? And if so how?
I'm currently looking into Spring Boot, am I on the right path?
I think the best would be Spring Boot, as it's made to easily allow running different types of applications. Also, you don't need Tomcat if you can run the same component with a simple Main and not using UI. Spring Boot, also, has a sample using Spring Integration here, so you should be up and running in no time.

Resources