Don't publish a docker image for each SBT subproject
Asked Answered
U

2

5

I have a multi-project SBT/Play2 app, and I need to publish a Docker image for the main project (which aggregate the others).

The problem is that sbt-native-packager publish in my local repo an image for all PLAY projects. The root image works fine, but I've 2 others images which shouldn't be published.

What I've added in my plugins.sbt

addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.0.0-RC1")

And this is my build.sbt

import Dependencies.Library._
import PlayKeys._
import com.typesafe.sbt.packager.docker._

lazy val root = (project in file("."))
  .enablePlugins(PlayScala)
  .enablePlugins(DockerPlugin)
  .settings(
    packageName in Docker := "docking-station",
    version in Docker := "latest",
    NativePackagerKeys.dockerBaseImage := "dockerfile/java:oracle-java8",
    NativePackagerKeys.dockerExposedPorts := Seq(9000, 9443),
    NativePackagerKeys.dockerExposedVolumes := Seq("/opt/docker/logs"),
  )
  .dependsOn(module1).aggregate(module1)
  .dependsOn(module2).aggregate(module2)
  .dependsOn(core).aggregate(core)

lazy val module1 = (project in file("modules/1"))
  .enablePlugins(PlayScala)
  .dependsOn(core)
  .dependsOn(entities)

lazy val module2 = (project in file("modules/2"))
  .enablePlugins(PlayScala)
  .dependsOn(core)

lazy val core = (project in file("modules/core"))

And this is what I get

sbt docker:publishLocal

REPOSITORY                 TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
docking-station            latest              0d81792dd1ff        2 seconds ago       873.3 MB
module1                 0.0.1               6d73e3623d2c        3 seconds ago       810.3 MB
module2                0.0.1               c847913663c2        3 seconds ago       809.9 MB

Do you know how to configure sbt-native-packager to not publish an image for these sub-projects?

Thanks for your help :)

Upthrow answered 9/3, 2015 at 18:12 Comment(3)
Can you try to disablePlugins(DockerPlugin) on the sub-projects?Gretagretal
Already tried without success.Upthrow
Hm. I think the PlayPlugin reactivates it. The aggregate option however will run all commands on sub-projects no matter what. If you remove it, the docker image shouldn't be build, but no task will be forwarded.Gretagretal
A
9

I just ran into this problem as well, and here is the solution that worked for me. If you check out the sbt documentation you can see that there is a setting for aggregation per task. So, you just set aggregation to false for the docker tasks. Like this:

lazy val root = (project in file("."))
  .enablePlugins(PlayScala)
  .enablePlugins(DockerPlugin)
  .settings(
    packageName in Docker := "docking-station",
    version in Docker := "latest",
      NativePackagerKeys.dockerBaseImage := "dockerfile/java:oracle-java8",
      NativePackagerKeys.dockerExposedPorts := Seq(9000, 9443),
      NativePackagerKeys.dockerExposedVolumes := Seq("/opt/docker/logs"),
    )
    .dependsOn(module1).aggregate(module1)
    .dependsOn(module2).aggregate(module2)
    .dependsOn(core).aggregate(core)
    .settings(
      aggregate in Docker := false
    )
Arabeila answered 9/7, 2015 at 20:8 Comment(0)
T
0

Also had to specify the dockerRepository for publishing to a private repo.

lazy val dockerSettings = {
val dockerRegistry = "docker.dev.orgul.io"
  Seq(
   dockerBaseImage := dockerRegistry + "/java-alpine:latest",
   dockerRepository := Some(dockerRegistry),

...

Tribade answered 13/1, 2017 at 16:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.