Christian
Christian

Reputation: 147

How to tag an image with fabric8-maven-plugin?

I want to build a Docker image with the fabric8-maven-plugin and push it to a custom registry (gcr.io/<myid>/demo123). However, the maven plugin always uses the project's group/artifact id for deriving the image tag. I thought I can configure the tag manually via the <name> tag of <image>, but this doesn't work... any ideas?

Executing the maven goal fabric8:build results in

[INFO] F8: Successfully tagged example/demo:snapshot-180210-220255-0223
[INFO] F8: [example/demo:snapshot-180210-220255-0223] "spring-boot": Built image sha256:003d6
[INFO] F8: [example/demo:snapshot-180210-220255-0223] "spring-boot": Tag with latest

This is my pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>demo</name>
<description>Demo project for Spring Boot</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.10.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>io.fabric8</groupId>
            <artifactId>fabric8-maven-plugin</artifactId>
            <version>3.5.33</version>
            <configuration>
                <verbose>true</verbose>
                <images>
                    <image>
                        <name>gcr.io/myid/demo123</name>
                    </image>
                </images>
            </configuration>
            <executions>
                <execution>
                    <id>fmp</id>
                    <goals>
                        <goal>resource</goal>
                        <goal>build</goal>
                        <goal>push</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Thanks in advance!


Solution: https://github.com/fabric8io/fabric8-maven-plugin/issues/1180

Upvotes: 1

Views: 3150

Answers (2)

Huseyin Ozballar
Huseyin Ozballar

Reputation: 91

Ran into the same problem. Adding the tag build fixed it. Cannot explain why, perhaps someone else knows.

<images>
  <image>
    <name>gcr.io/myid/demo123</name>
    <build></build>
  </image>
</images>

Upvotes: 2

Piyush G
Piyush G

Reputation: 76

I configured this way in pom.xml and it worked

```

<id>buildprofile</id>
<build>
    <plugins>
        <plugin>
            <groupId>io.fabric8</groupId>
            <artifactId>fabric8-maven-plugin</artifactId>
            <version>3.5.35</version>

            <configuration>
            <images>
        <image>
          <name>{image.user}/{image.name}:{image.tag}</name>
        </image>
      </images>
    </configuration>

    <executions>
      <execution>
        <goals>
          <goal>resource</goal>
          <goal>build</goal>
        </goals>
      </execution>
    </executions>
  </plugin>
</plugins>

```

I hit mvn clean install -Pbuildprofile

Upvotes: 1

Related Questions