Define multiple liquibase datasources in Quarkus YAML - yaml

How can I define multiple datasources for the Quarkus YAML extension ?
Apperantly, it works like the following in the application.properties file:
# Liquibase configuration for the default datasource
quarkus.liquibase.schemas=DEFAULT_TEST_SCHEMA
quarkus.liquibase.change-log=db/changeLog.xml
quarkus.liquibase.migrate-at-start=true
# Liquibase configuration for the "users" datasource
quarkus.liquibase.users.schemas=USERS_TEST_SCHEMA
quarkus.liquibase.users.change-log=db/users.xml
quarkus.liquibase.users.migrate-at-start=true
# Liquibase configuration for the "inventory" datasource
quarkus.liquibase.inventory.schemas=INVENTORY_TEST_SCHEMA
quarkus.liquibase.inventory.change-log=db/inventory.xml
quarkus.liquibase.inventory.migrate-at-start=true
But something like this doesn't work in the YAML version
"%test":
quarkus:
log:
level: INFO
datasource:
devservices:
enabled: true
liquibase:
change-log: "db/changeLog.xml"
users:
change-log: "db/users.xml"
Isn't it possible ?
Would be great if we could get more YAML examples in the docs :(

Related

Spring Boot Liquibase doesn't appear to support XML formatted changelog

spring-boot-starter-parent:2.7.5
I have configured the following in my src/main/resources/application.yml file:
spring:
liquibase:
change-log: classpath:/db/changelog/db.changelog-master.xml
---
spring:
config:
activate:
on-profile: prod
datasource:
driver-class-name: org.postgresql.Driver
url: ${DB_URL}
username: ${DB_USERNAME}
password: ${DB_PASSWORD}
Additionally, the following resource exists in the project repository:
src/main/resources/db/changelog/db.changelog-master.xml
I also have the following configured in src/test/resources/application.yml:
spring:
config:
activate:
on-profile: test
datasource:
driver-class-name: org.h2.Driver
url: jdbc:h2:mem:db;DB_CLOSE_DELAY=-1
username: sa
password: sa
liquibase:
change-log: classpath:/db/changelog/db.changelog-master.xml
When I try to build this project the build fails with the following error message:
Liquibase failed to start because no changelog could be found at 'classpath:/db/changelog/db.changelog-master.yaml'
Is there some way to configure spring boot to allow an xml based liquibase changelog file? If so, what am I missing? Or does it only support the yaml format?
Your configurations seems valid, but some configuration still points to classpath:/db/changelog/db.changelog-master.yaml (based by on provided error message)
If there is no some typo, than may be you should look for this property in some other configuration (.properties files, command line arguments and other, see doc for all possible ways)

Use JAAS config file with hikari data-source-properties

Is there a way to use a JAAS config file with Hikari data-source-properties? I have multiple Login contexts in the JAAS config file (to connect to Cassandra and Kafka) and would like to connect to Oracle db in the same way.
These are the current properties:
spring:
datasource:
url:
username:
driver-class-name: oracle.jdbc.OracleDriver
hikari:
data-source-properties:
oracle.net.kerberos5_cc_name: <ticker cache path here>
oracle.net.authentication_services: KERBEROS5
oracle.net.kerberos5_mutual_authentication: true
Instead of specifying ticket cache through these properties I'd like to keep them in the JAAS config file and specify the config path with VM args/System props (java.security.auth.login.config). The reason for this is that while specifying ticket cache paths in application properties, they get overriden. (If connection order is Oracle->Cassandra->Kafka, then the Oracle config will be overriden by Cassandra config, and then the Cassandra config will be overriden by Kafka configuration.)

spring-cloud-vault-config-databases with Spring Boot 2.4.0 Config Data API fails to bind properties

I'm using spring-cloud-vault-config-databases with Spring Boot 2.4.0 Config Data API as the prefered mode described here bootstrap.yml configuration not processed anymore with Spring Cloud 2020.0 :
When I'm using Spring Boot 2.4.0 Config Data API to import configuration from Vault (Preferred) the secret properties are not binded to the spring.datasource.username & spring.datasource.password and my postgres cnx fails.
When I'm using "Legacy Processing" with the bootstrap configuration property spring.cloud.bootstrap.enabled=true the properties spring.datasource.username & spring.datasource.password are well binded to my Vault secret.
What is the expected behaviour of the spring-cloud-vault-config-databases ?
Is expected to works with Spring Boot 2.4.0 Config Data API ?
my application.yml
spring.cloud.vault:
enabled: true
authentication: CERT
ssl:
key-store: file: ...
key-store-password: ...
trust-store: ...
trust-store: ...
trust-store-password: ...
cert-auth-path: ...
uri: https:...
namespace: ...
fail-fast: true
database:
enabled: true
role: myPostgresRole
backend: database/postgres/...
username-property: spring.datasource.username
password-property: spring.datasource.password
spring:
config:
import: vault://secret/... , vault://database/postgres/...
Versions used :
spring-boot : 2.4.11
spring-cloud : 2020.0.3
spring-cloud-vault-config-databases : 3.0.3

Read values from consul while bootstrap spring boot

I have question is there any way to retrieve certain values and inject them to bootstrap.yml while application is coming up.
I have configuration file like this:
spring:
application:
name: myApp
cloud:
consul:
enabled: true
host: localhost
port: 8500
config:
enabled: true
datasource:
url: jdbc:oracle:thin:#localhost:1111:XXXX
username: ${nameOfVariable1}
password: ${nameOfVariable1}
driver-class-name: oracle.jdbc.OracleDriver
For example, I need to configure embedded tomcat port, or DB credentials, I don't want to put it hardcoded in .yml properties file, instead I want to put some variable name in .yml so Spring will go and bring value from Consul. Is it possible?
You can use Spring Cloud Consul Config project that helps to load configuration into the Spring Environment during the special "bootstrap" phase.
3 steps:
add pom dependency: spring-cloud-starter-consul-config
enable consul config: spring.cloud.consul.config.enabled=true
add some config in consul kv in specific folder, such as key: config/testConsulApp/server.port, value:8081
and then start the sample web app, it will listen 8081.
more detail at spring cloud consul doc.
and demo code here

spring boot yaml profile names resolution

I have multimodule maven project in which I have one common part which I want to share between applications.
In common module I'm defining the configuration for liquibase and db connection. For this I have 2 profiles common-prod and common-dev located in application.yaml.
spring:
profiles: common-prod
# POSTGRE
datasource:
url: ${DATABASE_URL:jdbc:postgresql://localhost:5432/dbname}
driver-class-name: org.postgresql.Driver
username: pguser
password: pguser
jpa:
database-platform: org.hibernate.dialect.PostgreSQLDialect
hibernate:
ddl-auto: none
properties:
hibernate.default_schema: public
#LIQUIBASE
liquibase:
enabled: true
change-log: /db/changelog/db-changelog-master.xml
drop-first: false
---
spring:
profiles: common-dev
# POSTGRE
datasource:
url: ${DATABASE_URL:jdbc:postgresql://localhost:5432/dbname-dev}
username: pguserdev
password: pguserdev
#LIQUIBASE
liquibase:
enabled: true
drop-first: true
now in web application I want to define some additional properties. But when I include them in application.yaml (in web module) I think it overrides the application.yaml from common module.
So I need to
rename the application.yaml from common to something like application-common.yaml
rename the application.yaml in application to something like application-web.yaml
if I rename the common module's yaml file am I able to reference the profiles from within this file? eg something like -Dspring.profiles.active=common-common-prod or I need to separate this profiles to separate yaml files?
If I rename web modules config file to application-web.yaml I must allways include the web profile. I can live with that, but it would be simpler to include the profiles in application.yaml and don't care about command line arguments.

Resources