Created
May 19, 2017 15:03
-
-
Save pandaforme/e378dc3f1f32aa252b14e40937491e9c to your computer and use it in GitHub Desktop.
sbt-release integrates with sbt-docker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sbt.Keys._ | |
import sbt._ | |
import sbtdocker.DockerPlugin.autoImport._ | |
import sbtrelease.ReleasePlugin.autoImport.ReleaseTransformations._ | |
lazy val resolversSettings = ... | |
lazy val versions = ... | |
lazy val dependenciesSettings = ... | |
// Create a default Scala style task to run with compiles | |
lazy val scalastyleCompile = taskKey[Unit]("Run scalastyle before compile") | |
lazy val commonSettings = Seq( | |
scalaVersion := "2.11.8", | |
scalacOptions ++= Seq( | |
"-deprecation", | |
"-unchecked", | |
"-encoding", | |
"UTF-8", | |
"-Xlint", | |
"-Yclosure-elim", | |
"-Yinline", | |
"-Xverify", | |
"-feature", | |
"-language:postfixOps", | |
"-target:jvm-1.8" | |
), | |
resolvers ++= resolversSettings, | |
libraryDependencies ++= dependenciesSettings, | |
scalastyleCompile := scalastyle.in(Compile).toTask("").value, | |
(scalastyleConfig in Compile) := file( | |
s"${(resourceDirectory in Compile).value}/scalastyle-config.xml"), | |
(compile in Compile) <<= (compile in Compile) dependsOn scalastyleCompile | |
) ++ scalafmtSettings | |
lazy val dockerSettings = ... | |
lazy val loginAwsEcr = TaskKey[Unit]("loginAwsEcr", "Login AWS ECR") | |
loginAwsEcr := { | |
import sys.process._ | |
Seq("bash", "(aws ecr get-login --region us-west-2)") ! | |
} | |
lazy val publishDocker = ReleaseStep(action = st => { | |
val extracted = Project.extract(st) | |
val ref: ProjectRef = extracted.get(thisProjectRef) | |
extracted.runAggregated(loginAwsEcr in ref, st) | |
extracted.runAggregated( | |
sbtdocker.DockerKeys.dockerBuildAndPush in sbtdocker.DockerPlugin.autoImport.docker in ref, | |
st) | |
st | |
}) | |
lazy val releaseSettings = Seq( | |
releaseProcess := Seq[ReleaseStep]( | |
checkSnapshotDependencies, | |
inquireVersions, | |
runTest, | |
setReleaseVersion, | |
commitReleaseVersion, | |
publishDocker, | |
setNextVersion, | |
commitNextVersion | |
)) | |
lazy val root = Project( | |
id = "root", | |
base = file("."), | |
settings = commonSettings ++ dockerSettings ++ releaseSettings | |
).enablePlugins(DockerPlugin) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very helpful, thank you @pandaforme.
I had to make two changes:
imageNames in docker := Seq( ImageName( namespace = Some(s"$ecrNamespace/${organization.value}"), repository = name.value, tag = Some(version.value) ) )
lazy val loginAwsEcr = TaskKey[Unit]("loginAwsEcr", "Login AWS ECR") loginAwsEcr := { import sys.process._ val dockerLogin = Seq("aws", "ecr", "get-login", "--no-include-email", "--region", "eu-central-1").!! dockerLogin.replaceAll("\n", "").split(" ").toSeq.! }