use of com.spotify.docker.client.messages.ProgressMessage in project docker-client by spotify.
the class DefaultDockerClientTest method testBuildImageId.
@Test
public void testBuildImageId() throws Exception {
final Path dockerDirectory = getResource("dockerDirectory");
final AtomicReference<String> imageIdFromMessage = new AtomicReference<>();
final String returnedImageId = sut.build(dockerDirectory, "test", 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 testBuildNoRm.
@Test
public void testBuildNoRm() throws Exception {
final Path dockerDirectory = getResource("dockerDirectory");
final String removingContainers = "Removing intermediate container";
// Test that intermediate containers are removed with FORCE_RM by parsing output. We must
// set NO_CACHE so that docker will generate some containers to remove.
final AtomicBoolean removedContainer = new AtomicBoolean(false);
sut.build(dockerDirectory, "test", new ProgressHandler() {
@Override
public void progress(ProgressMessage message) throws DockerException {
if (containsIgnoreCase(message.stream(), removingContainers)) {
removedContainer.set(true);
}
}
}, BuildParam.noCache(), BuildParam.forceRm());
assertTrue(removedContainer.get());
// Set NO_RM and verify we don't get message that containers were removed.
sut.build(dockerDirectory, "test", new ProgressHandler() {
@Override
public void progress(ProgressMessage message) throws DockerException {
assertThat(message.stream(), not(containsString(removingContainers)));
}
}, BuildParam.noCache(), BuildParam.rm(false));
}
use of com.spotify.docker.client.messages.ProgressMessage in project docker-client by spotify.
the class DefaultDockerClientTest method testLoad.
@Test
public void testLoad() throws Exception {
// Ensure the local Docker instance has the busybox image so that save() will work
sut.pull(BUSYBOX_LATEST);
// duplicate busybox with another name
final String image1 = BUSYBOX + "test1" + System.nanoTime() + ":latest";
final String image2 = BUSYBOX + "test2" + System.nanoTime() + ":latest";
try (InputStream imagePayload = new BufferedInputStream(new FileInputStream(save(BUSYBOX_LATEST)))) {
sut.create(image1, imagePayload);
}
try (InputStream imagePayload = new BufferedInputStream(new FileInputStream(save(BUSYBOX_LATEST)))) {
sut.create(image2, imagePayload);
}
final File imagesFile = save(image1, image2);
// Remove image from the local Docker instance to test the load
sut.removeImage(image1);
sut.removeImage(image2);
// Try to inspect deleted images and make sure ImageNotFoundException is thrown
try {
sut.inspectImage(image1);
fail("inspectImage should have thrown ImageNotFoundException");
} catch (ImageNotFoundException e) {
// we should get exception because we deleted image
}
try {
sut.inspectImage(image2);
fail("inspectImage should have thrown ImageNotFoundException");
} catch (ImageNotFoundException e) {
// we should get exception because we deleted image
}
final List<ProgressMessage> messages = new ArrayList<>();
final Set<String> loadedImages;
try (InputStream imageFileInputStream = new FileInputStream(imagesFile)) {
loadedImages = sut.load(imageFileInputStream, new ProgressHandler() {
@Override
public void progress(ProgressMessage message) throws DockerException {
messages.add(message);
}
});
}
if (dockerApiVersionAtLeast("1.24")) {
// Verify that both images are loaded
assertEquals(loadedImages.size(), 2);
assertTrue(loadedImages.contains(image1));
assertTrue(loadedImages.contains(image2));
}
if (dockerApiVersionAtLeast("1.23")) {
// 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);
}
}
// Try to inspect created images and make sure ImageNotFoundException is not thrown
try {
sut.inspectImage(image1);
sut.inspectImage(image2);
} catch (ImageNotFoundException e) {
fail("image not properly loaded in the local Docker instance");
}
// Clean created image
sut.removeImage(image1);
sut.removeImage(image2);
}
use of com.spotify.docker.client.messages.ProgressMessage in project docker-client by spotify.
the class DefaultDockerClientTest method testBuildWithPull.
@Test
public void testBuildWithPull() throws Exception {
requireDockerApiVersionAtLeast("1.19", "build with pull");
final Path dockerDirectory = getResource("dockerDirectory");
final String pullMsg = "Pulling from";
// Build once to make sure we have cached images.
sut.build(dockerDirectory);
// Build again with PULL set, and verify we pulled the base image
final AtomicBoolean pulled = new AtomicBoolean(false);
sut.build(dockerDirectory, "test", new ProgressHandler() {
@Override
public void progress(ProgressMessage message) throws DockerException {
if (!isNullOrEmpty(message.status()) && message.status().contains(pullMsg)) {
pulled.set(true);
}
}
}, BuildParam.pullNewerImage());
assertTrue(pulled.get());
}
use of com.spotify.docker.client.messages.ProgressMessage in project docker-client by spotify.
the class DefaultDockerClientTest method testBuildImageIdWithAuth.
@Test
public void testBuildImageIdWithAuth() throws Exception {
final Path dockerDirectory = getResource("dockerDirectory");
final AtomicReference<String> imageIdFromMessage = new AtomicReference<>();
final RegistryAuth registryAuth = RegistryAuth.builder().username(AUTH_USERNAME).password(AUTH_PASSWORD).build();
final DockerClient sut2 = DefaultDockerClient.fromEnv().registryAuthSupplier(new FixedRegistryAuthSupplier(registryAuth, RegistryConfigs.create(singletonMap("", registryAuth)))).build();
final String returnedImageId = sut2.build(dockerDirectory, "test", 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()));
}
Aggregations