quarkusio / quarkus

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

quarkus-maven-plugin no longer utilizes profile properties after a file was written to ${project.build.outputDirectory}/application-develop.properties #43366

Closed jg-cantaa closed 1 month ago

jg-cantaa commented 1 month ago

Describe the bug

My original goal is to specify properties at build-time. (e.g. specifying quarkus.datasource.jdbc.url at build-time in CI)

I have a POM file with several profiles like this:

<profile>
      <id>azureDevops</id>
      <properties>
          <!--Azure Container Registry-->
          <quarkus.container-image.username>00000000-0000-0000-0000-000000000000</quarkus.container-image.username>
          <quarkus.container-image.image>${env.ACR_URL}/${project.artifactId}/${deployment}:latest</quarkus.container-image.image>
          <quarkus.container-image.build>true</quarkus.container-image.build>
          <quarkus.container-image.push>true</quarkus.container-image.push>

          <!--Kubernetes-->
          <jkube.namespace>${env.K8SNAMESPACE}</jkube.namespace>
          <jkube.generator.name>${env.ACR_URL}/${project.artifactId}/${deployment}:latest</jkube.generator.name>
          <quarkus.kubernetes.deployment-target>kubernetes</quarkus.kubernetes.deployment-target>

          <quarkus.jib.environment-variables.JAVA_APP_DIR>/deployments/data</quarkus.jib.environment-variables.JAVA_APP_DIR>
          <quarkus.jib.jvm-additional-arguments>-Xmx12G</quarkus.jib.jvm-additional-arguments>

          <maven.test.skip>true</maven.test.skip>
        </properties>
        </profile>
        <profile>
            <id>local</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <deployment>local</deployment>
            </properties>
        </profile>
        <profile>
        <id>develop</id>
        <properties>
            <deployment>develop</deployment>
            <quarkus.datasource.jdbc.url>jdbc:postgresql://${env.DB_HOST_DEVELOP}/odus_dev?currentSchema=max&amp;ApplicationName=MbcsSearch</quarkus.datasource.jdbc.url>
            <quarkus.datasource.password>${env.DB_ODUS_PASS_DEVELOP}</quarkus.datasource.password>
            <quarkus.datasource.username>${env.DB_ODUS_USER_DEVELOP}</quarkus.datasource.username>
            <zk.password>${env.SEARCH_ZK_ADMIN_PASSWORD_DEVELOP}</zk.password>
            <odus.password>${env.SEARCH_ODUS_ADMIN_PASSWORD_DEVELOP}</odus.password>
            <odus.secret>${env.SEARCH_ODUS_CLIENT_SECRET_DEVELOP}</odus.secret>
        </properties>
      </profile>

In CI we run maven with the profiles flag "-P azureDevops,$(branchName)". This configuration passes CI and deploys, but at runtime Quarkus complains that the Datasource is not configured:

Caused by: io.quarkus.runtime.configuration.ConfigurationException: Unable to find datasource '<default>' for persistence unit '<default>': Datasource '<default>' is not configured. To solve this, configure datasource '<default>'. Refer to https://quarkus.io/guides/datasource for guidance.

This is somewhat expected as quarkus cannot read the properties from the pom. As a solution to this I have found the properties-maven-plugin from org.codehaus.mojo. Utilizing their plugin like this:

<plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>properties-maven-plugin</artifactId>
                <version>1.2.1</version>
                <executions>
                    <execution>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>write-active-profile-properties</goal>
                        </goals>
                        <configuration>
                            <outputFile>
                                ${project.build.outputDirectory}/application-${deployment}.properties
                            </outputFile>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

Which I tested locally to produce an application-develop.properties in the target folder. Since quarkus uses the develop profile it should then load the values from there.

Expected behavior

I expected quarkus to not have a problem with this plugin, as it just writes properties to a file in the target folder.

Actual behavior

Once the plugin is added, quarkus fails with the message:

[ERROR] Caused by: com.google.cloud.tools.jib.api.RegistryAuthenticationFailedException: Failed to authenticate with registry registry-1.docker.io/agent/mbcs-search because: 401 Unauthorized
[ERROR] GET https://auth.docker.io/token?service=registry.docker.io&scope=repository:agent/mbcs-search:pull,push
[ERROR] {"details":"incorrect username or password"}

This indicates to me that it has problems with the properties set in the profile once the plugin is enabled. Without the plugin it works fine.

I have even looked at the source of the plugin (https://github.com/mojohaus/properties-maven-plugin/blob/master/src/main/java/org/codehaus/mojo/properties/WriteActiveProfileProperties.java) to see if that messes with the properties, but I could not find a reason.

Once I tried to write the property file to ${project.build.outputDirectory}/test/test.properties it passed CI again.

How to Reproduce?

No response

Output of uname -a or ver

-

Output of java -version

No response

Quarkus version or git rev

3.7.4 ### Build tool (ie. output of `mvnw --version` or `gradlew --version`) Apache Maven 3.9.6 (bc0240f3c744dd6b6ec2920b3cd08dcc295161ae) Maven home: /home/jakobgerhardt/.m2/wrapper/dists/apache-maven-3.9.6-bin/3311e1d4/apache-maven-3.9.6 Java version: 11.0.23, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64 Default locale: de_DE, platform encoding: UTF-8 OS name: "linux", version: "6.9.3-76060903-generic", arch: "amd64", family: "unix" ### Additional information I tried running this plugin in a different phase, but to no avail.
quarkus-bot[bot] commented 1 month ago

/cc @geoand (jib,kubernetes), @iocanel (kubernetes), @quarkusio/devtools (maven)

geoand commented 1 month ago

cc @radcortez

radcortez commented 1 month ago

I've tried it, and it works. Do you have an application.properties sitting in the exact location? It is required to load profile properties files: https://quarkus.io/guides/config-reference#profile-aware-files

jg-cantaa commented 1 month ago

A colleague was able to fix it. Apparently it was due to some filtering set to true in the <resources> section for the resources folder?

I guess this is not really a quarkus issue, although I wish that quarkus would add documentation on how to idiomatically set configuration at build time

geoand commented 1 month ago

Thanks for the update