3

I am trying to deploy a multi-modules project using an sbt-docker plugin. I want to create separate containers for api and app modules and to skip other modules. However, every time I run docker: publish I get such an error:

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

Here is my build.sbt file:

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")))
  )

I would be very grateful for any advice on how to fix my build.sbt file to publish it to docker hub!

Cassie
  • 339
  • 1
  • 3
  • 13

1 Answers1

0

My guess would be that you have two different problems for your subprojects app and api:

1) In app, it seems like you're missing a publishTo setting. I would expect to have one, as per official SBT docs.

2) In api, there is one publishTo but it is defined within the block .settings(dockerfile in docker := {...}) so the value is not returned / assigned to your sub-project's setting. Try extracting it from there and setting up explicitly e.g. .settings(publishTo := Some(Resolver.file("Unused transient repository"...))) like as you do for the root project.

Hope that helps!

Vladimir Salin
  • 2,951
  • 2
  • 36
  • 49