spotify / dockerfile-maven

MATURE: A set of Maven tools for dealing with Dockerfiles
Apache License 2.0
2.76k stars 494 forks source link

Incompatibility with podman-docker #370

Open adamish opened 3 years ago

adamish commented 3 years ago

Description

This lies between bug request / feature. As it stands RHEL 8 no longer supports docker, instead docker-podman is recommended. Theoretically this is a drop-in replacement for docker. However when podman is used with dockerfile-maven it fails to build images.

How to reproduce

Use dockerfile-maven plugin with docker-podman

What do you expect

Build should be success

What happened instead

Maven reports build failure stating

"java.lang.IllegalStateException: Could not acquire image ID or digest following build"

It appears underlying image build was successful...

"[INFO] Successfully built 2d636e47efb5222571aadedc23eb0419788f585cefd6186da5d25c728aafe6ca"

I've taken liberty of debugging this. The "problem" occurs in com.spotify.docker.client.messages.ProgressMessage.buildImageId() This method expects a String that starts with "Successfully built", however the string that is received contains lots of lines of data before this

--> 114aeadc56b
114aeadc56b1ba07e52ead49a69935c4cb89e44e9d7aeb86584e07c967444b4b
<various docker instructions, RUN, ADD etc>
COMMIT localhost
Successfully built 114aeadc56b1ba07e52ead49a69935c4cb89e44e9d7aeb86584e07c967444b4b

Software:

Full backtrace

Caused by: java.lang.IllegalStateException: Could not acquire image ID or digest following build
    at com.spotify.docker.client.shaded.com.google.common.base.Preconditions.checkState (Preconditions.java:444)
    at com.spotify.docker.client.DefaultDockerClient$BuildProgressHandler.getImageId (DefaultDockerClient.java:305)
    at com.spotify.docker.client.DefaultDockerClient$BuildProgressHandler.access$1200 (DefaultDockerClient.java:294)
    at com.spotify.docker.client.DefaultDockerClient.build (DefaultDockerClient.java:1501)
    at com.spotify.docker.client.DefaultDockerClient.build (DefaultDockerClient.java:1465)
    at com.spotify.plugin.dockerfile.BuildMojo.buildImage (BuildMojo.java:240)
    at com.spotify.plugin.dockerfile.BuildMojo.execute (BuildMojo.java:135)
    at com.spotify.plugin.dockerfile.AbstractDockerMojo.tryExecute (AbstractDockerMojo.java:265)
    at com.spotify.plugin.dockerfile.AbstractDockerMojo.execute (AbstractDockerMojo.java:254)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
elab commented 3 years ago

Something like that would be enough (minimal invasive):

  public String buildImageId() {
    // stream messages end with new line, so call trim to remove it
    final String stream = stream();
    if (stream == null) return null;

    String IMAGE_ID_PREFIX = "Successfully built ";
    int index = stream.indexOf(IMAGE_ID_PREFIX);
    return index >= 0
           ? stream.substring(index + IMAGE_ID_PREFIX.length()).trim()
           : null;
  }

instead of the https://github.com/spotify/docker-client/blob/v8.16.0/src/main/java/com/spotify/docker/client/messages/ProgressMessage.java#L116-L122:

  public String buildImageId() {
    // stream messages end with new line, so call trim to remove it
    final String stream = stream();
    return stream != null && stream.startsWith("Successfully built")
           ? stream.substring(stream.lastIndexOf(' ') + 1).trim()
           : null;
  }
stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.