sbt / sbt-native-packager

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

Support ability to add docker command(s) after base image #1488

Closed pertsodian closed 2 years ago

pertsodian commented 2 years ago

Expected behaviour

Allow via settings so that we can have the following in generated Dockerfile

FROM <base_image> as mainstage
RUN microdnf update -y && microdnf clean all
<the rest>

As I understand, we need this so that we can stay up to date if there are any security updates

Actual behaviour

dockerCommands is a Seq so we can only append or prepend, or write from scratch

I would not mind writing from scratch since our use case is very simple. So I could just take the generated Dockerfile, add my favorite extra commands at my favorite spots and override the dockerCommands entirely.

However, with the multiple-layers changes, we have these /1 /2 etc. Those could look a little too raw (?), plus I'm not sure if they are subjected to be changed in subsequent versions.

Information

pertsodian commented 2 years ago

I guess the other side of the argument is to create our own base image separately, instead of calling microdnf update in every build. This sounds like better idea..

pertsodian commented 2 years ago

In case someone else runs into this, but cannot afford to manage own base image, I think this could be a good alternative:

  dockerBaseImage := "basestage",
  dockerCommands := Seq(
    Cmd("FROM", ActualBaseDockerImage, "as basestage"),
    Cmd("RUN", "microdnf update -y && microdnf clean all"),
    Cmd("")
  ) ++ dockerCommands.value