Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to #1784

Open
StFS opened this issue Apr 29, 2024 · 0 comments
Open

Ability to #1784

StFS opened this issue Apr 29, 2024 · 0 comments

Comments

@StFS
Copy link

StFS commented Apr 29, 2024

Description

I'd like to be able to re-tag a docker image that got built with multiple other repo/image:tag combos. Personally, I don't need to push all these different images to a registry, it's enough for me to just be able to define additional names for the image. However, I'd imagine that being able to push these multiple names would be beneficial to others.

In my case, this is needed because a component (module) got renamed and we want to publish the docker image under the new name but also want to publish under the legacy name for backwards compatibility. There is no differences in configuration, we just want the exact same image published under two different names.

What I've tried

I've tried defining multiple <image> tags in my project but I keep ending up with one image that works and another one that is essentially empty (~4 MB in size).

My setup is that I have a parent project with the following configuration:

...
        <plugin>
          <groupId>io.fabric8</groupId>
          <artifactId>docker-maven-plugin</artifactId>
          <version>0.43.4</version>
          <executions>
            <execution>
              <id>build_images</id>
              <phase>package</phase>
              <goals>
                <goal>build</goal>
              </goals>
            </execution>
            <execution>
              <id>push_image</id>
              <phase>install</phase>
              <goals>
                <goal>push</goal>
              </goals>
            </execution>
          </executions>
          <dependencies>
            <dependency>
              <groupId>io.fabric8</groupId>
              <artifactId>run-java-sh</artifactId>
              <version>${run-java-sh.version}</version>
            </dependency>
          </dependencies>
          <configuration>
            <images>
              <image>
                <name>${docker.repository}/%a:%v</name>
                <build>
                  <maintainer>The Eclipse Hono project</maintainer>
                  <labels>
                    <project>Eclipse Hono</project>
                  </labels>
                  <tags>
                    <tag>${docker.image.additional.tag}</tag>
                  </tags>
                  <imagePullPolicy>Always</imagePullPolicy>
                  <from>${java-base-image.name}</from>
                </build>
              </image>
            </images>
          </configuration>
        </plugin>
...

And then I have a child project with the following config:

...
  <parent>
    <groupId>org.eclipse.hono</groupId>
    <artifactId>hono-services-parent</artifactId>
    <version>2.6.0-SNAPSHOT</version>
    <relativePath>../parent</relativePath>
  </parent>
  <artifactId>hono-service-command-router-infinispan</artifactId>
...
  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>io.fabric8</groupId>
          <artifactId>docker-maven-plugin</artifactId>
          <configuration>
            <images>
              <!-- The following image gets generated correctly (around 364MB size) -->
              <image>
                <build>
                  <labels>
                    <implemented.api.1>Command Router</implemented.api.1>
                  </labels>
                  <ports>
                    <port>5671</port>
                    <port>5672</port>
                    <port>${health.check.port}</port>
                  </ports>
                </build>
              </image>
              
              <!-- The following image always gets generated "empty" (only a 4.26MB size) -->
              <image> 
                <name>${docker.repository}/hono-service-command-router:%v</name>
                <build>
                  <labels>
                    <implemented.api.1>Command Router</implemented.api.1>
                  </labels>
                  <ports>
                    <port>5671</port>
                    <port>5672</port>
                    <port>${health.check.port}</port>
                  </ports>
                </build>
              </image>
            </images>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>

  </build>

  <profiles>
    <profile>
      <id>build-docker-image</id>
      <build>
        <plugins>
          <plugin>
            <groupId>io.fabric8</groupId>
            <artifactId>docker-maven-plugin</artifactId>
          </plugin>
        </plugins>
      </build>
    </profile>

    <profile>
      <id>build-native-image</id>
      <build>
        <plugins>
          <plugin>
            <groupId>io.fabric8</groupId>
            <artifactId>docker-maven-plugin</artifactId>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

But even if defining multiple <image> blocks would produce two valid images, my guess is that they would not be the same image (that is, the second image would not be a re-tag of the first one). So even if this "worked", I would actually rather prefer being able to do it with "image name aliases".

What I would like to have

In my child project, I would like to be able to define "aliases" for the image repo/name:tag. The tag <alias> is already used so we couldn't use that, but maybe something like <image_aliases> (or whatever).

So the config for the child project would look something like this:

...
  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>io.fabric8</groupId>
          <artifactId>docker-maven-plugin</artifactId>
          <configuration>
            <images>
              <image>
                <image_aliases>
                  <image_alias>${docker.repository}/hono-service-command-router:%v</image_alias>
                  <image_alias>some.other.repo/some-other-name:v7.7.7</image_alias>
                </image_aliases>
                <build>
                  <labels>
                    <implemented.api.1>Command Router</implemented.api.1>
                  </labels>
                  <ports>
                    <port>5671</port>
                    <port>5672</port>
                    <port>${health.check.port}</port>
                  </ports>
                </build>
              </image>
            </images>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
...

And this would result in the image being built as is currently being done but then the image would additionally be tagged with ${docker.repository}/hono-service-command-router:%v and some.other.repo/some-other-name:v7.7.7.

Am I way out there with this? Does this not make any sense maybe?

Similar issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant