fabric8 docker-maven-plugin: include additional tags on build

一个人想着一个人 提交于 2021-01-28 11:23:41

问题


I have the fabric8 docker-maven-plugin configured in my pom.xml as follows:

  <build>
    ...
    <plugins>
      ...
      <plugin>
        <groupId>io.fabric8</groupId>
        <artifactId>docker-maven-plugin</artifactId>
        <version>${docker.plugin.version}</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>build</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <images>
            <image>
              <name>${docker.image.prefix}/${project.artifactId}:%l</name>
              <build>
                <dockerFile>Dockerfile</dockerFile>
                <assembly>
                  <descriptorRef>artifact</descriptorRef>
                </assembly>
              </build>
            </image>
          </images>
        </configuration>
      </plugin>
      ...
    </plugins>
    ...
  </build>

I'm using the %l placeholder which tags the image with the latest label if the version contains -SNAPSHOT, otherwise it uses the pom version. When building from CI, I'd like to include some additional tags (possibly more then one) to my image (e.g. build number / branch name) but I'd like to keep %l placeholder behavior. I think that it should be possible using maven properties from command line, but I couldn't figure it out from the plugin docs (https://dmp.fabric8.io/)

How can I include additional tags when executing the docker:build goal?


回答1:


You can use the <tags> tag:

https://dmp.fabric8.io/#build-configuration

<properties>
  ...
  <!-- set default -->
  <docker.image-tag>${project.version}</docker.image-tag>
  ...
</properties>


<image>
  ...
  <name>repo/something/%a:%l</name>
  <build>
    ...
    <tags>
      <tag>${docker.image-tag}</tag>
    </tags>
    ...
  </build>
  ...
</image>

this will tag your image with both the %l behavior and the custom set ${docker.image-tag}.

mvn docker:build -Ddocker.image-tag=mytag


来源:https://stackoverflow.com/questions/44554857/fabric8-docker-maven-plugin-include-additional-tags-on-build

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!