use of io.fabric8.maven.docker.config.ImageConfiguration 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);
}
use of io.fabric8.maven.docker.config.ImageConfiguration in project fabric8-maven-plugin by fabric8io.
the class ContainerHandler method getContainerPorts.
private List<ContainerPort> getContainerPorts(ImageConfiguration imageConfig) {
BuildImageConfiguration buildConfig = imageConfig.getBuildConfiguration();
List<String> ports = buildConfig.getPorts();
if (!ports.isEmpty()) {
List<ContainerPort> ret = new ArrayList<>();
PortMapping portMapping = new PortMapping(ports, project.getProperties());
JSONArray portSpecs = portMapping.toJson();
for (int i = 0; i < portSpecs.length(); i++) {
JSONObject portSpec = portSpecs.getJSONObject(i);
ret.add(extractContainerPort(portSpec));
}
return ret;
} else {
return null;
}
}
use of io.fabric8.maven.docker.config.ImageConfiguration in project fabric8-maven-plugin by fabric8io.
the class PrometheusEnricherTest method testDetectPrometheusPort.
@Test
public void testDetectPrometheusPort() throws Exception {
final ProcessorConfig config = new ProcessorConfig(null, null, Collections.singletonMap(PrometheusEnricher.ENRICHER_NAME, new TreeMap()));
final BuildImageConfiguration imageConfig = new BuildImageConfiguration.Builder().ports(Arrays.asList(PrometheusEnricher.PROMETHEUS_PORT)).build();
// Setup mock behaviour
new Expectations() {
{
context.getConfig();
result = config;
imageConfiguration.getBuildConfiguration();
result = imageConfig;
context.getImages();
result = Arrays.asList(imageConfiguration);
}
};
PrometheusEnricher enricher = new PrometheusEnricher(context);
Map<String, String> annotations = enricher.getAnnotations(Kind.SERVICE);
assertEquals(2, annotations.size());
assertEquals("9779", annotations.get(Annotations.Management.PROMETHEUS_PORT));
assertEquals("true", annotations.get(Annotations.Management.PROMETHEUS_SCRAPE));
}
use of io.fabric8.maven.docker.config.ImageConfiguration in project fabric8-maven-plugin by fabric8io.
the class DefaultServiceEnricherTest method setupExpectations.
private void setupExpectations(final boolean withPorts, String... configParams) {
// Setup mock behaviour
final TreeMap config = new TreeMap();
for (int i = 0; i < configParams.length; i += 2) {
config.put(configParams[i], configParams[i + 1]);
}
new Expectations() {
{
context.getConfig();
result = new ProcessorConfig(null, null, Collections.singletonMap("fmp-service", config));
imageConfiguration.getBuildConfiguration();
result = getBuildConfig(withPorts);
context.getImages();
result = Arrays.asList(imageConfiguration);
}
};
}
use of io.fabric8.maven.docker.config.ImageConfiguration in project fabric8-maven-plugin by fabric8io.
the class ImageEnricher method mergeImageConfigurationWithContainerSpec.
// Add missing information to the given containers as found
// configured
private void mergeImageConfigurationWithContainerSpec(List<Container> containers) {
List<ImageConfiguration> images = getImages();
int idx = 0;
for (ImageConfiguration imageConfiguration : images) {
Container container = getContainer(idx, containers);
mergeImagePullPolicy(imageConfiguration, container);
mergeImage(imageConfiguration, container);
mergeContainerName(imageConfiguration, container);
mergeEnvVariables(container);
idx++;
}
}
Aggregations