spring-boot icon indicating copy to clipboard operation
spring-boot copied to clipboard

Add documentation tip showing how to configure publishRegistry maven properties from the command line

Open ffroliva opened this issue 3 years ago • 7 comments

If I have a private registry and I want to publish the generated docker image I need to provide username, password, and url in the maven pom.xml.

...
<plugin>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-maven-plugin</artifactId>
  <configuration>
    <image>
      <name>${docker.image.prefix}/${project.artifactId}:${project.version}</name>
    </image>
    <docker>
      <publishRegistry>
        <username>USERNAME</username>
        <password>PASSWORD</password>
        <url>URL</url>
      </publishRegistry>
    </docker>
  </configuration>
  <executions>
    <execution>
      <goals>
        <goal>build-image</goal>
      </goals>
    </execution>
  </executions>
</plugin>

I would like to be able to send this variables over the command line as follows:

mvn spring-boot:build-image \
-DskipTests \
-Dspring-boot.build-image.imageName=nexus:8870/rcl/op-risk-ui:test \
-Dspring-boot.build-image.publishRegistry.username=<USERNAME> \
-Dspring-boot.build-image.publishRegistry.password=<PASSWORD>
-Dspring-boot.build-image.publishRegistry.url=<URL>

Currently the following variables doesnt exist for the command line:

  • -Dspring-boot.build-image.publishRegistry.username
  • -Dspring-boot.build-image.publishRegistry.password
  • Dspring-boot.build-image.publishRegistry.url

I believe they should be created here: https://github.com/spring-projects/spring-boot/blob/82b90d57496ba85be316b9eb88a36d81f2cc9baa/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/BuildImageMojo.java

ffroliva avatar May 13 '22 09:05 ffroliva

I'm not sure how easy this will be to fix. I suspect that we can't just add a property attribute to the docker @Parameter because it's a complex type. We'll need to dig into the internals of Maven.

In the meantime, you can probably do something like this:

<plugin>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-maven-plugin</artifactId>
  <configuration>
    <image>
      <name>${docker.image.prefix}/${project.artifactId}:${project.version}</name>
    </image>
    <docker>
      <publishRegistry>
        <username>${spring-boot.build-image.publishRegistry.username}</username>
        <password>${spring-boot.build-image.publishRegistry.password}</password>
        <url>${spring-boot.build-image.publishRegistry.url}</url>
      </publishRegistry>
    </docker>
  </configuration>
  <executions>
    <execution>
      <goals>
        <goal>build-image</goal>
      </goals>
    </execution>
  </executions>
</plugin>

philwebb avatar May 13 '22 17:05 philwebb

It's indeed not possible to map a nested parameter unless we create a parameter for the sole purpose to be mapped. This is one of the downsides of using such structure with Maven plugins. I don't think we should expose the parameters and users should rather define a property that suits their needs using either the suggestion above, or using a profile.

snicoll avatar May 16 '22 12:05 snicoll

I don't think we should expose the parameters and users should rather define a property that suits their needs using either the suggestion above, or using a profile.

I agree with @snicoll, as Maven makes it simple enough to create your own properties and use them in the plugin configuration.

scottfrederick avatar May 16 '22 16:05 scottfrederick

I too agree with @snicoll. We've already seen some examples of users defining their own properties such as this from #29756:

<configuration>
    <image>
        <name>${docker.image-name}</name>
    </image>
    <docker>
        <publishRegistry>
            <username>${docker.credentials.username}</username>
            <password>${docker.credentials.password}</password>
        </publishRegistry>
    </docker>
</configuration>

This feels like the right way to go to me.

wilkinsona avatar May 16 '22 16:05 wilkinsona

Thanks everyone. I'm going to repurpose this one as documentation issue.

philwebb avatar May 16 '22 17:05 philwebb

I think, then, that this scenario should be added to the documentation since I understand this is quite a common use case. The example where you add this variable directly in the pom.xml doesn't really represent the best practice and will almost always be avoided, therefor showing one approach to go would be important for the whole community.

Em seg., 16 de mai. de 2022 às 13:14, Stéphane Nicoll < @.***> escreveu:

It's indeed not possible to map a nested parameter unless we create a parameter for the sole purpose to be mapped. This is one of the downsides of using such structure with Maven plugins. I don't think we should expose the parameters and users should rather define a property that suits their needs using either the suggestion above, or using a profile.

— Reply to this email directly, view it on GitHub https://github.com/spring-projects/spring-boot/issues/31024#issuecomment-1127595644, or unsubscribe https://github.com/notifications/unsubscribe-auth/AF67VG6ZVFAVWVZRBAUECF3VKI3YTANCNFSM5V2ZOBYA . You are receiving this because you authored the thread.Message ID: @.***>

ffroliva avatar Oct 11 '22 09:10 ffroliva

@ffroliva please consult the history of the issue before commenting. That's exactly what this issue is about.

snicoll avatar Oct 11 '22 09:10 snicoll

Closing in favor of #34517

scottfrederick avatar Mar 08 '23 21:03 scottfrederick