Micronaut Dockerfile 中断包构建

Micronaut Dockerfile breaks package build

我使用

创建了一个简单的 Micronaut 应用程序

mn create-app app_name --build maven

带 JDK 11 以防万一。

这将创建一个可以正常编译的 Maven 项目,但包含一个 Dockerfile,如下所示:

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

但是,Maven AFAICT 中没有 docker 构建。

所以我包括了这个

<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>

它确实设法构建了一个 docker 图像,但并非没有人工干预。原因是在 mvn package 后,在 target/ 中创建了三个 jar:

这使得 docker 目标失败

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

该消息确实有意义,因为所有 jar 都与 Dockerfile 中的 COPY 源模式相匹配。

现在,我只是删除了其他两个 jar(原始和阴影)和 运行 docker 目标,但只要我在本地手动模式下工作就可以了.

我是不是遗漏了什么,或者这是对 Micronaut 项目创建的疏忽?

很遗憾,我无法帮助您进行 micronaut 配置。但是,如果目的是复制主 jar 文件并且未知版本后缀是复制时使用通配符的原因,则可以将 finalName 元素添加到 pom.xml 以去除来自 JAR 文件名称的版本信息:

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

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

后者。

如果您在 https://github.com/micronaut-projects/micronaut-profiles/issues 提出问题,我们可以解决问题。

相关文件:

感谢您的输入。