Skip to content

Commit

Permalink
Make dockerfile configuration a file object instead of a string (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
andybradshaw authored and uschi2000 committed Apr 5, 2017
1 parent 59ec584 commit 27a036d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 27 deletions.
6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ plugins {
}
````

Set the container name, and then optionally specify a Dockerfile path, any task
Set the container name, and then optionally specify a Dockerfile, any task
dependencies and file resources required for the Docker build. This plugin will
automatically include outputs of task dependencies in the Docker build context.

**Docker Configuration Parameters**
- `name` the name to use for this container, may include a tag
- `tags` (optional) an argument list of tags to create; any tag in `name` will
be stripped before applying a specific tag; defaults to the empty set
- `dockerfile` (optional) dockerfile to use for building the image; defaults to
`${projectDir}/Dockerfile`
- `dockerfile` (optional) the dockerfile to use for building the image; defaults to
`project.file('Dockerfile')` and must be a file object
- `files` (optional) an argument list of files to be included in the Docker build context, evaluated per `Project#files`. For example, `files tasks.distTar.outputs` adds the TAR/TGZ file produced by the `distTar` tasks, and `files tasks.distTar.outputs, 'my-file.txt'` adds the archive in addition to file `my-file.txt` from the project root directory. The specified files are collected in a Gradle CopySpec which is copied `into` the Docker build context directory. The underlying CopySpec can be used to copy entire directories into the build context, for example:
````gradle
docker {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ import org.gradle.api.file.CopySpec
class DockerExtension {
Project project

private static final String DEFAULT_DOCKERFILE_PATH = 'Dockerfile'
private String name = null
private String dockerfile = 'Dockerfile'
private File dockerfile = null
private String dockerComposeTemplate = 'docker-compose.yml.template'
private String dockerComposeFile = 'docker-compose.yml'
private Set<Task> dependencies = ImmutableSet.of()
Expand Down Expand Up @@ -57,7 +58,7 @@ class DockerExtension {
return name
}

public void setDockerfile(String dockerfile) {
public void setDockerfile(File dockerfile) {
this.dockerfile = dockerfile
}

Expand Down Expand Up @@ -119,8 +120,11 @@ class DockerExtension {
Preconditions.checkArgument(!Strings.isNullOrEmpty(name),
"name is a required docker configuration item.")

resolvedDockerfile = project.file(dockerfile)
Preconditions.checkArgument(resolvedDockerfile.exists(), "dockerfile '%s' does not exist.", dockerfile)
if (dockerfile != null) {
resolvedDockerfile = dockerfile
} else {
resolvedDockerfile = project.file(DEFAULT_DOCKERFILE_PATH)
}
resolvedDockerComposeFile = project.file(dockerComposeFile)
resolvedDockerComposeTemplate = project.file(dockerComposeTemplate)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,6 @@ class PalantirDockerPluginTests extends AbstractPluginTest {
buildResult.output.contains("name is a required docker configuration item.")
}

def 'fail with missing dockerfile'() {
given:
buildFile << '''
plugins {
id 'com.palantir.docker'
}
docker {
name 'test'
dockerfile 'missing'
}
'''.stripIndent()

when:
BuildResult buildResult = with('docker').buildAndFail()

then:
buildResult.output.contains("dockerfile 'missing' does not exist.")
}

def 'check plugin creates a docker container with default configuration'() {
given:
String id = 'id1'
Expand Down Expand Up @@ -116,7 +97,7 @@ class PalantirDockerPluginTests extends AbstractPluginTest {
docker {
name '${id}'
dockerfile 'foo'
dockerfile project.file("foo")
}
""".stripIndent()

Expand Down

0 comments on commit 27a036d

Please sign in to comment.