Skip to content

Commit

Permalink
Merge pull request #3 from Dwolla/cross-sbt
Browse files Browse the repository at this point in the history
cross-build for sbt 0.13 and 1.0
  • Loading branch information
bpholt authored Aug 28, 2017
2 parents 8d7b6d1 + fc2ace0 commit 4e56297
Show file tree
Hide file tree
Showing 13 changed files with 120 additions and 73 deletions.
41 changes: 33 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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"
34 changes: 34 additions & 0 deletions .travis/release.sh
Original file line number Diff line number Diff line change
@@ -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 "[email protected]"

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"
46 changes: 18 additions & 28 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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: _*)
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version = 0.13.12
sbt.version=0.13.16
7 changes: 3 additions & 4 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -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")
4 changes: 4 additions & 0 deletions scripted.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
scriptedLaunchOpts := { scriptedLaunchOpts.value ++
Seq("-Xmx1024M", "-XX:MaxPermSize=256M", "-Dplugin.version=" + version.value)
}
scriptedBufferLog := false
39 changes: 18 additions & 21 deletions src/main/scala/com/dwolla/sbt/docker/DockerContainerPlugin.scala
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
1 change: 1 addition & 0 deletions version.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version in ThisBuild := "1.2.12-SNAPSHOT"

0 comments on commit 4e56297

Please sign in to comment.