micronaut-maven-plugin icon indicating copy to clipboard operation
micronaut-maven-plugin copied to clipboard

Use imageName property of native-image-maven-plugin to define the Docker image name when packaging

Open ivangfr opened this issue 4 years ago • 0 comments

Hi,

After this fix https://github.com/micronaut-projects/micronaut-maven-plugin/issues/53, I've been reconfiguring my Micronaut apps and I had an idea.

What about, whenever we define explicitly the plugin org.graalvm.nativeimage:native-image-maven-plugin (maybe we need to customize something as described in the Micronaut Maven Plugin Documentation) and set the imageName property, we use the imageName to be the final name of the docker native image.

For instance, considering the piece of pom.xml below,

<artifactId>micronaut-simple-api</artifactId>
<version>1.0.0</version>
...
<properties>
	...
    <docker.image.prefix>docker.mycompany.com</docker.image.prefix>
</properties>

...
<plugins>
    <plugin>
        <groupId>io.micronaut.build</groupId>
        <artifactId>micronaut-maven-plugin</artifactId>
    </plugin>
    <plugin>
        <groupId>org.graalvm.nativeimage</groupId>
        <artifactId>native-image-maven-plugin</artifactId>
        <configuration>
            <imageName>${docker.image.prefix}/${project.artifactId}-native:${project.version}</imageName>
        </configuration>
    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
            <!-- Uncomment to enable incremental compilation -->
            <!-- <useIncrementalCompilation>false</useIncrementalCompilation> -->
            <annotationProcessorPaths combine.children="append">
                <path>
                    <groupId>io.micronaut</groupId>
                    <artifactId>micronaut-graal</artifactId>
                    <version>${micronaut.version}</version>
                </path>
            </annotationProcessorPaths>
            <compilerArgs>
                <arg>-Amicronaut.processing.group=com.mycompany.micronautsimpleapi</arg>
                <arg>-Amicronaut.processing.module=micronaut-simple-api</arg>
            </compilerArgs>
        </configuration>
    </plugin>
    <plugin>
        <groupId>com.google.cloud.tools</groupId>
        <artifactId>jib-maven-plugin</artifactId>
        <configuration>
            <to>
                <image>${docker.image.prefix}/${project.artifactId}-jvm:${project.version}</image>
            </to>
        </configuration>
    </plugin>
</plugins>
...
  • If we run ./mvnw package -Dpackaging=docker-native, we get docker.mycompany.com/micronaut-simple-api-native:1.0.0 (from native-image-maven-plugin)
  • If we run ./mvnw package -Dpackaging=docker, we get docker.mycompany.com/micronaut-simple-api-jvm:1.0.0 (from jib-maven-plugin)

Currently, it's getting the what it's defined in jib-maven-plugin property.

ivangfr avatar Dec 06 '20 15:12 ivangfr