英文:
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
文件的内容
- 在构建镜像时运行setup.sh,它运行Java代码以创建
到目前为止,我尝试了两种内联<assembly>
的方法:
- https://github.com/sodved/java-docker-demo/blob/0.0.1-0/sod-docker/pom-depency.xml 是我第一次尝试。在组件集中使用
dependencySet
。但我注意到依赖项甚至未包含在/target
文件夹中(我想是因为sod-docker
中没有实际的Java代码需要编译,所以依赖项没有被复制)。 - https://github.com/sodved/java-docker-demo/blob/0.0.1-0/sod-docker/pom.xml 是我第二次尝试。首先将构件明确复制到
/target
文件夹(这起作用)。然后在组件集中使用file
来尝试复制文件。
在这两种情况下,我都没有看到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
- setup.sh is run when building the image. It runs the java to create the
I have tried two approaches to the inline <assembly>
so far:
- https://github.com/sodved/java-docker-demo/blob/0.0.1-0/sod-docker/pom-depency.xml Was my first attempt. Using
dependecySet
in the assembly. But I noted that the dependency was not even included in the/target
folder (I assume because there is no actual java code to compile in sod-docker, so the dependencies were not copied). - https://github.com/sodved/java-docker-demo/blob/0.0.1-0/sod-docker/pom.xml Was my second attempt. It first explicitly copied the artifact into
/target
folder (which worked). Then usedfile
in the assembly to try and copy the file.
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
<external>
<type>properties</type>
<prefix>docker</prefix>
<mode>override</mode>
</external>
But as the doco here (http://dmp.fabric8.io/#property-configuration) says, this means the <build>
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 <external>
section and everything works.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论