Skip to content

Commit

Permalink
Docker build context defaults to $projectDir when no "files" are spec…
Browse files Browse the repository at this point in the history
…ified (#62), fixed #58
  • Loading branch information
stefan-huettemann authored and uschi2000 committed Aug 16, 2016
1 parent c8e5a25 commit 61fe9e0
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ automatically include outputs of task dependencies in the Docker build context.
`${projectDir}/Dockerfile`
- `dependsOn` (optional) an argument list of tasks that docker builds must depend on;
defaults to the empty set
- `files` (optional) an argument list of files to be included in the docker build context
- `files` (optional) an argument list of files to be included in the docker build context; if this parameter is omitted, all files in `${projectDir}` are included
- `buildArgs` (optional) an argument map of string to string which will set --build-arg
arguments to the docker build command; defaults to empty, which results in no --build-arg parameters
- `pull` (optional) a boolean argument which defines whether Docker should attempt to pull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,20 @@ class PalantirDockerPlugin implements Plugin<Project> {
}
}
from ext.dependencies*.outputs
from ext.resolvedFiles
if (ext.resolvedFiles) {
// provide compatibility with optional 'files' parameter:
from ext.resolvedFiles
} else {
// default: copy all files excluding the project buildDir
from(project.projectDir) {
exclude "${project.buildDir.name}"
}
}
into dockerDir
}

List<String> buildCommandLine = ['docker', 'build']
if (! ext.buildArgs.isEmpty()) {
if (!ext.buildArgs.isEmpty()) {
for (Map.Entry<String, String> buildArg : ext.buildArgs.entrySet()) {
buildCommandLine.addAll('--build-arg', "${buildArg.getKey()}=${buildArg.getValue()}")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,4 +388,34 @@ class PalantirDockerPluginTests extends AbstractPluginTest {
execCond("docker rmi -f ${id}") || true
}

def 'check files are correctly added to docker context using default'() {
given:
String id = 'id9'
String filename = "bar.txt"
temporaryFolder.newFile('Dockerfile') << """
FROM alpine:3.2
MAINTAINER ${id}
ADD ${filename} /tmp/
""".stripIndent()
buildFile << """
plugins {
id 'com.palantir.docker'
}
docker {
name '${id}'
}
""".stripIndent()
new File(projectDir, filename).createNewFile()
when:
BuildResult buildResult = with('docker').build()

then:
buildResult.task(':dockerPrepare').outcome == TaskOutcome.SUCCESS
buildResult.task(':docker').outcome == TaskOutcome.SUCCESS
exec("docker inspect --format '{{.Author}}' ${id}") == "'${id}'\n"
execCond("docker rmi -f ${id}") || true
}

}

0 comments on commit 61fe9e0

Please sign in to comment.