Search code examples
quarkus

Is there a way to setup a remote quarkus postgresql dev-service?


Due to security concerns, my company doesn't allows to use containers on our laptops.

So we can't use the normal quarkus:dev to run our test that connects to Postgresql.

But they provides us a remote machine where we can use Podman to run some containers.

What I'm doing now is to manually ssh to that machine and starting a Postgresql container before running local tests.

What I would like is to do this automatically, and also find a way to do the same on Jenkins when when we need to run a pipeline to release a new version.


Solution

  • This is a common scenario, and the intention of Quarkus's developer joy features is to allow it to work in a frictionless way, without requiring scripts or manual tunneling.

    There are two options, although which one works best for you will depend a bit on how your company's remote podman is set up.

    1. Remote dev services. (When you run Quarkus in dev mode, the automatic provisioning of unconfigured services is called 'dev services'.) The idea here is that you use dev services normally, but under the covers, the container client is connecting to the remote instances. For Dev services, Testcontainers provides container connectivity under the covers. This should work transparently as long as podman run works. You'd set it up using something like
    podman system connection add remote --identity ~/.ssh/my-key ssh://my-host/podman/podman.sock
    podman system connection default remote
    

    If you don't have a local podman client, or if the podman connection settings don't sort it out, setting DOCKER_HOST to the right remote socket will also tell Testcontainers where to look.

    1. Remote dev mode. Here, the whole application is running in a container on the remote server. Changes to your local files are reflected in the remote instance.

    To use remote dev mode, you build a special jar and then launch it in the remote environment. Add the following to your application.properties:

    %dev.quarkus.package.type=mutable-jar 
    

    Then build the jar (they could be in the application.properties, but then you couldn't commit it to source control):

    QUARKUS_LIVE-RELOAD_PASSWORD=<arbitrary password> ./mvnw install
    

    The install will build you a normal fast-jar dockerfile. Run it in your remote environment with QUARKUS_LAUNCH_DEVMODE=true added to the podman run command.

    Then, locally, instead of mvn quarkus:dev, you'd run ./mvnw quarkus:remote-dev -Dquarkus.live-reload.url=http://my-remote-host:8080

    https://quarkus.io/guides/maven-tooling#remote-development-mode has a more complete set of instructions. This option does have more moving parts and more latency, since you're transferring your whole application to the remote server every time code changes. So if you can, just configuring podman and using remote dev services is probably better.

    A third option, which probably isn't relevant for you, is to use Testcontainers Cloud. Quarkus dev services use Testcontainers under the covers, and Testcontainers Cloud is a convenient way of running Testcontainers remotely.