When deploying to Kubernetes (for example) at dev time, it is useful to be able to modify the image name on the command line, so that it can always be unique and Kubernetes can detect the change and do a rolling update (or whatever it needs to do).
E.g. when using Skaffold, it presents a custom builder with an env var (IMAGE), so that you can do this automatically. This seems to be working for me:
apiVersion: skaffold/v2alpha4
kind: Config
build:
artifacts:
- image: localhost:5000/apps/demo
custom:
buildCommand: ./mvnw spring-boot:build-image -D docker.image=$IMAGE && docker push $IMAGE
dependencies:
paths:
- src
- pom.xml
deploy:
kustomize:
paths:
- "src/main/k8s/demo/"
But at the cost of having to modify the pom.xml
and add the docker.image
property:
<properties>
<java.version>1.8</java.version>
<docker.image>localhost:5000/apps/${project.artifactId}</docker.image>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<image>
<name>${docker.image}</name>
</image>
</configuration>
</plugin>
</plugins>
</build>
It would be useful to not have to make those pom.xml
changes, e.g. if Spring Boot had its own property that works as a -D
out of the box.
Comment From: wilkinsona
We should do the same for Gradle using @Option
.
Comment From: wilkinsona
https://github.com/spring-projects/spring-boot/commit/3f378e1276b300f5baca4250a89ec082e4fa2306 has taken care of the Gradle side of things.