wiremock / wiremock-docker

Wiremock Docker image
https://hub.docker.com/r/wiremock/wiremock
MIT License
211 stars 99 forks source link

2.32.0 missing SLF4J implementation #51

Closed ascopes closed 2 years ago

ascopes commented 2 years ago

It appears both the debian-based and alpine-based container images are missing an SLF4J logger implementation on the classpath.

I understand that the non-standalone JAR of WireMock does not contain an implementation of SLF4J, but that the standalone JAR should. I assume the standalone JAR should be the one being used in this image, so I am not entirely sure what is going on.

Reproduction steps

Debian

  1. Run docker run -it --rm wiremock/wiremock:2.32.0 --verbose
  2. Observe the error in the output:
$ docker run --rm -it wiremock/wiremock:2.32.0 --verbose

2022-06-07 17:11:03.371 Verbose logging enabled
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
2022-06-07 17:11:04.138 Verbose logging enabled
 /$$      /$$ /$$                     /$$      /$$                     /$$
| $$  /$ | $$|__/                    | $$$    /$$$                    | $$
| $$ /$$$| $$ /$$  /$$$$$$   /$$$$$$ | $$$$  /$$$$  /$$$$$$   /$$$$$$$| $$   /$$
| $$/$$ $$ $$| $$ /$$__  $$ /$$__  $$| $$ $$/$$ $$ /$$__  $$ /$$_____/| $$  /$$/
| $$$$_  $$$$| $$| $$  \__/| $$$$$$$$| $$  $$$| $$| $$  \ $$| $$      | $$$$$$/
| $$$/ \  $$$| $$| $$      | $$_____/| $$\  $ | $$| $$  | $$| $$      | $$_  $$
| $$/   \  $$| $$| $$      |  $$$$$$$| $$ \/  | $$|  $$$$$$/|  $$$$$$$| $$ \  $$
|__/     \__/|__/|__/       \_______/|__/     |__/ \______/  \_______/|__/  \__/

port:                         8080
enable-browser-proxying:      false
disable-banner:               false
no-request-journal:           false
verbose:                      true

Alpine

  1. Run docker run -it --rm wiremock/wiremock:2.32.0-alpine --verbose
  2. Observe the error in the output:
$ docker run --rm -it wiremock/wiremock:2.32.0-alpine --verbose

2022-06-07 17:14:19.608 Verbose logging enabled
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
2022-06-07 17:14:20.223 Verbose logging enabled
 /$$      /$$ /$$                     /$$      /$$                     /$$
| $$  /$ | $$|__/                    | $$$    /$$$                    | $$
| $$ /$$$| $$ /$$  /$$$$$$   /$$$$$$ | $$$$  /$$$$  /$$$$$$   /$$$$$$$| $$   /$$
| $$/$$ $$ $$| $$ /$$__  $$ /$$__  $$| $$ $$/$$ $$ /$$__  $$ /$$_____/| $$  /$$/
| $$$$_  $$$$| $$| $$  \__/| $$$$$$$$| $$  $$$| $$| $$  \ $$| $$      | $$$$$$/
| $$$/ \  $$$| $$| $$      | $$_____/| $$\  $ | $$| $$  | $$| $$      | $$_  $$
| $$/   \  $$| $$| $$      |  $$$$$$$| $$ \/  | $$|  $$$$$$/|  $$$$$$$| $$ \  $$
|__/     \__/|__/|__/       \_______/|__/     |__/ \______/  \_______/|__/  \__/

port:                         8080
enable-browser-proxying:      false
disable-banner:               false
no-request-journal:           false
verbose:                      true
ascopes commented 2 years ago

Current workaround:

FROM wiremock/wiremock:latest-alpine
RUN apk add --no-cache curl \
    && curl -o /var/wiremock/lib/logback-classic.jar https://repo1.maven.org/maven2/ch/qos/logback/logback-classic/1.2.11/logback-classic-1.2.11.jar \
    && curl -o /var/wiremock/lib/logback-core.jar https://repo1.maven.org/maven2/ch/qos/logback/logback-core/1.2.11/logback-core-1.2.11.jar

With TestContainers:

    @Bean(autowireCandidate = false)
    public ImageFromDockerfile wireMockImage() {
        var jars = Map.of(
                "logback-classic.jar", "https://repo1.maven.org/maven2/ch/qos/logback/logback-classic/1.2.11/logback-classic-1.2.11.jar",
                "logback-core.jar", "https://repo1.maven.org/maven2/ch/qos/logback/logback-core/1.2.11/logback-core-1.2.11.jar"
        );
        return new ImageFromDockerfile("me/wiremock-patch-gh-51", true)
                .withDockerfileFromBuilder(bldr -> {
                    bldr.from("wiremock/wiremock:2.33.2-alpine")
                            .run("apk", "add", "-q", "--no-cache", "curl");
                    jars.forEach((target, url) -> {
                        log.info("[wiremock-docker gh-51] curl -o {} {}", target, url);
                        bldr.run("curl", "--fail", "-o", "/var/wiremock/lib/" + target, url);
                    });
                });
    }
rodolpheche commented 2 years ago

This repository only handles Docker packaging of Wiremock standalone jar.

Here is the explanation on why slf4j implementation are not included in the jar : https://github.com/wiremock/wiremock/issues/258#issuecomment-91491412

ascopes commented 2 years ago

@rodolpheche The linked issue only addresses the non-standalone JAR, not the standalone one. Those questions went unanswered since 2019, so I am still a little confused.

Should I be opening an issue on the Wiremock repository itself instead, or is it expected behaviour that the standalone copy needs additional JARs to allow logging to work correctly?

Any advice would be greatly appreciated

rodolpheche commented 2 years ago

The explanation is the same for both standalone JAR and not-standalone JAR.

You could ask to @tomakehurst but I think you'll get the same answer : those who want to get technical logs from execution should bring their own slf4j implementation