Skip to content

Commit

Permalink
Accept boolean typed 'pull' build param
Browse files Browse the repository at this point in the history
  • Loading branch information
gesellix committed Jan 31, 2022
1 parent cdedd4b commit bb24c07
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ public void onFinished() {
if (buildargs instanceof Map) {
buildargs = new Moshi.Builder().build().adapter(Map.class).toJson((Map) buildargs);
}
Object pull = buildParams.getOrDefault("pull", null);
if (pull instanceof Boolean) {
pull = Boolean.toString((Boolean) pull);
}

getDockerClient().build(
callback,
Expand All @@ -231,7 +235,7 @@ public void onFinished() {
tag,
(Boolean) buildParams.getOrDefault("quiet", null),
(Boolean) buildParams.getOrDefault("nocache", null),
(String) buildParams.getOrDefault("pull", null),
(String) pull,
(boolean) buildParams.getOrDefault("rm", true),
(String) buildargs,
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.gradle.testfixtures.ProjectBuilder
import org.gradle.workers.WorkQueue
import org.gradle.workers.WorkerExecutor
import spock.lang.Specification
import spock.lang.Unroll

import java.time.Duration
import java.time.temporal.ChronoUnit
Expand Down Expand Up @@ -151,6 +152,32 @@ class DockerBuildTaskSpec extends Specification {
task.outputs.files.isEmpty()
}

@Unroll
def "should accept boolean for 'pull' build param"() {
def inputStream = new FileInputStream(File.createTempFile("docker", "test"))

given:
task.buildContext = inputStream
task.buildParams = [rm: false, pull: pull, dockerfile: './custom.Dockerfile']
task.imageName = "imageName"

when:
task.build()

then:
1 * dockerClient.build(_, _,
"./custom.Dockerfile", "imageName",
null, null, pull.toString(), false,
null, null, null,
null, inputStream)

and:
task.outputs.files.isEmpty()

where:
pull << [true, false]
}

def "uses auth configs if not overridden via build options"() {
def inputStream = new FileInputStream(File.createTempFile("docker", "test"))
Map<String, AuthConfig> authConfigs = ["host.name": new AuthConfig(username: "user-name", password: "a secret")]
Expand Down

0 comments on commit bb24c07

Please sign in to comment.