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

additions to dockerCommands are run as user #1417

Closed frankivo closed 1 year ago

frankivo commented 3 years ago

For instance: to add packages to the base image you need to be root.

Worked around this by flatMapping the dockerCommands and inserting an extra item.

dockerCommands := dockerCommands.value.flatMap {
  case Cmd("USER", args@_*) if args.contains("1001:0") => Seq(
    Cmd("RUN", "apk add --no-cache ttf-dejavu bash"),
    Cmd("USER", args: _*)
  )
  case cmd => Seq(cmd)
}

Perhaps this could be made somewhat easier/prettyer.

muuki88 commented 3 years ago

Thanks for your feature request ☺️

I'm really no expert in docker so bare with meh 😇 my assumption would be that these additions should be made somewhere else and this image should be used as a base image.

For simple testing the flatMapping is not super pretty, but okaish for testing.

frankivo commented 3 years ago

But the 1001 user comes from the docker plugin right? If not, you might be right :)

muuki88 commented 3 years ago

It does! But you can disable it if you want

Docker / daemonUserUid := None
frankivo commented 3 years ago

I don't really like any of the solutions, but I'm not sure there is a better way 🤷

cbrunnkvist commented 3 years ago

I had to use this workaround too @frankivo just in order to get something super basic like a ADD http://.. + chmod +x working AT ALL. It's really been a time-waster for me figuring why appending to dockerCommands always ends with some variation on "chmod: changing permissions of ‘/bin/whatever’: Operation not permitted`.

I think it would have be a non-issue if this pitfall was documented and dockerCommands supported a prepend operator. 😫

muuki88 commented 3 years ago

Thanks for your feedback @cbrunnkvist albight the frustration. To be honest the DockerPlugin is by far the most complex one and there are a lot of variations in docker version, docker api version, local permission setup and actual docker distribution, which makes this not a trivial thing.

SBT Native Packager has the "batteries included" approach meaning that a default setup should work out of the box. If you have any suggestions for improving the available docker settings feel I'm more than happy to discuss ideas or even better merge pull requests :D

Regarding the documentation: Please open a pull request and add this piece of information where you would have expected it :)