eclipse-jkube / jkube

Build and Deploy java applications on Kubernetes
https://www.eclipse.dev/jkube/
Eclipse Public License 2.0
775 stars 521 forks source link

JIB image build is failing if a Dockerfile is located in the root folder of the project. #970

Open sunix opened 3 years ago

sunix commented 3 years ago

Description

As a user, I would like to use the jib build strategy and not the default docker one. So when I am invoking:

mvn k8s:build  -Djkube.build.strategy=jib

It should use the jib strategy.

However if a Dockerfile is located in the root folder of the project, the error is raised:

[ERROR] Failed to execute goal org.eclipse.jkube:kubernetes-maven-plugin:1.4.0:build (default-cli) on project live-stream-question: Failed to execute the build: Error when building JIB image: Dockerfile mode is not supported with JIB build strategy -> [Help 1]

Selection_524

Info

manusa commented 3 years ago

There's a collision in mode detection here.

The Dockerfile in the root directory makes JKube assume we are running in Simple Dockerfile mode.

JIB build strategy is not compatible with (any of) the Dockerfile mode(s).

I'm not sure what the right approach here can be.

Some ideas:

sunix commented 3 years ago

My suggestion is avoid failure when possible: if the user is requesting the JIB build strategy, we have to obey and build with JIB even if the Dockerfile is not used.

It may be good to add a kind of summary at the end of the build. Something like:

[INFO] k8s:  /home/sunix/github/parisjug/live-stream-question/target/docker/java/live-stream-question/1.0.0/tmp/docker-build.tar successfully built
[INFO] k8s:  Docker image built with JIB strategy
[WARN] k8s:  Dockerfile detected but ignored as Dockerfile mode is not supported with JIB build strategy
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  16.411 s
[INFO] Finished at: 2021-10-05T09:36:45+02:00
[INFO] ------------------------------------------------------------------------
manusa commented 3 years ago

Yes, but the user might be assuming that JKube is operationg in Dockerfile mode, and it's not, which will lead them to unexpected (and maybe unpleasant) results. Thus we might want the user to opt-in to said way of working by forcing them to provide an extra-flag.

Your proposal aligns with my second suggestion "Additional warning and fall-back to next mode....", but as I say there, I find this very dangerous. We can further discuss this during triage session.

manusa commented 3 years ago

As agreed during triage meeting: