Activating profiles

Let's learn how to activate a specific profile by taking the prod profile in the preceding configuration as an example. First of all, we need to start a PostgreSQL instance named postgresProd and bind it to port 7432:

docker run --ulimit memlock=-1:-1 -it --rm=true --memory-swappiness=0 --name quarkus_Prod -e POSTGRES_USER=quarkus -e POSTGRES_PASSWORD=quarkus -e POSTGRES_DB=postgresProd -e PGPORT=7432 -p 7432:7432 postgres:10.5

Then, we need to provide profile information during the package phase, as follows:

mvn clean package -Dquarkus.profile=prod -DskipTests=true

When running the application, it will pick up the profile you specified in the package phase:

java -jar target/profiles-demo-1.0-SNAPSHOT-runner.jar

As an alternative, it is also possible to specify the profile using the QUARKUS_PROFILE environment variable, like so:

export QUARKUS_PROFILE=dev
java -jar target/profiles-demo-1.0-SNAPSHOT-runner.jar

Finally, it's worth mentioning that the same strategy can be used to define non standard profiles. For example, let's say we want to add a staging profile for applications that need to be checked before production:

%staging.quarkus.datasource.url=jdbc:postgresql://localhost:8432/postgresStage

Here, we can apply the same strategy we've used for other profiles, that is, we can either specify the profile at application startup using the Java system property (quarkus-profile) or add the necessary information to the QUARKUS_PROFILE environment variable.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.134.79.121