@SuppressFBWarnings("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE")
@Override
public String build(final Path directory, final String name, final String dockerfile,
final ProgressHandler handler, final BuildParam... params)
throws DockerException, InterruptedException, IOException {
checkNotNull(handler, "handler");
WebTarget resource = noTimeoutResource().path("build");
for (final BuildParam param : params) {
resource = resource.queryParam(param.name(), param.value());
}
if (name != null) {
resource = resource.queryParam("t", name);
}
if (dockerfile != null) {
resource = resource.queryParam("dockerfile", dockerfile);
}
final RegistryConfigs registryConfigs = registryAuthSupplier.authForBuild();
final BuildProgressHandler buildHandler = new BuildProgressHandler(handler);
try (final CompressedDirectory compressedDirectory = CompressedDirectory.create(directory);
final InputStream fileStream = Files.newInputStream(compressedDirectory.file())) {
requestAndTail(POST, buildHandler, resource,
resource.request(APPLICATION_JSON_TYPE)
.header("X-Registry-Config",
authRegistryHeader(registryConfigs)),
Entity.entity(fileStream, "application/tar"));
return buildHandler.getImageId();
}
}