docker-maven-plugin icon indicating copy to clipboard operation
docker-maven-plugin copied to clipboard

When deployAtEnd is set, d-m-p should push docker images after a multi-module build

Open sparsick opened this issue 5 years ago • 12 comments

Description

The idea is cloned from maven-deploy-plugin. When the user property deployAtEnd is set, d-m-p should push all Docker images at the end of multi module build. These docker images are created during this multi module build.

  • If it's a feature request, what is your use case : In a CI build I want to ensure that the multi module build runs successfully before the docker images are pushed to the registry.

Workaround:

mvn deploy -DdeployAtEnd -Ddocker.skip.push
mvn docker:push

I think it's relate to #745

sparsick avatar Sep 20 '19 10:09 sparsick

I see the use case, but how would a parent pom know which images to push ? 'would have to check how the deploy plugin deals with this and maybe one can also already achieve that with d-m-p with some clever lifecycle bindings, so that the sub-modules push e.g. on the postInstall phase (which is reached only when the build doesn't break before.

rhuss avatar Oct 08 '19 15:10 rhuss

I discussed the solution of the deploy plugin with @khmarbaise. He recommends me to use the Maven deployer extension for this use case in deploy plugin. Maybe for this issue it would be a good idea to write a docker push extension. What do you think?

sparsick avatar Nov 06 '19 16:11 sparsick

I'm not very familiar with extensions, but sounds like a good idea ;-) Such an extension then could pick up all images to push at the end of the whole run.

I would happy to help to integrate any PR which goes in this direction.

rhuss avatar Nov 21 '19 08:11 rhuss

Yes, please please make it work, it is very much needed :). We often have this kind of structure

Parent-Aggregator |-- Module A (e.g. a common Business API) |-- Module B, depends on A, defines image X |-- Module C, depends on A, defines image Y |-- Module D, product assembly, defines E2E tests and runs them utilizing images. Defines E2E test image

We usually only ever want to push images, after all E2E Tests were done.

MariusSchmidt avatar Apr 28 '20 16:04 MariusSchmidt

I started a PoC for this issue.

Currently, test infrastructure and the skeleton is set up.

sparsick avatar May 17 '20 19:05 sparsick

I release the first version of the Maven Extension. It is available in Maven Central

sparsick avatar Jul 06 '20 05:07 sparsick

This is a great idea, but I see that both this plugin and its inspiration plugin are in the POC Phase. Any plans to make either of these extensions production-ready, or push the change upstream to the modified plugins?

tpischke-bedag avatar Jun 30 '21 09:06 tpischke-bedag

@tpischke-bedag Could you test the current release version of the Maven extension and give me feedback if it works in your use case? IMHO there are some dependencies clean-ups to do. If it is better for the community, I can move the Maven extension to this project (@rhuss what do you think?). But we cannot merge it with the plugin because a Maven extension is a separate concept towards a Maven plugin.

sparsick avatar Jun 30 '21 09:06 sparsick

Thus looks promising, but of course, there's always something new to deal with – in particular, some users are likely to move away from fabric8 and to https://www.eclipse.org/jkube/ , which is apparently its designated successor. But that can be dealt with later.

TIBCOrkrajews avatar Jun 30 '21 13:06 TIBCOrkrajews

@TIBCOrkrajews : JKube is the successor to Fabric8 Maven Plugin not Docker Maven Plugin. It's applicable for users who are working with Kubernetes. This project is still alive and maintained.

rohanKanojia avatar Jun 30 '21 13:06 rohanKanojia

@tpischke-bedag Could you test the current release version of the Maven extension and give me feedback if it works in your use case? IMHO there are some dependencies clean-ups to do. If it is better for the community, I can move the Maven extension to this project (@rhuss what do you think?). But we cannot merge it with the plugin because a Maven extension is a separate concept towards a Maven plugin.

We solved this by adding a dedicated deployment maven Module for the moment, but we will try testing this and providing feedback hopefully soon.

tpischke-bedag avatar Jul 01 '21 07:07 tpischke-bedag

@tpischke-bedag Could you test the current release version of the Maven extension and give me feedback if it works in your use case? IMHO there are some dependencies clean-ups to do. If it is better for the community, I can move the Maven extension to this project (@rhuss what do you think?). But we cannot merge it with the plugin because a Maven extension is a separate concept towards a Maven plugin.

During testing, I get the following error at the end of the build: build 01-Jul-2021 13:25:08 [WARNING] Failed to notify spy com.github.sparsick.maven.docker.extension.DockerPushExtension: {"message":"invalid reference format"}

The push works normally when the extension is not active. The image name is composed using some maven properties, maybe they are not being resolved correctly?

<name>registry.example.com/${docker.namespace}/backend:git-commit-id_${git.commit.id}</name>

My suspicion is that the following code does not allow for interpolation of maven properties in the image name:

 private void parseDockerImageName(Object configuration) {
        LOGGER.debug("Configuration: {}", configuration);

        // this is necessary because cast throw an exception "incompatible type"
        Xpp3Dom dom = Xpp3DomBuilder.build(new StringReader(configuration.toString()));
        dockerImageNames.addAll(Arrays.stream(dom.getChild("images").getChildren("image")).map(image -> image.getChild("name").getValue()).collect(Collectors.toSet()));
        LOGGER.info("Found docker image names: {}", dockerImageNames);
    }

I haven't been able to get the extension to log any debug information, even with the maven -X flag, is there some trick to turn on the logging?

Added an issue in the project: https://github.com/sparsick/maven-docker-extension/issues/40

tpischke-bedag avatar Jul 01 '21 10:07 tpischke-bedag