use of io.fabric8.docker.api.model.Image in project fabric8-maven-plugin by fabric8io.
the class ImageStreamService method appendImageStreamResource.
/**
* Save the images stream to a file
* @param imageName name of the image for which the stream should be extracted
* @param target file to store the image stream
*/
public void appendImageStreamResource(ImageName imageName, File target) throws MojoExecutionException {
String tag = Strings.isNullOrBlank(imageName.getTag()) ? "latest" : imageName.getTag();
try {
ImageStream is = new ImageStreamBuilder().withNewMetadata().withName(imageName.getSimpleName()).endMetadata().withNewSpec().addNewTag().withName(tag).withNewFrom().withKind("ImageStreamImage").endFrom().endTag().endSpec().build();
createOrUpdateImageStreamTag(client, imageName, is);
File fullTargetFile = appendImageStreamToFile(is, target);
log.info("ImageStream %s written to %s", imageName.getSimpleName(), fullTargetFile);
} catch (KubernetesClientException e) {
KubernetesResourceUtil.handleKubernetesClientException(e, this.log);
} catch (IOException e) {
throw new MojoExecutionException(String.format("Cannot write ImageStream descriptor for %s to %s : %s", imageName.getFullName(), target.getAbsoluteFile(), e.getMessage()), e);
}
}
use of io.fabric8.docker.api.model.Image in project fabric8-maven-plugin by fabric8io.
the class DockerBuildService method build.
@Override
public void build(ImageConfiguration imageConfig) throws Fabric8ServiceException {
io.fabric8.maven.docker.service.BuildService dockerBuildService = dockerServiceHub.getBuildService();
io.fabric8.maven.docker.service.BuildService.BuildContext dockerBuildContext = config.getDockerBuildContext();
try {
dockerBuildService.buildImage(imageConfig, dockerBuildContext);
// Assume we always want to tag
dockerBuildService.tagImage(imageConfig.getName(), imageConfig);
} catch (Exception ex) {
throw new Fabric8ServiceException("Error while trying to build the image", ex);
}
}
use of io.fabric8.docker.api.model.Image in project fabric8-maven-plugin by fabric8io.
the class ContainerHandlerTest method getImageNameTest.
@Test
public void getImageNameTest() {
ContainerHandler handler = new ContainerHandler(project, envVarHandler, probeHandler);
// Image Configuration with name and without registry
ImageConfiguration imageConfiguration2 = new ImageConfiguration.Builder().name("test").alias("test-app").buildConfig(buildImageConfiguration1).build();
// Image Configuration without name and with registry
ImageConfiguration imageConfiguration3 = new ImageConfiguration.Builder().alias("test-app").buildConfig(buildImageConfiguration1).registry("docker.io").build();
// Image Configuration without name and registry
ImageConfiguration imageConfiguration4 = new ImageConfiguration.Builder().alias("test-app").buildConfig(buildImageConfiguration1).build();
images.clear();
images.add(imageConfiguration1);
images.add(imageConfiguration2);
images.add(imageConfiguration3);
images.add(imageConfiguration4);
containers = handler.getContainers(config1, images);
assertEquals("docker.io/test", containers.get(0).getImage());
assertEquals("test", containers.get(1).getImage());
assertNull(containers.get(2).getImage());
assertNull(containers.get(3).getImage());
}
use of io.fabric8.docker.api.model.Image in project fabric8-maven-plugin by fabric8io.
the class ImageStreamServiceTest method simple.
@Test
public void simple() throws IOException, MojoExecutionException {
ImageStreamService service = new ImageStreamService(client, log);
final ImageStream lookedUpIs = lookupImageStream("ab12cd");
setupClientMock(lookedUpIs, "test");
ImageName name = new ImageName("test:1.0");
File target = File.createTempFile("ImageStreamServiceTest", ".yml");
service.appendImageStreamResource(name, target);
assertTrue(target.exists());
Map result = readImageStreamDescriptor(target);
Yaml yaml;
System.out.println(result.toString());
assertNotNull(result);
List<Map> items = getItemsList(result);
assertEquals(1, items.size());
Map isRead = (Map<String, Object>) items.get(0);
assertNotNull(isRead);
assertEquals("ImageStream", isRead.get("kind"));
Map spec = (Map<String, Object>) isRead.get("spec");
assertNotNull(spec);
List tags = (List) spec.get("tags");
assertNotNull(tags);
assertEquals(1, tags.size());
Map tag = (Map) tags.get(0);
Map from = (Map) tag.get("from");
assertEquals("ImageStreamImage", from.get("kind"));
assertEquals("test@ab12cd", from.get("name"));
assertEquals("default", from.get("namespace"));
// Add a second image stream
ImageStream secondIs = lookupImageStream("secondIS");
setupClientMock(secondIs, "second-test");
ImageName name2 = new ImageName("second-test:1.0");
service.appendImageStreamResource(name2, target);
result = readImageStreamDescriptor(target);
System.out.println(result.toString());
items = getItemsList(result);
assertEquals(2, items.size());
Set<String> names = new HashSet<>(Arrays.asList("second-test", "test"));
for (Map item : items) {
assertTrue(names.remove(((Map) item.get("metadata")).get("name")));
}
assertTrue(names.isEmpty());
}
use of io.fabric8.docker.api.model.Image in project fabric8-maven-plugin by fabric8io.
the class OpenshiftBuildServiceTest method checkTarPackage.
@Test
public void checkTarPackage() throws Exception {
int nTries = 0;
boolean bTestComplete = false;
do {
try {
nTries++;
BuildService.BuildServiceConfig config = defaultConfig.build();
WebServerEventCollector<OpenShiftMockServer> collector = createMockServer(config, true, 50, true, true);
OpenShiftMockServer mockServer = collector.getMockServer();
OpenShiftClient client = mockServer.createOpenShiftClient();
final OpenshiftBuildService service = new OpenshiftBuildService(client, logger, dockerServiceHub, config);
ImageConfiguration imageWithEnv = new ImageConfiguration.Builder(image).buildConfig(new BuildImageConfiguration.Builder(image.getBuildConfiguration()).env(Collections.singletonMap("FOO", "BAR")).build()).build();
service.createBuildArchive(imageWithEnv);
final List<ArchiverCustomizer> customizer = new LinkedList<>();
new Verifications() {
{
archiveService.createDockerBuildArchive(withInstanceOf(ImageConfiguration.class), withInstanceOf(MojoParameters.class), withCapture(customizer));
assertTrue(customizer.size() == 1);
}
};
customizer.get(0).customize(tarArchiver);
final List<File> file = new LinkedList<>();
new Verifications() {
{
String path;
tarArchiver.addFile(withCapture(file), path = withCapture());
assertEquals(".s2i/environment", path);
}
};
assertEquals(1, file.size());
List<String> lines;
try (FileReader reader = new FileReader(file.get(0))) {
lines = IOUtils.readLines(reader);
}
assertTrue(lines.contains("FOO=BAR"));
bTestComplete = true;
} catch (Fabric8ServiceException exception) {
Throwable rootCause = getRootCause(exception);
logger.warn("A problem encountered while running test {}, retrying..", exception.getMessage());
// Let's wait for a while, and then retry again
if (rootCause != null && rootCause instanceof IOException) {
continue;
}
}
} while (nTries < MAX_TIMEOUT_RETRIES && !bTestComplete);
}
Aggregations