daniu
daniu

Reputation: 15008

Micronaut Dockerfile breaks package build

I've created a simple Micronaut application using

mn create-app app_name --build maven

with a JDK 11 in case that matters.

This creates a maven project which compiles fine, but includes a Dockerfile like this:

FROM adoptopenjdk/openjdk11-openj9:jdk-11.0.1.13-alpine-slim
COPY target/app_name*.jar app_name.jar
EXPOSE 8080
CMD java -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -Dcom.sun.management.jmxremote -noverify ${JAVA_OPTS} -jar app_name.jar

However, there is no docker build included in the Maven AFAICT.

So I included this

<plugin>
    <groupId>com.spotify</groupId>
    <artifactId>dockerfile-maven-plugin</artifactId>
    <version>${dockerfile-maven-version}</version>
    <executions>
        <execution>
            <id>default</id>
            <goals>
                <goal>build</goal>
                <goal>push</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <repository>dockerUser/app_name</repository>
        <tag>${project.version}</tag>
        <buildArgs>
            <JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
        </buildArgs>
    </configuration>
</plugin>

which does manage to build a docker image, but not without manual intervention. The reason is that upon mvn package, three jars get created in target/:

which makes the docker target fail with

When using COPY with more than one source file, the destination must be a directory and end with a /

That message does make sense because all the jars match the COPY source pattern in the Dockerfile.

Right now, I just delete the other two jars (original and shaded) and run the docker target on its own, but that's only fine as long as I work in local manual mode.

Am I missing something or is this an oversight on the Micronaut project creation?

Upvotes: 1

Views: 916

Answers (2)

Michiel
Michiel

Reputation: 3480

I can't help you with the micronaut configuration, unfortunately. However, if the purpose is to copy the main jar file and the unknown version suffix is the cause of the wildcard being used while copying, a finalName element can be added to the pom.xml in order to strip the version info from the name of the JAR file:

<build>
    <finalName>app_name</finalName>
</build>

Upvotes: 2

Related Questions