【发布时间】:2021-05-03 13:45:14
【问题描述】:
我想集成 Spring Boot maven 插件功能来构建 OCI 映像并将其发布到远程存储库
我的目标
我想使用以下插件配置:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<image>
<name>${docker.image.prefix}/${project.artifactId}:${project.version}</name>
</image>
</configuration>
<executions>
<execution>
<goals>
<goal>build-image</goal>
</goals>
</execution>
</executions>
</plugin>
现在我想通过命令行传递docker.publishRegistry 变量。
到目前为止我已经尝试过什么
我尝试使用 -Ddocker.publishRegistry.username 属性传递参数,但没有成功。
当您查看插件的源代码时,Docker 没有分配给它的 Parameter 属性:
/**
* Alias for {@link Image#publish} to support configuration via command-line property.
*/
@Parameter(property = "spring-boot.build-image.publish", readonly = true)
Boolean publish;
/**
* Docker configuration options.
* @since 2.4.0
*/
@Parameter
private Docker docker;
所以我猜这个参数是不可能通过命令行定义的吧?
当前的解决方法
目前我正在通过全局 maven 属性定义属性,并在 docker 范围内重用它们。
我的 pom.xml:
<properties>
<docker-registry>https://example.org</docker-registry>
<docker-registry-username>username</docker-registry-username>
<docker-registry-username>password</docker-registry-username>
</properties>
<!-- ... -->
<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>${docker-registry-username}</username>
<password>${docker-registry-password}</password>
<url>${docker-registry}</url>
</publishRegistry>
</docker>
</configuration>
<executions>
<execution>
<goals>
<goal>build-image</goal>
</goals>
</execution>
</executions>
</plugin>
我正在构建:
./mvnw -B -s \
-Dspring-boot.build-image.publish=true \
-Ddocker-registry-username="$USERNAME" \
-Ddocker-registry-password="$PASSWORD" \
-Ddocker-registry="$REGISTRY" \
clean deploy
【问题讨论】:
标签: spring-boot maven spring-boot-maven-plugin