quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.58k stars 2.63k forks source link

QUARKUS_PROFILE=dev and '-Dquarkus.profile=dev' not working for native image #37177

Closed mhubig closed 9 months ago

mhubig commented 10 months ago

Describe the bug

Setting QUARKUS_PROFILE=dev or appending the comand line option -Dquarkus.profile=dev to the native image has no effect. The application is always started with the prod profile:

 ERROR: Failed to start application (with profile [prod])

Expected behavior

Native build application should start with the profile provided by setting QUARKUS_PROFILE or appending the argument -Dquarkus.profile=<name>.

Actual behavior

No response

How to Reproduce?

No response

Output of uname -a or ver

Linux 8e5df6b21197 6.4.16-linuxkit #1 SMP PREEMPT Fri Nov 10 14:49:23 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

java version "17.0.8" 2023-07-18 LTS Java(TM) SE Runtime Environment Oracle GraalVM 17.0.8+9.1 (build 17.0.8+9-LTS-jvmci-23.0-b14) Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 17.0.8+9.1 (build 17.0.8+9-LTS-jvmci-23.0-b14, mixed mode, sharing)

Mandrel or GraalVM version (if different from Java)

No response

Quarkus version or git rev

3.5.2

Build tool (ie. output of mvnw --version or gradlew --version)

Maven home: /Users/Markus.Hubig/.m2/wrapper/dists/apache-maven-3.9.5-bin/32db9c34/apache-maven-3.9.5 Java version: 21.0.1, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/graalvm-jdk-21/Contents/Home Default locale: de_DE, platform encoding: UTF-8 OS name: "mac os x", version: "14.1", arch: "aarch64", family: "mac"

Additional information

No response

quarkus-bot[bot] commented 10 months ago

/cc @Karm (mandrel), @galderz (mandrel), @zakkak (mandrel,native-image)

melloware commented 10 months ago

Hmmm I could be wrong but Native Build automatically presupposes Production mode right? I don't think you can run in Dev mode in a Native image?

geoand commented 10 months ago

@mhubig what exactly are you trying to achieve?

yrodiere commented 10 months ago

@geoand FWIW I noticed something similar with @QuarkusIntegrationTest...

If I set this in my config:

quarkus.test.integration-test-profile=integrationtest

Then @QuarkusIntegrationTest will start quarkus with the correct profile (-Dquarkus.profile=integrationtest):

Executing "/home/yrodiere/workspaces/main/search.quarkus.io/target/search-quarkus-io-999-SNAPSHOT-runner -Dquarkus.http.port=8081 -Dquarkus.http.ssl-port=8444 -Dtest.url=http://localhost:8081 -Dquarkus.log.file.path=/home/yrodiere/workspaces/main/search.quarkus.io/target/quarkus.log -Dquarkus.log.file.enable=true -Dquarkus.log.category."io.quarkus".level=INFO -Dquarkus.profile=integrationtest -Dfetching.quarkusio.uri=file:///tmp/all6579920155752301763/ -Dquarkus.hibernate-search-orm.elasticsearch.hosts=localhost:42601"

But startup logs seem to indicate -Dquarkus.profile was ignored:

2023-11-24 12:47:00,196 INFO  [io.quarkus] (main) Profile prod activated. 

And indeed, I confirm my integrationtest profile is not active: I set a custom log level for a certain category with that profile, and the level still doesn't appear in logs (I did set the min-level correctly at build time).

From what I can see the line "Profile prod activated" gets the list of profiles from Smallrye Config:

https://github.com/quarkusio/quarkus/blob/32047ae811f21919ba452c027b1e300edcc3f581/core/deployment/src/main/java/io/quarkus/deployment/steps/MainClassBuildStep.java#L271-L272

Perhaps there's a regression, with profiles not being set correctly, at least in native mode?

It might be a regression caused by my changes in #36560 ... But I'd certainly like @radcortez 's help to investigate this.

yrodiere commented 10 months ago

It might be a regression caused by my changes in https://github.com/quarkusio/quarkus/pull/36560 ... But I'd certainly like @radcortez 's help to investigate this.

Hurray, it's not caused by #36560, because that was only merged in Quarkus 3.6, not in 3.5!

But... that means we really don't know where this is coming from. Any idea @radcortez?

geoand commented 10 months ago

Thanks for checking!

yrodiere commented 10 months ago

Also, related (but not exactly the same problem): #36376

mhubig commented 9 months ago

@mhubig what exactly are you trying to achieve?

We are building a docker container with a native quarkus build. We tried to reproduce a bug locally using the production container. Here is a snippet of our application.properties file:

quarkus.datasource.jdbc.url=jdbc:postgresql:///postgres
quarkus.datasource.jdbc.driver=org.postgresql.Driver

%prod.quarkus.datasource.jdbc.url=jdbc:postgresql:///${CLOUDSQL_DATABASE_NAME}
%prod.quarkus.datasource.username=${CLOUDSQL_USER_NAME}
%prod.quarkus.datasource.password=password
%prod.quarkus.datasource.jdbc.additional-jdbc-properties.cloudSqlInstance=${CLOUDSQL_CONNECTION_NAME}
%prod.quarkus.datasource.jdbc.additional-jdbc-properties.socketFactory=com.google.cloud.sql.postgres.SocketFactory
%prod.quarkus.datasource.jdbc.additional-jdbc-properties.enableIamAuth=true

The prod profile settings ensure we are using the Google Cloud SQL SocketFactory when deploying our container to production, but if we start the container locally we would like to use a local database so we tried to set a different profile.

We can archive this by setting the properties via ENV variables, but we thought this is possible by using profiles ...

radcortez commented 9 months ago

The profiles are set correctly. It is just the log that is off.

But remember, for native images, static init code will use the profile used at build time (because static init is initialized during native image compilation), so you may get unexpected results.

yrodiere commented 9 months ago

The profiles are set correctly. It is just the log that is off.

@radcortez Maybe that's a different issue, but I did get some runtime properties apparently being set to an incorrect value... Here's a reproducer: