-
Notifications
You must be signed in to change notification settings - Fork 441
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
[Docker] add dockerEnvVars support #1137
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6aa7e2b
add dockerEnvVars support
kimxogus bd8fa14
add sbt scripted test
kimxogus d070fa3
fix doc
kimxogus 88ea18e
scalafmt
kimxogus 639afd3
sbt 0.13.x compat, fix plugins type
kimxogus 45b2df1
add docs
kimxogus 5cf438a
scalafmt
kimxogus 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,6 @@ import com.typesafe.sbt.packager.linux.LinuxPlugin.autoImport.{daemonUser, defau | |
import com.typesafe.sbt.packager.universal.UniversalPlugin | ||
import com.typesafe.sbt.packager.universal.UniversalPlugin.autoImport.stage | ||
import com.typesafe.sbt.SbtNativePackager.Universal | ||
import com.typesafe.sbt.packager.Compat._ | ||
import com.typesafe.sbt.packager.{MappingsHelper, Stager} | ||
|
||
import scala.sys.process.Process | ||
|
@@ -61,7 +60,7 @@ object DockerPlugin extends AutoPlugin { | |
*/ | ||
val UnixSeparatorChar = '/' | ||
|
||
override def requires = UniversalPlugin | ||
override def requires: UniversalPlugin.type = UniversalPlugin | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The more generic type would be |
||
|
||
override def projectConfigurations: Seq[Configuration] = Seq(Docker) | ||
|
||
|
@@ -71,6 +70,7 @@ object DockerPlugin extends AutoPlugin { | |
dockerExposedUdpPorts := Seq(), | ||
dockerExposedVolumes := Seq(), | ||
dockerLabels := Map(), | ||
dockerEnvVars := Map(), | ||
dockerRepository := None, | ||
dockerUsername := None, | ||
dockerAlias := DockerAlias( | ||
|
@@ -104,6 +104,7 @@ object DockerPlugin extends AutoPlugin { | |
generalCommands ++ | ||
Seq(makeWorkdir(dockerBaseDirectory)) ++ makeAdd(dockerVersion.value, dockerBaseDirectory, user, group) ++ | ||
dockerLabels.value.map(makeLabel) ++ | ||
dockerEnvVars.value.map(makeEnvVar) ++ | ||
makeExposePorts(dockerExposedPorts.value, dockerExposedUdpPorts.value) ++ | ||
makeVolumes(dockerExposedVolumes.value, user, group) ++ | ||
Seq(makeUser(user), makeEntrypoint(dockerEntrypoint.value), makeCmd(dockerCmd.value)) | ||
|
@@ -175,6 +176,15 @@ object DockerPlugin extends AutoPlugin { | |
Cmd("LABEL", variable + "=\"" + value.toString + "\"") | ||
} | ||
|
||
/** | ||
* @param envVar | ||
* @return ENV command | ||
*/ | ||
private final def makeEnvVar(envVar: (String, String)): CmdLike = { | ||
val (variable, value) = envVar | ||
Cmd("ENV", variable + "=\"" + value.toString + "\"") | ||
} | ||
|
||
/** | ||
* @param dockerBaseDirectory, the installation directory | ||
*/ | ||
|
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
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,19 @@ | ||
enablePlugins(DockerPlugin) | ||
|
||
name := "simple-test" | ||
|
||
version := "0.1.0" | ||
|
||
dockerEnvVars := Map("FOO" -> "bar", "FOO_BAR" -> "foo bar", "NUMBER" -> "123") | ||
|
||
|
||
TaskKey[Unit]("checkDockerfile") := { | ||
val dockerfile = IO.read((stagingDirectory in Docker).value / "Dockerfile") | ||
|
||
assert(dockerfile contains """ENV FOO="bar"""", s"does not contain foo=bar\n$dockerfile") | ||
assert(dockerfile contains """ENV FOO_BAR="foo bar"""", s"does not contain foo=bar\n$dockerfile") | ||
assert(dockerfile contains """ENV NUMBER="123"""", s"does not contain foo=bar\n$dockerfile") | ||
|
||
streams.value.log.success("Successfully tested Dockerfile") | ||
() | ||
} |
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 @@ | ||
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % sys.props("project.version")) |
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,3 @@ | ||
# Stage the distribution and ensure files show up. | ||
> docker:stage | ||
> checkDockerfile |
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.
I'm not sure if this compiles with sbt 0.13.x