不要为每个 SBT 子项目发布 docker 图片
Don't publish a docker image for each SBT subproject
我有一个多项目 SBT/Play2 应用程序,我需要为主项目发布一个 Docker 图像(聚合其他项目)。
问题是 sbt-native-packager
在我的本地存储库中发布了所有 PLAY 项目的图像。根图像工作正常,但我还有 2 个不应发布的图像。
我在 plugins.sbt
中添加的内容
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.0.0-RC1")
这是我的 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"))
这就是我得到的
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
你知道如何配置sbt-native-packager
不发布这些子项目的图像吗?
感谢您的帮助:)
我也 运行 遇到了这个问题,这是对我有用的解决方案。如果查看 sbt documentation,您会看到每个任务都有一个聚合设置。因此,您只需将 docker 任务的聚合设置为 false。像这样:
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
)
还必须指定 dockerRepository
以发布到私人仓库。
lazy val dockerSettings = {
val dockerRegistry = "docker.dev.orgul.io"
Seq(
dockerBaseImage := dockerRegistry + "/java-alpine:latest",
dockerRepository := Some(dockerRegistry),
...
我有一个多项目 SBT/Play2 应用程序,我需要为主项目发布一个 Docker 图像(聚合其他项目)。
问题是 sbt-native-packager
在我的本地存储库中发布了所有 PLAY 项目的图像。根图像工作正常,但我还有 2 个不应发布的图像。
我在 plugins.sbt
中添加的内容addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.0.0-RC1")
这是我的 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"))
这就是我得到的
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
你知道如何配置sbt-native-packager
不发布这些子项目的图像吗?
感谢您的帮助:)
我也 运行 遇到了这个问题,这是对我有用的解决方案。如果查看 sbt documentation,您会看到每个任务都有一个聚合设置。因此,您只需将 docker 任务的聚合设置为 false。像这样:
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
)
还必须指定 dockerRepository
以发布到私人仓库。
lazy val dockerSettings = {
val dockerRegistry = "docker.dev.orgul.io"
Seq(
dockerBaseImage := dockerRegistry + "/java-alpine:latest",
dockerRepository := Some(dockerRegistry),
...