3

我正在尝试使用 sbt-docker 插件部署一个多模块项目。我想为 api 和 app 模块创建单独的容器并跳过其他模块。但是,每次我运行时docker: publish都会出现这样的错误:

[error] (api/*:publishConfiguration) Repository for publishing is not specified.
[error] (app/*:publishConfiguration) Repository for publishing is not specified.

这是我的 build.sbt 文件:

import sbt.Keys.publishTo

name := "project-name"

val globalSettings = Seq[SettingsDefinition](
  version := "1.0",
  scalaVersion := "2.12.4"
)

enablePlugins(DockerPlugin)

//.. other modules

val app = Project("app", file("app"))
  .enablePlugins(DockerPlugin)
  .dependsOn(repositories)
  .settings(globalSettings: _*)
  .settings(
    libraryDependencies ++= Seq(
      "com.typesafe.akka" %% "akka-http" % "10.0.11",
      "com.typesafe.akka" %% "akka-http-testkit" % "10.0.11" % Test,
      "de.heikoseeberger" %% "akka-http-circe" % "1.18.0",
      "net.ruippeixotog" %% "scala-scraper" % "2.1.0"
    ),
    resolvers += Resolver.bintrayRepo("hseeberger", "maven")
  )
  .settings(assemblyJarName in assembly := "app.jar")
  .settings(dockerfile in docker := {
    val artifact: File = assembly.value
    val artifactTargetPath = s"/app/${artifact.name}"

    new Dockerfile {
      from("java")
      add(artifact, artifactTargetPath)
      entryPoint("java", "-jar", artifactTargetPath)
    }
  },
    imageNames in docker := Seq(ImageName(s"name/dru-app"))
  )

val api = Project("api", file("api"))
  .enablePlugins(DockerPlugin)
  .dependsOn(app)
  .settings(globalSettings: _*)
  .settings(
    libraryDependencies ++= Seq(
      "com.typesafe.akka" %% "akka-http" % "10.0.11",
      "com.typesafe.akka" %% "akka-http-testkit" % "10.0.11" % Test,
      "de.heikoseeberger" %% "akka-http-circe" % "1.18.0",
      "net.ruippeixotog" %% "scala-scraper" % "2.1.0"

    ),
    resolvers += Resolver.bintrayRepo("hseeberger", "maven")
  )
  .settings(assemblyJarName in assembly := "api.jar")
  .settings(dockerfile in docker := {
    val artifact: File = assembly.value
    val artifactTargetPath = s"/api/${artifact.name}"
    publishTo := Some(Resolver.file("Unused transient repository", file("https://hub.docker.com/r/name/dru-api")))

    new Dockerfile {
      from("java")
      add(artifact, artifactTargetPath)
      entryPoint("java", "-jar", artifactTargetPath)
    }
  },
    imageNames in docker := Seq(ImageName(s"name/dru-api"))
  )


val root = Project("DRU-W3-FP-1-Toloka-Parser", file("."))
  .aggregate(app, api)
  .settings(
    publish := {},
    publishLocal := {},
    publishArtifact := false,
    publishTo := Some(Resolver.file("Unused transient repository", file("target/unusedrepo")))
  )

对于如何修复我的 build.sbt 文件以将其发布到 docker hub 的任何建议,我将不胜感激!

4

1 回答 1

0

我的猜测是您的子项目有两个不同的app问题api

1) 在app中,您似乎缺少一个publishTo设置。根据官方 SBT 文档,我希望有一个。

2) 在api中,有一个publishTo,但它是在块中定义的,.settings(dockerfile in docker := {...})因此该值不会返回/分配给您的子项目的设置。尝试从那里提取它并明确设置,例如.settings(publishTo := Some(Resolver.file("Unused transient repository"...)))像您为root项目所做的那样。

希望有帮助!

于 2019-03-22T15:41:22.423 回答