sbt / sbt-native-packager

sbt Native Packager
https://sbt-native-packager.readthedocs.io/en/stable/
BSD 2-Clause "Simplified" License
1.6k stars 441 forks source link

BUILDKIT output is logged as error #1371

Closed LeonardMeyer closed 4 years ago

LeonardMeyer commented 4 years ago

Expected behaviour

When BuildKit is used to build the docker images, lines are output to the proper log level.

Actual behaviour

When BuildKit is used to build the docker images, everything is logged using log.error(...). The problem does not come from sbt-native-packager but from BuildKit itself, which outputs most of its stuff to stderr. See this issue.

[error] #2 [internal] load .dockerignore [error] #2 transferring context: 2B done [error] #2 DONE 0.0s [error] #1 [internal] load build definition from Dockerfile [error] #1 transferring dockerfile: 8.94kB done [error] #1 DONE 0.0s [error] #3 [internal] load metadata for docker.io/library/openjdk:8-jre [error] #3 DONE 0.0s [error] #4 [internal] load metadata for docker.io/library/ubuntu:focal [error] #4 DONE 1.1s [error] #12 [internal] load build context [error] #12 DONE 0.0s [error] #5 [mainstage 1/52] FROM docker.io/library/openjdk:8-jre

Maybe we could make the publishLocalLogger used in the publishLocal task a setting ? Or Just make the DockerPlugin supports DOCKER_BUILDKIT env var ?

Information

muuki88 commented 4 years ago

Hi @LeonardMeyer Thanks for your detailed report :heart_eyes:

The output of cli tools to the wrong logger is also an issue on RPM. My understanding at the time was that rpm wrote to stderr, which causes this and there wasn't much to do, other than just sending everything to stdout, which felt wrong as stderr is supposed for errors (I guess :sweat_smile: ).

Making the logger a setting could be an option, but usually folks don't like to dig down into sbt :joy: So I would go for a "fix if DOCKER_BUILDKIT" is set. I have a feeling that this going to cause a lot of trouble either way in the future and the option to check if it's enabled or not is helpful.

What would you suggest for a fix? The simplest solution would be to "if DOCKER_BUILDKIT == 1 then log everything in stderr as info"

LeonardMeyer commented 4 years ago

Yes I was thinking of something similar. Just detect if the env var is set and change logger accordingly. I know sbt-release is using a custom logger for Git too, which exhibits the same behavior. I can put together a PR if you want, when I can find the time.

kovacshuni commented 2 years ago

Sorry I don't understand. Is there a fix for this? It's still happening to me on sbt-native-packager 1.9.11

LeonardMeyer commented 2 years ago

@kovacshuni If you've set the DOCKER_BUILDKIT to 1 it should work. Either that or something changed ?

kovacshuni commented 2 years ago

works. In my GitHub Actions I put:

    - name: Push docker image to Google Artifact Registry
      env:
        DOCKER_BUILDKIT: 1
      run: sbt Docker/publish