use of com.spotify.docker.client.messages.ProgressMessage in project docker-client by spotify.
the class DefaultDockerClient method build.
@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);
}
// Convert auth to X-Registry-Config format
final RegistryConfigs registryConfigs = registryAuthSupplier.authForBuild();
try (final CompressedDirectory compressedDirectory = CompressedDirectory.create(directory);
final InputStream fileStream = Files.newInputStream(compressedDirectory.file());
final ProgressStream build = request(POST, ProgressStream.class, resource, resource.request(APPLICATION_JSON_TYPE).header("X-Registry-Config", authRegistryHeader(registryConfigs)), Entity.entity(fileStream, "application/tar"))) {
String imageId = null;
while (build.hasNextMessage(POST, resource.getUri())) {
final ProgressMessage message = build.nextMessage(POST, resource.getUri());
final String id = message.buildImageId();
if (id != null) {
imageId = id;
}
handler.progress(message);
}
return imageId;
}
}
use of com.spotify.docker.client.messages.ProgressMessage in project docker-client by spotify.
the class DefaultDockerClientTest method testBuildNoCache.
@Test
public void testBuildNoCache() throws Exception {
final Path dockerDirectory = getResource("dockerDirectory");
final String usingCache = "Using cache";
// Build once to make sure we have cached images.
sut.build(dockerDirectory);
// Build again and make sure we used cached image by parsing output.
final AtomicBoolean usedCache = new AtomicBoolean(false);
sut.build(dockerDirectory, "test", new ProgressHandler() {
@Override
public void progress(final ProgressMessage message) throws DockerException {
if (message.stream() != null && message.stream().contains(usingCache)) {
usedCache.set(true);
}
}
});
assertTrue(usedCache.get());
// Build again with NO_CACHE set, and verify we don't use cache.
sut.build(dockerDirectory, "test", new ProgressHandler() {
@Override
public void progress(ProgressMessage message) throws DockerException {
assertThat(message.stream(), not(containsString(usingCache)));
}
}, BuildParam.noCache());
}
use of com.spotify.docker.client.messages.ProgressMessage in project docker-client by spotify.
the class DefaultDockerClientTest method testBuildImageIdPathToDockerFile.
@Test
public void testBuildImageIdPathToDockerFile() throws Exception {
final Path dockerDirectory = getResource("dockerDirectory");
final AtomicReference<String> imageIdFromMessage = new AtomicReference<>();
final String returnedImageId = sut.build(dockerDirectory, "test", "innerDir/innerDockerfile", new ProgressHandler() {
@Override
public void progress(ProgressMessage message) throws DockerException {
final String imageId = message.buildImageId();
if (imageId != null) {
imageIdFromMessage.set(imageId);
}
}
});
assertThat(returnedImageId, is(imageIdFromMessage.get()));
}
use of com.spotify.docker.client.messages.ProgressMessage in project docker-client by spotify.
the class DefaultDockerClientTest method testGetImageIdFromBuild.
@Test
public void testGetImageIdFromBuild() {
// Include a new line because that's what docker returns.
final ProgressMessage message1 = ProgressMessage.builder().stream("Successfully built 2d6e00052167\n").build();
assertThat(message1.buildImageId(), is("2d6e00052167"));
final ProgressMessage message2 = ProgressMessage.builder().id("123").build();
assertThat(message2.buildImageId(), nullValue());
final ProgressMessage message3 = ProgressMessage.builder().stream("Step 2 : CMD[]").build();
assertThat(message3.buildImageId(), nullValue());
}
use of com.spotify.docker.client.messages.ProgressMessage in project docker-client by spotify.
the class DefaultDockerClientTest method testCustomProgressMessageHandler.
@Test
public void testCustomProgressMessageHandler() throws Exception {
final List<ProgressMessage> messages = new ArrayList<>();
sut.pull(BUSYBOX_LATEST, new ProgressHandler() {
@Override
public void progress(ProgressMessage message) throws DockerException {
messages.add(message);
}
});
// Verify that we have multiple messages, and each one has a non-null field
assertThat(messages, not(empty()));
for (final ProgressMessage message : messages) {
assertTrue(message.error() != null || message.id() != null || message.progress() != null || message.progressDetail() != null || message.status() != null || message.stream() != null);
}
}
Aggregations