Question: Best approach to generating more than one dockerfile from a module?
I have a requirement to build two dockerfiles from one module. These will have different base images and various configurations.
The plugin seems to assume a singular docker artifact per module. I can do some messy stuff in sbt... that gets more and more messy by making my own set of configuration keys that mirror everything the plugin does, clones of 'docker' 'dockerBuildAndPush' etc.
That is a horrible way to go about it. Is there a better way?
I'm interested in the same question.
I've came up with following approach. Not ideal, but gets the job done:
dockerfile in docker := {
if (sys.env.get("SOME_VALUE").isDefined) {
new Dockerfile {
… // some docker file
}
} else {
new Dockerfile {
… // alternative docker file
}
}
}
Basically, in sbt you can have arbitrary code inside the task definition body. You can access environment, read settings, etc. Hope this helps.
P.S. A better way would be not to scope sbt-docker's settings and values under docker task key, but rather let them be scoped in natural sbt way. Then one could've defined e.g. custom sbt configurations to scope dockerfile, imageNames, etc.
This could also work:
import sbtdocker.DockerSettings
lazy val OtherArtifact = config("otherArtifact")
.settings(
inConfig(OtherArtifact)(DockerSettings.baseDockerSettings),
OtherArtifact / docker / imageNames := ???, // alternative image name
OtherArtifact / docker / dockerfile := ??? // alternative docker file
)
sbt OtherArtifact/docker should build alternative image whereas sbt docker should build primary one.