-
Notifications
You must be signed in to change notification settings - Fork 443
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate Docker Layers for Dependencies and App jars. (#1310)
* Docker Layers separate for Dependencies and App jars. * Use indexed layers to allow flexibility * avoid mapping `dockerPackageMappings` * Calculate `dockerLayerMappings` once It is reused in Docker/stage and and Docker/dockerCommands. This intermediate step helps with cyclic dependency. * Dirty version that supports PR code review remarks * Fix chmod for layers * Revert changes around Docker / mappings * Revert changes dockerLayerMappings * Documenting `dockerLayerGrouping` * Testing layer groups * fix tests * fix more tests * Version that might pass the tests * Fix import for sbt 0.1.x * scalafmt * Experiment with Option[Int] for layer mapping * Docker tests of opt-out from layering * Test of dockerPackageMappings * Documentation
- Loading branch information
Showing
16 changed files
with
183 additions
and
48 deletions.
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
15 changes: 15 additions & 0 deletions
15
src/main/scala/com/typesafe/sbt/packager/docker/LayeredMapping.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,15 @@ | ||
package com.typesafe.sbt.packager.docker | ||
|
||
import java.io.File | ||
|
||
/** | ||
* Mapping of file to intermediate layers. | ||
* | ||
* @param layerId The identifier in the layer used to increase cache hits in | ||
* docker caching. LayerId is present in docker:stage directory structure | ||
* and in intermediate image produced in the multi-stage docker build. | ||
* None means the layering is skipped for this file. | ||
* @param file The file produced by universal/stage to be moved into `Docker / stage` directory. | ||
* @param path The path in the final image | ||
*/ | ||
case class LayeredMapping(layerId: Option[Int], file: File, path: String) |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# Generate the Docker image locally | ||
> docker:publishLocal | ||
$ exists target/docker/stage/Dockerfile | ||
$ exists target/docker/stage/opt/docker/bin/docker-exec | ||
$ exists target/docker/stage/1/opt/docker/bin/docker-exec | ||
> checkDockerfile | ||
$ exec bash -c 'docker run docker-package:0.1.0 | grep -q "Hello world"' | ||
$ exec bash -c 'docker run docker-package:0.1.0 | grep -q "Hello world"' |
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,10 @@ | ||
enablePlugins(JavaAppPackaging) | ||
|
||
organization := "com.example" | ||
name := "docker-groups" | ||
version := "0.1.0" | ||
|
||
dockerPackageMappings in Docker ++= Seq( | ||
(baseDirectory.value / "docker" / "spark-env.sh") -> "/opt/docker/spark/spark-env.sh", | ||
(baseDirectory.value / "docker" / "log4j.properties") -> "/opt/docker/spark/log4j.properties" | ||
) |
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 @@ | ||
dockerLayerGrouping in Docker := (_ => None) |
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 @@ | ||
foo=goo |
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 @@ | ||
echo "Hello!" |
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,14 @@ | ||
dockerLayerGrouping in Docker := { | ||
val dockerBaseDirectory = (defaultLinuxInstallLocation in Docker).value | ||
(path: String) => | ||
{ | ||
val pathInWorkdir = path.stripPrefix(dockerBaseDirectory) | ||
if (pathInWorkdir.startsWith(s"/lib/${organization.value}")) | ||
Some(2) | ||
else if (pathInWorkdir.startsWith("/bin/")) | ||
Some(123) | ||
else if (pathInWorkdir.startsWith("/spark/")) | ||
Some(54) | ||
else None | ||
} | ||
} |
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")) |
3 changes: 3 additions & 0 deletions
3
src/sbt-test/docker/test-layer-groups/src/main/scala/Main.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,3 @@ | ||
object Main extends App { | ||
println("Hello world") | ||
} |
Oops, something went wrong.