Skip to content

Commit

Permalink
fix(Docker.*?Plugin): restore the sbt-standard task concurrency tags (#…
Browse files Browse the repository at this point in the history
…1352)

"restore"-ish: sbt defines Publish and Network on both publish & publishLocal, we replace Network by Disk on publishLocal to reflect the DockerPlugin's actual resource usage
  • Loading branch information
cchepelov authored Jul 8, 2020
1 parent 07d7b84 commit 631f809
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 40 deletions.
49 changes: 29 additions & 20 deletions src/main/scala/com/typesafe/sbt/packager/docker/DockerPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,10 @@ object DockerPlugin extends AutoPlugin {

stage0 ++ stage1
}
) ++ mapGenericFilesToDocker ++ inConfig(Docker)(
Seq(
executableScriptName := executableScriptName.value,
mappings ++= dockerPackageMappings.value,
name := name.value,
packageName := packageName.value,
publishLocal := {
) ++ mapGenericFilesToDocker ++ inConfig(Docker)({

def publishLocalTask =
Def.task {
val log = streams.value.log
publishLocalDocker(
stage.value,
Expand All @@ -252,25 +249,37 @@ object DockerPlugin extends AutoPlugin {
log.info(
s"Built image ${dockerAlias.value.withTag(None).toString} with tags [${dockerAliases.value.flatMap(_.tag).mkString(", ")}]"
)
},
publish := {
} tag (Tags.Disk, Tags.Publish)

def publishTask =
Def.task {
val _ = publishLocal.value
val alias = dockerAliases.value
val log = streams.value.log
val execCommand = dockerExecCommand.value
alias.foreach { aliasValue =>
publishDocker(execCommand, aliasValue.toString, log)
}
},
clean := {
val alias = dockerAliases.value
val log = streams.value.log
val rmiCommand = dockerRmiCommand.value
// clean up images
alias.foreach { aliasValue =>
rmiDocker(rmiCommand, aliasValue.toString, log)
}
},
} tag (Tags.Network, Tags.Publish)

def cleanTask = Def.task {
val alias = dockerAliases.value
val log = streams.value.log
val rmiCommand = dockerRmiCommand.value
// clean up images
alias.foreach { aliasValue =>
rmiDocker(rmiCommand, aliasValue.toString, log)
}
}

Seq(
executableScriptName := executableScriptName.value,
mappings ++= dockerPackageMappings.value,
name := name.value,
packageName := packageName.value,
publishLocal := publishLocalTask.value,
publish := publishTask.value,
clean := cleanTask.value,
sourceDirectory := sourceDirectory.value / "docker",
stage := Stager.stage(Docker.name)(streams.value, stagingDirectory.value, dockerLayerMappings.value.map {
case LayeredMapping(layerIdx, file, path) => (file, pathInLayer(path, layerIdx))
Expand Down Expand Up @@ -308,7 +317,7 @@ object DockerPlugin extends AutoPlugin {
generateDockerConfig(dockerCommands.value, stagingDirectory.value)
}
)
)
})

/**
* @param comment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,26 +60,28 @@ object DockerSpotifyClientPlugin extends AutoPlugin {
dockerApiVersion := dockerServerApiVersion.value
)

def publishLocalDocker: Def.Initialize[Task[Unit]] = Def.task {
val context = stage.value
val primaryAlias = dockerAlias.value
val aliases = dockerAliases.value
val log = streams.value.log

val dockerDirectory = context.toString

val docker = new DockerClientTask()
docker.packageDocker(primaryAlias, aliases, dockerDirectory, log)
}

def publishDocker: Def.Initialize[Task[Unit]] = Def.task {
val _ = publishLocal.value
val aliases = dockerAliases.value
val log = streams.value.log

val docker = new DockerClientTask()
docker.publishDocker(aliases, log)
}
def publishLocalDocker: Def.Initialize[Task[Unit]] =
Def.task {
val context = stage.value
val primaryAlias = dockerAlias.value
val aliases = dockerAliases.value
val log = streams.value.log

val dockerDirectory = context.toString

val docker = new DockerClientTask()
docker.packageDocker(primaryAlias, aliases, dockerDirectory, log)
} tag (Tags.Publish, Tags.Disk)

def publishDocker: Def.Initialize[Task[Unit]] =
Def.task {
val _ = publishLocal.value
val aliases = dockerAliases.value
val log = streams.value.log

val docker = new DockerClientTask()
docker.publishDocker(aliases, log)
} tag (Tags.Network, Tags.Publish)

def dockerServerVersion: Def.Initialize[Task[Option[DockerVersion]]] = Def.task {
val docker = new DockerClientTask()
Expand Down

0 comments on commit 631f809

Please sign in to comment.