fabric8io docker-maven-plugin 组件和外部工件

huangapple go评论80阅读模式
英文:

fabric8io docker-maven-plugin assembly and external artifact

问题

我正尝试在Maven中创建一个Docker镜像,其中包含来自不同Maven项目的构件。但我复制的示例似乎无法正常工作。

我认为问题在于我实际上并不真正理解组件集是如何工作的,因此我正在寻求关于我想在这里做什么的帮助。我已经设置了一个人为的简单示例,说明了我要尝试做的事情:

https://github.com/sodved/java-docker-demo/tree/0.0.1-0

pom.xml
sod-java/pom.xml
sod-java/src/main/java/sodved/Sod.java
sod-docker/pom-depency.xml
sod-docker/pom.xml
sod-docker/src/main/docker/setup.sh
sod-docker/src/main/docker/Dockerfile
sod-docker/src/main/docker/run.sh

所以我的项目有两个模块:

  • sod-java:构建可执行的JAR文件(只是将一个文件写入/tmp/sod.txt
  • sod-docker:使用Dockerfile创建一个Java Alpine镜像
    • 在构建镜像时运行setup.sh,它运行Java代码以创建/tmp/sod.txt
    • run.sh是默认命令,写入/tmp/sod.txt文件的内容

到目前为止,我尝试了两种内联<assembly>的方法:

在这两种情况下,我都没有看到JAR文件被组件集复制到任何地方,也没有在Docker插件创建的tar文件中看到,因此在尝试在Dockerfile的COPY命令中引用JAR文件时会出现错误。

我知道这个示例有点人为。但它简单,并且与我们在工作中的标准方式相匹配。因此,对于工具、布局等,我没有太多的灵活性。

实际案例用于构建数据库镜像。获取基础镜像,运行Java代码以操作数据库,将其保存为新镜像以在下游使用。

简而言之:
我如何指定groupId、artifactId、version,并将相应的构件包含在我的Docker镜像中。Docker源代码本身不包含Java。

英文:

I am trying to create a docker image from within maven which includes artifacts from a different maven project. But the examples I have copied do not appear to be working.

I think the problem here is I do not really understand how assemblies work and so am asking for help on what I want to do here. I have set up a contrived simple example of what I am trying to do here:

https://github.com/sodved/java-docker-demo/tree/0.0.1-0

pom.xml
sod-java/pom.xml
sod-java/src/main/java/sodved/Sod.java
sod-docker/pom-depency.xml
sod-docker/pom.xml
sod-docker/src/main/docker/setup.sh
sod-docker/src/main/docker/Dockerfile
sod-docker/src/main/docker/run.sh

So my project has two modules:

  • sod-java which builds an executable jar (which just writes a file to /tmp/sod.txt)
  • sod-docker which creates a java alpine image with Dockerfile
    • setup.sh is run when building the image. It runs the java to create the /tmp/sod.txt
    • run.sh is the default command writes the content of the /tmp/sod.txt file

I have tried two approaches to the inline <assembly> so far:

In both cases I do not see the jar file copied anywhere by the assembly or in the tar file which the docker plugin creates and so I get an error when attempting to reference the jar in a Dockerfile COPY command.

I know the example is a bit contrived. But its simple and fitting with the standard way we do things at work. So I do not have a lot of flexibility in respect to tools, layouts etc.

The real case is used to build database images. Get base image, run java code to manipulate database, save as new image to be used downstream.

TLDR:
How can I specify a groupId, artifactId, version and have the corresponding artifact included in my docker image. The docker source itself contains no java.

答案1

得分: 0

好的,已经搞清楚了。

问题在于 pom.xml 文件中指定了一些外部配置:

<external>
    <type>properties</type>
    <prefix>docker</prefix>
    <mode>override</mode>
</external>

但是如文档所述(http://dmp.fabric8.io/#property-configuration),这意味着 pom.xml 中的 配置(包括我的汇编)将被忽略。我不确定为什么我们的标准使用了外部配置,在这个问题上我会与我们的运维人员进行沟通。但是移除这个 部分后一切正常运作。

英文:

OK, have figured it out.

The issue was that the pom.xml specified some external configuration

&lt;external&gt;
    &lt;type&gt;properties&lt;/type&gt;
    &lt;prefix&gt;docker&lt;/prefix&gt;
    &lt;mode&gt;override&lt;/mode&gt;
&lt;/external&gt;

But as the doco here (http://dmp.fabric8.io/#property-configuration) says, this means the &lt;build&gt; configuration (including my assembly) in the pom.xml will be ignored. I am not sure why our standard uses the external configuration, will chase up our ops people on that. But removing this &lt;external&gt; section and everything works.

huangapple
  • 本文由 发表于 2020年4月7日 10:26:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/61071862.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定