diff --git a/.travis.yml b/.travis.yml index b412f04..4c6a4cb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,18 +1,43 @@ services: docker -sudo: true +dist: trusty +sudo: required language: scala -scala: - - 2.10.6 +cache: + directories: + - $HOME/.ivy2/cache + - $HOME/.sbt/boot/ +before_cache: + # Tricks to avoid unnecessary cache updates + - find $HOME/.ivy2 -name "ivydata-*.properties" -delete + - find $HOME/.sbt -name "*.lock" -delete -script: sbt ++$TRAVIS_SCALA_VERSION pipeline +env: + global: + - secure: "Nw9jhj8Kt/ApiBpDuTd12Fqvs2eBspV5ZjQYsUXDipT7XzdLOhPE7WHD6xtC7X3MJRFtwXddq/Ud0NFxcqqfUwInRk51zPVoBr1eLY55Xz8ChXEmdkh/Vig1IW9YTkko5m7urPSK6zEFYdv3uTjkr6Pb1ZnVnt9mwHmLrSxP40Nremy812ZJTw7DhFf1y1/rq6EvsiBb2ifBW/vaWrSk3uWm1UAHFOP4vsuUqguamXAz2KSfxbac6aZQskHsGoc/hBGic1Kon/ZC+dexl+YEte4I56HtnddaR8dHRiKUOmf6JUck8DSJbLMEWGuzt4tVJrA7VLQo3R46QbIv1rQEPB9RVVQQs/aK9WonLrn2sIkoE7QhAKcN6YzLpCvElcl5+j2Uu6frMZUTwuxhOpKMgOZbKFqzqj2G3HaeK89dsOKHtv50T3bM61A7aHhYlN34EuiKPAriub76yzRdNUOsjz3mSfRKvEyQspgl3qVHwCaGV2ls6WlnCCVnaTW2EMuTf3WlcOUTVUG3sk8LgWNiGQ+FZx6OgeCL4XHhgSmUtpUcXuv3qkjfrtM/lp0Z+IKco8vqaXWgZkDqP49GhO5ncyPec+IcopmEZsUVlf3u++zdJbjymLuQDVruWkTkttHgyvqMpxkCTQTIbP0hMebtkzVfvVVyhfnnuwasGM3m17M=" + +matrix: + include: + - env: SBT_VERSION="0.13.16" + jdk: openjdk7 + - env: SBT_VERSION="1.0.0" + jdk: oraclejdk8 + +script: + - sbt "^^${SBT_VERSION}" pipeline before_deploy: - mkdir -p $HOME/.bintray - openssl aes-256-cbc -K $encrypted_0fde879eb030_key -iv $encrypted_0fde879eb030_iv -in .credentials.enc -out $HOME/.bintray/.credentials -d deploy: - provider: script - script: sbt publish - on: - branch: master + - provider: script + script: .travis/release.sh + on: + branch: master + condition: $SBT_VERSION == "1.0.0" && $(git log -n1 --format=format:"%an") != "Dwolla Bot" + - provider: script + script: sbt "^^${SBT_VERSION}" publish + on: + tags: true + condition: $(git log -n1 --format=format:"%an") == "Dwolla Bot" diff --git a/.travis/release.sh b/.travis/release.sh new file mode 100755 index 0000000..c6d50fd --- /dev/null +++ b/.travis/release.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +set -o errexit -o nounset + +USERNAME="Dwolla Bot" + +commit_username=$(git log -n1 --format=format:"%an") +if [[ "$commit_username" == "$USERNAME" ]]; then + echo "Refusing to release a commit created by this script." + exit 0 +fi + +if [ "$TRAVIS_BRANCH" != "master" ]; then + echo "Only the master branch will be released. This branch is $TRAVIS_BRANCH." + exit 0 +fi + +git config user.name "$USERNAME" +git config user.email "dev+dwolla-bot@dwolla.com" + +git remote add release https://$GH_TOKEN@github.com/Dwolla/sbt-docker-containers.git +git fetch release + +git clean -dxf +git checkout master +git branch --set-upstream-to=release/master + +MASTER=$(git rev-parse HEAD) +if [ "$TRAVIS_COMMIT" != "$MASTER" ]; then + echo "Checking out master set HEAD to $MASTER, but Travis was building $TRAVIS_COMMIT, so refusing to continue." + exit 0 +fi + +sbt clean "release with-defaults" diff --git a/build.sbt b/build.sbt index 2f778b5..6913e0d 100644 --- a/build.sbt +++ b/build.sbt @@ -1,30 +1,29 @@ -import java.lang.System._ - -lazy val buildVersion = { - val mainVersion = "1.2" - val minorVersion = Option(getenv("TRAVIS_BUILD_NUMBER")) - minorVersion match { - case Some(v: String) ⇒ s"$mainVersion.$v" - case None ⇒ mainVersion + "-SNAPSHOT" - } -} - -lazy val specs2Version = "3.8.5" - lazy val buildSettings = Seq( organization := "com.dwolla.sbt", name := "docker-containers", homepage := Some(url("https://github.com/Dwolla/sbt-docker-containers")), description := "SBT plugin to define and manage Docker containers based on images creating using sbt-native-packager", licenses += ("MIT", url("http://opensource.org/licenses/MIT")), - version := buildVersion, - scalaVersion := "2.10.6", + crossSbtVersions := Vector("1.0.0", "0.13.16"), sbtPlugin := true, startYear := Option(2016), - libraryDependencies ++= Seq( - "org.specs2" %% "specs2-core" % specs2Version % "test", - "org.specs2" %% "specs2-mock" % specs2Version % "test" - ) + libraryDependencies ++= { + import sbt.Defaults.sbtPluginExtra + val specs2Version = "3.8.6" + val currentSbtVersion = (sbtBinaryVersion in pluginCrossBuild).value + + Seq( + // https://github.com/sbt/sbt/issues/3393 + sbtPluginExtra("com.typesafe.sbt" % "sbt-native-packager" % "1.2.2", currentSbtVersion, scalaBinaryVersion.value), + "org.specs2" %% "specs2-core" % specs2Version % "test", + "org.specs2" %% "specs2-mock" % specs2Version % "test" + ) + }, + releaseVersionBump := sbtrelease.Version.Bump.Minor, + releaseProcess --= { + import ReleaseTransformations._ + Seq(runClean, runTest, publishArtifacts) + } ) lazy val bintraySettings = Seq( @@ -35,18 +34,9 @@ lazy val bintraySettings = Seq( pomIncludeRepository := { _ ⇒ false } ) -addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.1.4") - lazy val pipeline = InputKey[Unit]("pipeline", "Runs the full build pipeline: compile, test, integration tests") pipeline := scripted.dependsOn(test in Test).evaluated -scriptedLaunchOpts := { scriptedLaunchOpts.value ++ - Seq("-Xmx1024M", "-Dplugin.version=" + version.value) -} - -// uncomment to see sbt output for each scripted test run -//scriptedBufferLog := false - val dockerContainersPlugin = (project in file(".")) .settings(buildSettings ++ bintraySettings: _*) .settings(ScriptedPlugin.scriptedSettings: _*) diff --git a/project/build.properties b/project/build.properties index 444fa91..c091b86 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version = 0.13.12 +sbt.version=0.13.16 diff --git a/project/plugins.sbt b/project/plugins.sbt index e649d95..b08ba6a 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,7 +1,6 @@ logLevel := Level.Warn -libraryDependencies <+= sbtVersion { sv ⇒ - "org.scala-sbt" % "scripted-plugin" % sv -} +libraryDependencies += "org.scala-sbt" % "scripted-plugin" % sbtVersion.value -addSbtPlugin("me.lessis" % "bintray-sbt" % "0.3.0") +addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.5.1") +addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.6") diff --git a/scripted.sbt b/scripted.sbt new file mode 100644 index 0000000..161ffa0 --- /dev/null +++ b/scripted.sbt @@ -0,0 +1,4 @@ +scriptedLaunchOpts := { scriptedLaunchOpts.value ++ + Seq("-Xmx1024M", "-XX:MaxPermSize=256M", "-Dplugin.version=" + version.value) +} +scriptedBufferLog := false diff --git a/src/main/scala/com/dwolla/sbt/docker/DockerContainerPlugin.scala b/src/main/scala/com/dwolla/sbt/docker/DockerContainerPlugin.scala index 1d59caf..fb54916 100644 --- a/src/main/scala/com/dwolla/sbt/docker/DockerContainerPlugin.scala +++ b/src/main/scala/com/dwolla/sbt/docker/DockerContainerPlugin.scala @@ -1,12 +1,12 @@ package com.dwolla.sbt.docker +import com.dwolla.sbt.docker.model._ import com.typesafe.sbt.packager.docker.DockerPlugin -import model.{DockerCreateArguments, DockerProcessBuilder, DockerRemoveContainerArguments, DockerRemoveImageArguments, DockerStartArguments, DockerStopArguments} import sbt.Keys._ import sbt._ import scala.language.postfixOps -import util.Try +import scala.util.Try object DockerContainerPlugin extends AutoPlugin { @@ -29,27 +29,24 @@ object DockerContainerPlugin extends AutoPlugin { lazy val dockerCreateArguments = TaskKey[DockerCreateArguments]("dockerCreateArguments", "task key used internally for testing the createLocal task") in Docker lazy val dockerStartArguments = TaskKey[DockerStartArguments]("dockerStartArguments", "task key used internally for testing the startLocal task") in Docker lazy val dockerCleanArguments = TaskKey[Seq[DockerProcessBuilder]]("dockerCleanArguments", "task key used internally for testing the docker:clean task") in Docker - lazy val logger = TaskKey[Logger]("logger", "logger from streams") in Docker lazy val tasks = Seq( - logger <<= streams map { (streams) ⇒ streams.log }, - dockerCreateArguments <<= ( - name in createLocalDockerContainer, - dockerTarget in Docker, - dockerContainerMemoryLimit, - dockerContainerPortPublishing, - dockerContainerPublishAllPorts, - dockerContainerLinks, - dockerContainerAdditionalEnvironmentVariables - ) map DockerCreateArguments.fromBasicSbtTypes, - createLocalDockerContainer <<= (dockerCreateArguments, logger, publishLocal in Docker) map runDockerCreateAndReturnContainerName, - - dockerStartArguments <<= createLocalDockerContainer map DockerStartArguments.apply, - startLocalDockerContainer <<= (dockerStartArguments, logger) map runDockerProcess, - runLocalDockerContainer <<= startLocalDockerContainer, - - dockerCleanArguments <<= (name in createLocalDockerContainer, dockerTarget in Docker) map toDockerCleanProcesses, - clean in Docker <<= (dockerCleanArguments, logger, clean) map runDockerProcessesIgnoringErrors + dockerCreateArguments := DockerCreateArguments.fromBasicSbtTypes( + (name in createLocalDockerContainer).value, + dockerAlias.value.versioned, + dockerContainerMemoryLimit.value, + dockerContainerPortPublishing.value, + dockerContainerPublishAllPorts.value, + dockerContainerLinks.value, + dockerContainerAdditionalEnvironmentVariables.value), + createLocalDockerContainer := runDockerCreateAndReturnContainerName(dockerCreateArguments.value, streams.value.log, (publishLocal in Docker).value), + + dockerStartArguments := DockerStartArguments(createLocalDockerContainer.value), + startLocalDockerContainer := runDockerProcess(dockerStartArguments.value, streams.value.log), + runLocalDockerContainer := startLocalDockerContainer.value, + + dockerCleanArguments := toDockerCleanProcesses((name in createLocalDockerContainer).value, dockerAlias.value.versioned), + clean in Docker := runDockerProcessesIgnoringErrors(dockerCleanArguments.value, streams.value.log, clean.value) ) def runDockerProcess(processBuilder: DockerProcessBuilder, logger: Logger): Unit = { diff --git a/src/main/scala/com/dwolla/sbt/docker/model/DockerProcessBuilder.scala b/src/main/scala/com/dwolla/sbt/docker/model/DockerProcessBuilder.scala index c94e836..3f03b87 100644 --- a/src/main/scala/com/dwolla/sbt/docker/model/DockerProcessBuilder.scala +++ b/src/main/scala/com/dwolla/sbt/docker/model/DockerProcessBuilder.scala @@ -1,7 +1,7 @@ package com.dwolla.sbt.docker.model import com.dwolla.sbt.docker.DockerCommandLineOptions._ -import sbt.{Process, ProcessBuilder} +import scala.sys.process.{Process, ProcessBuilder} trait DockerProcessBuilder { def toDockerProcessBuilder: ProcessBuilder = Process(dockerCommand, argumentSequence) diff --git a/src/sbt-test/docker-containers/can-be-enabled-without-explicit-settings/project/build.properties b/src/sbt-test/docker-containers/can-be-enabled-without-explicit-settings/project/build.properties deleted file mode 100644 index da4bbed..0000000 --- a/src/sbt-test/docker-containers/can-be-enabled-without-explicit-settings/project/build.properties +++ /dev/null @@ -1 +0,0 @@ -sbt.version = 0.13.9 \ No newline at end of file diff --git a/src/sbt-test/docker-containers/clean-can-run-without-existing-containers/project/build.properties b/src/sbt-test/docker-containers/clean-can-run-without-existing-containers/project/build.properties deleted file mode 100644 index da4bbed..0000000 --- a/src/sbt-test/docker-containers/clean-can-run-without-existing-containers/project/build.properties +++ /dev/null @@ -1 +0,0 @@ -sbt.version = 0.13.9 \ No newline at end of file diff --git a/src/test/scala/com/dwolla/sbt/docker/DockerContainerPluginSpec.scala b/src/test/scala/com/dwolla/sbt/docker/DockerContainerPluginSpec.scala index f4ca711..fe49107 100644 --- a/src/test/scala/com/dwolla/sbt/docker/DockerContainerPluginSpec.scala +++ b/src/test/scala/com/dwolla/sbt/docker/DockerContainerPluginSpec.scala @@ -1,17 +1,16 @@ package com.dwolla.sbt.docker -import com.dwolla.sbt.docker.DockerContainerPlugin.{baseDockerContainerSettings, defaultValues, projectSettings, requires, tasks} +import com.dwolla.sbt.docker.DockerContainerPlugin._ +import com.dwolla.sbt.docker.model.DockerCreateArguments.ContainerName +import com.dwolla.sbt.docker.model._ import com.typesafe.sbt.packager.docker.DockerPlugin -import model.DockerCreateArguments.ContainerName -import model.{DockerCreateArguments, DockerProcessBuilder, DockerRemoveContainerArguments, DockerRemoveImageArguments, DockerStopArguments} import org.specs2.mock.Mockito import org.specs2.mutable.Specification import org.specs2.specification.Scope -import sbt._ +import sbt.Logger + +import scala.sys.process._ -/** - * If any of these tests fail, make sure mockito comes AFTER specs2 on the test classpath. this seems to be an issue in IntelliJ. - */ class DockerContainerPluginSpec extends Specification with Mockito { trait Setup extends Scope { diff --git a/src/test/scala/com/dwolla/sbt/docker/model/DockerProcessBuilderSpec.scala b/src/test/scala/com/dwolla/sbt/docker/model/DockerProcessBuilderSpec.scala index 431c282..59bb0d8 100644 --- a/src/test/scala/com/dwolla/sbt/docker/model/DockerProcessBuilderSpec.scala +++ b/src/test/scala/com/dwolla/sbt/docker/model/DockerProcessBuilderSpec.scala @@ -2,7 +2,7 @@ package com.dwolla.sbt.docker.model import com.dwolla.sbt.docker.DockerCommandLineOptions._ import org.specs2.mutable.Specification -import sbt.Process +import scala.sys.process.Process class DockerProcessBuilderSpec extends Specification { diff --git a/version.sbt b/version.sbt new file mode 100644 index 0000000..ff4a7c0 --- /dev/null +++ b/version.sbt @@ -0,0 +1 @@ +version in ThisBuild := "1.2.12-SNAPSHOT"