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

Plugin doesn't abort building an image in case Podman is used and the Dockerfile can't be processed #1512

Closed
jh-cd opened this issue Dec 19, 2021 · 3 comments · Fixed by #1585
Assignees

Comments

@jh-cd
Copy link
Contributor

jh-cd commented Dec 19, 2021

Description

Short:

Podman's response for POST /build lacks of header "Content-Type: application/json".

Long:

When triggering a build, docker-maven-plugin sends a POST /build request and checks the response.
The response is 200 OK despite the build result, so docker-maven-plugin checks for errors in the response's content.
It does this by checking the headers for "Content-Type: application/json". If given, it checks if the response contains an "error" object. If present, docker-maven-plugin raises an exception to stop the Maven build.

The code in HcChunkedResponseHandlerWrapper is:

    public Object handleResponse(HttpResponse response) throws IOException {
        try (InputStream stream = response.getEntity().getContent()) {
            // Parse text as json
            if (isJson(response)) {
                EntityStreamReaderUtil.processJsonStream(handler, stream);
            }
        }
        return null;
    }

    private static boolean isJson(HttpResponse response) {
        return Stream.of(response.getAllHeaders())
                .filter(h -> h.getName().equalsIgnoreCase("Content-Type"))
                .anyMatch(h -> h.getValue().toLowerCase().startsWith("application/json"));
    }

And the handler BuildJsonResponseHandler is:

    public void process(JsonObject json) throws DockerAccessException {
        if (json.has("error")) {
            String msg = json.get("error").getAsString();
            String detailMsg = "";
            ...
            throw new DockerAccessException(...);
        ...

In case Podman is used, no "Content-Type: application/json" is given, nor any "Content-Type" at all. docker-maven-plugin won't parse the response-content for errors, and won't raise an exception to stop the Maven build.

A workaround is needed.

Versions

Maven:

$ mvn -v
Apache Maven 3.6.3
Maven home: /usr/share/maven
Java version: 1.8.0_312, vendor: Private Build, runtime: /usr/lib/jvm/java-8-openjdk-amd64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.11.0-43-generic", arch: "amd64", family: "unix"

Plugin:

<plugin>
    <groupId>io.fabric8</groupId>
    <artifactId>docker-maven-plugin</artifactId>
    <version>0.38.1</version>
</plugin>

Podman:

podman version 3.4.2

@jh-cd jh-cd changed the title Plugin doesn't abort the build in case the Dockerfile can't be processed when building remote Plugin doesn't abort the build when building remote in case the Dockerfile can't be processed Dec 19, 2021
@jh-cd jh-cd changed the title Plugin doesn't abort the build when building remote in case the Dockerfile can't be processed When building remote, the plugin doesn't abort the build in case the Dockerfile can't be processed Dec 20, 2021
@jh-cd jh-cd changed the title When building remote, the plugin doesn't abort the build in case the Dockerfile can't be processed Plugin doesn't abort building an image in case Podman is used and the Dockerfile can't be processed Feb 3, 2022
@rohanKanojia
Copy link
Member

@jh-cd : Hi, Do you plan to contribute a fix upstream for this issue?

@jh-cd
Copy link
Contributor Author

jh-cd commented Jul 21, 2022

@rohanKanojia Yes, I created PR #1585.

@manusa
Copy link
Member

manusa commented Jul 27, 2022

image

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

Successfully merging a pull request may close this issue.

3 participants