-
Notifications
You must be signed in to change notification settings - Fork 445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use spotify docker-client for docker:publishLocal goal #658
Merged
+86
−1
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
83 changes: 83 additions & 0 deletions
83
src/main/scala/com/typesafe/sbt/packager/docker/DockerSpotifyClientPlugin.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.typesafe.sbt | ||
package packager | ||
package docker | ||
|
||
import java.nio.file.Paths | ||
|
||
import com.spotify.docker.client.messages.ProgressMessage | ||
import com.spotify.docker.client.{ProgressHandler, DockerClient, DefaultDockerClient} | ||
import com.spotify.docker.client.DockerClient.BuildParameter._ | ||
import sbt._ | ||
import sbt.Keys._ | ||
import packager.Keys._ | ||
import universal.UniversalPlugin.autoImport.stage | ||
|
||
|
||
/** | ||
* == DockerSpotifyClientPlugin Plugin == | ||
* | ||
* This plugin helps you build docker containers using Spotify Docker Client. | ||
* | ||
* == Configuration == | ||
* | ||
* In order to configure this plugin take a look at the available [[com.typesafe.sbt.packager.docker.DockerKeys]] | ||
* | ||
* == Requirements == | ||
* | ||
* You need docker to have docker installed on your system. | ||
* Check with a single command: | ||
* | ||
* {{{ | ||
* docker version | ||
* }}} | ||
* | ||
* | ||
* @note this plugin is not intended to build very customizable docker images, but turn your mappings | ||
* configuration in a docker image with almost no ''any'' configuration. | ||
* | ||
* @example Enable the plugin in the `build.sbt` | ||
* {{{ | ||
* enablePlugins(DockerSpotifyClientPlugin) | ||
* }}} | ||
*/ | ||
object DockerSpotifyClientPlugin extends AutoPlugin { | ||
|
||
override def requires = DockerPlugin | ||
|
||
import DockerPlugin.autoImport._ | ||
|
||
override lazy val projectSettings = inConfig(Docker)(clientSettings) | ||
|
||
def clientSettings = Seq( | ||
publishLocal := publishLocalDocker.value | ||
|
||
) | ||
|
||
def publishLocalDocker = Def.task { | ||
val context = stage.value | ||
val tag = dockerTarget.value | ||
val latest = dockerUpdateLatest.value | ||
val log = streams.value.log | ||
|
||
val dockerDirectory = context.toString | ||
val docker: DockerClient = DefaultDockerClient.fromEnv().build() | ||
|
||
log.info(s"PublishLocal using Docker API ${docker.version().apiVersion()}") | ||
|
||
val id = docker.build(Paths.get(dockerDirectory), tag, new ProgressHandler() { | ||
def progress(message: ProgressMessage) = { | ||
Option(message.error()) match { | ||
case Some(error) if error.nonEmpty => log.error(message.error()) | ||
case _ => log.info(message.stream()) | ||
} | ||
} | ||
}, FORCE_RM) | ||
|
||
if (latest) { | ||
val name = tag.substring(0, tag.lastIndexOf(":")) + ":latest" | ||
docker.tag(tag, name, true) | ||
} | ||
} | ||
|
||
|
||
} |
This file contains 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is actually not a requirement, via an env var you can just point at a remote endpoint