https://github.com/t1/quarkus-compose-devservice-demo
Advanced demos of using Quarkus Dev Services
https://github.com/t1/quarkus-compose-devservice-demo
Last synced: about 1 year ago
JSON representation
Advanced demos of using Quarkus Dev Services
- Host: GitHub
- URL: https://github.com/t1/quarkus-compose-devservice-demo
- Owner: t1
- Created: 2025-06-22T07:26:21.000Z (about 1 year ago)
- Default Branch: trunk
- Last Pushed: 2025-07-09T23:12:10.000Z (about 1 year ago)
- Last Synced: 2025-07-10T09:19:40.831Z (about 1 year ago)
- Language: Java
- Size: 20.5 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.adoc
Awesome Lists containing this project
README
= Quarkus Compose Dev Services Demo
Advanced demos of using https://quarkus.io[Quarkus] Dev Services:
* a `MockService` class in `/src/dev/java` that runs in `test` and `dev` modes, but not in `prod`.
* a `compose.yaml` that starts a https://min.io[min.io] S3 server.
The `TestDataLoader` class in `/src/test/java` creates a bucket and uploads some test data to the `minio` server.
For details about the Compose Dev Services, see the corresponding https://quarkus.io/guides/compose-dev-services[Quarkus Guide].
Note that the `MockService` does not use that mechanism nor a Docker container, but being just a regular Java class, this is a handy alternative for mocking services.
== Usage
Start the dev mode with (we set the `defaultGoal` to `quarkus:dev` in the `dev` profile of the `pom.xml`):
[source,bash]
----
mvn -Pdev
----
Then you can access all endpoints in the Dev UI, or by opening these URLs in your browser, curl, httpie, etc.:
* http://localhost:8080/hello direct greeting
* http://localhost:8080/mock response from the `MockService`
* http://localhost:8080/hello/mock greeting utilizing the `MockService`
* http://localhost:/test/s3.txt response from `S3`
* http://localhost:8080/hello/s3 greeting utilizing `S3`
You can also run the tests by pressing `r`.
== Issues
=== Dependency that defines a Dev Service https://github.com/quarkusio/quarkus/issues/48460[#48460]
We have a dependency on `quarkus-jdbc-postgresql`, even though we don't use it in this demo.
But we need some dependency with a Dev Service so the Compose Dev Services load at all.
=== Port Mapping
When you run the tests from within the dev mode, a second instance of the Dev Services is started, so we need separate ports for the `minio` service for `test` and `dev` mode.
The easiest way to do that is to map the `minio` service port `9000` to a random host port.
We would also like to bind the network interface only to `localhost`, so the service is not being exposed on a Linux machine (as the default binding is `0.0.0.0`), but then we need to specify the host port as well; `127.0.0.1:9000` doesn't work, because `127.0.0.1` is not a valid port number.
The https://github.com/compose-spec/compose-spec/blob/main/spec.md[Compose Spec] defines a syntax for specifying a port range, so we could use "127.0.0.1:9000:9000-9999", but that syntax is currently not supported by Quarkus Dev Services; it fails with `Error parsing ExposedPort '9000-9999'` in `ExposedPort.java:131`.
There's also a https://github.com/compose-spec/compose-spec/blob/main/spec.md#long-syntax-3[long form] for the port mapping, but that fails, too:
[source,yaml]
----
services:
s3:
ports:
- name: api
target: 9000
host_ip: 127.0.0.1
----