Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Best approach to generating more than one dockerfile from a module? #73

Open
scottcarey opened this issue Aug 1, 2017 · 3 comments

Comments

@scottcarey
Copy link

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?

@ILLKO
Copy link

ILLKO commented Aug 9, 2017

I'm interested in the same question.

@RomanIakovlev
Copy link

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.

@argast
Copy link

argast commented Sep 13, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants