use of io.fabric8.docker.api.model.Image in project fabric8-maven-plugin by fabric8io.
the class OpenshiftBuildServiceTest method testFailedBuild.
@Test(expected = Fabric8ServiceException.class)
public void testFailedBuild() throws Exception {
BuildService.BuildServiceConfig config = defaultConfig.build();
WebServerEventCollector<OpenShiftMockServer> collector = createMockServer(config, false, 50, false, false);
OpenShiftMockServer mockServer = collector.getMockServer();
OpenShiftClient client = mockServer.createOpenShiftClient();
OpenshiftBuildService service = new OpenshiftBuildService(client, logger, dockerServiceHub, config);
service.build(image);
}
use of io.fabric8.docker.api.model.Image in project fabric8-maven-plugin by fabric8io.
the class OpenshiftBuildServiceTest method testSuccessfulSecondBuild.
@Test
public void testSuccessfulSecondBuild() 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();
OpenshiftBuildService service = new OpenshiftBuildService(client, logger, dockerServiceHub, config);
service.build(image);
assertTrue(mockServer.getRequestCount() > 8);
collector.assertEventsRecordedInOrder("build-config-check", "patch-build-config", "pushed");
collector.assertEventsNotRecorded("new-build-config");
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.docker.api.model.Image in project fabric8-maven-plugin by fabric8io.
the class OpenshiftBuildServiceTest method init.
@Before
public void init() throws Exception {
final File dockerFile = new File(baseDir, "Docker.tar");
dockerFile.getParentFile().mkdirs();
dockerFile.createNewFile();
imageStreamFile.delete();
new Expectations() {
{
dockerServiceHub.getArchiveService();
result = archiveService;
archiveService.createDockerBuildArchive(withAny(ImageConfiguration.class.cast(null)), withAny(MojoParameters.class.cast(null)));
result = dockerFile;
minTimes = 0;
project.getArtifact();
result = "myapp";
minTimes = 0;
dockerMojoParameters.getProject();
result = project;
minTimes = 0;
}
};
image = new ImageConfiguration.Builder().name(projectName).buildConfig(new BuildImageConfiguration.Builder().from(projectName).build()).build();
defaultConfig = new BuildService.BuildServiceConfig.Builder().buildDirectory(baseDir).buildRecreateMode(BuildRecreateMode.none).s2iBuildNameSuffix("-s2i-suffix2").openshiftBuildStrategy(OpenShiftBuildStrategy.s2i).dockerMojoParameters(dockerMojoParameters);
}
use of io.fabric8.docker.api.model.Image in project fabric8-maven-plugin by fabric8io.
the class DefaultControllerEnricher method addMissingResources.
@Override
public void addMissingResources(KubernetesListBuilder builder) {
final String name = getConfig(Config.name, MavenUtil.createDefaultResourceName(getProject()));
final ResourceConfig config = new ResourceConfig.Builder().controllerName(name).imagePullPolicy(getConfig(Config.pullPolicy)).withReplicas(Configs.asInt(getConfig(Config.replicaCount))).build();
final List<ImageConfiguration> images = getImages();
// Check if at least a replica set is added. If not add a default one
if (!KubernetesResourceUtil.checkForKind(builder, POD_CONTROLLER_KINDS)) {
// At least one image must be present, otherwise the resulting config will be invalid
if (!Lists.isNullOrEmpty(images)) {
String type = getConfig(Config.type);
if ("deployment".equalsIgnoreCase(type)) {
log.info("Adding a default Deployment");
builder.addToDeploymentItems(deployHandler.getDeployment(config, images));
} else if ("statefulSet".equalsIgnoreCase(type)) {
log.info("Adding a default StatefulSet");
builder.addToStatefulSetItems(statefulSetHandler.getStatefulSet(config, images));
} else if ("daemonSet".equalsIgnoreCase(type)) {
log.info("Adding a default DaemonSet");
builder.addToDaemonSetItems(daemonSetHandler.getDaemonSet(config, images));
} else if ("replicaSet".equalsIgnoreCase(type)) {
log.info("Adding a default ReplicaSet");
builder.addToReplicaSetItems(rsHandler.getReplicaSet(config, images));
} else if ("replicationController".equalsIgnoreCase(type)) {
log.info("Adding a default ReplicationController");
builder.addToReplicationControllerItems(rcHandler.getReplicationController(config, images));
} else if ("job".equalsIgnoreCase(type)) {
log.info("Adding a default Job");
builder.addToJobItems(jobHandler.getJob(config, images));
}
}
} else if (KubernetesResourceUtil.checkForKind(builder, "StatefulSet")) {
final StatefulSetSpec spec = statefulSetHandler.getStatefulSet(config, images).getSpec();
if (spec != null) {
builder.accept(new TypedVisitor<StatefulSetBuilder>() {
@Override
public void visit(StatefulSetBuilder statefulSetBuilder) {
statefulSetBuilder.editOrNewSpec().editOrNewTemplate().editOrNewSpec().endSpec().endTemplate().endSpec();
mergeStatefulSetSpec(statefulSetBuilder, spec);
}
});
if (spec.getTemplate() != null && spec.getTemplate().getSpec() != null) {
final PodSpec podSpec = spec.getTemplate().getSpec();
builder.accept(new TypedVisitor<PodSpecBuilder>() {
@Override
public void visit(PodSpecBuilder builder) {
KubernetesResourceUtil.mergePodSpec(builder, podSpec, name);
}
});
}
}
} else {
final DeploymentSpec spec = deployHandler.getDeployment(config, images).getSpec();
if (spec != null) {
builder.accept(new TypedVisitor<DeploymentBuilder>() {
@Override
public void visit(DeploymentBuilder deploymentBuilder) {
deploymentBuilder.editOrNewSpec().editOrNewTemplate().editOrNewSpec().endSpec().endTemplate().endSpec();
mergeDeploymentSpec(deploymentBuilder, spec);
}
});
if (spec.getTemplate() != null && spec.getTemplate().getSpec() != null) {
final PodSpec podSpec = spec.getTemplate().getSpec();
builder.accept(new TypedVisitor<PodSpecBuilder>() {
@Override
public void visit(PodSpecBuilder builder) {
KubernetesResourceUtil.mergePodSpec(builder, podSpec, name);
}
});
}
}
}
}
use of io.fabric8.docker.api.model.Image in project fabric8-maven-plugin by fabric8io.
the class DefaultServiceEnricher method extractPorts.
// ========================================================================================================
// Port handling
private List<ServicePort> extractPorts(List<ImageConfiguration> images) {
List<ServicePort> ret = new ArrayList<>();
boolean isMultiPort = Boolean.parseBoolean(getConfig(Config.multiPort));
List<ServicePort> configuredPorts = extractPortsFromConfig();
for (ImageConfiguration image : images) {
List<String> podPorts = getPortsFromBuildConfiguration(image);
if (podPorts.isEmpty()) {
continue;
}
// Extract first port and remove first element
addPortIfNotNull(ret, extractPortsFromImageSpec(image.getName(), podPorts.remove(0), shiftOrNull(configuredPorts)));
// Remaining port specs if multi-port is selected
if (isMultiPort) {
for (String port : podPorts) {
addPortIfNotNull(ret, extractPortsFromImageSpec(image.getName(), port, shiftOrNull(configuredPorts)));
}
}
}
// If there are still ports configured add them directly
if (isMultiPort) {
ret.addAll(mirrorMissingTargetPorts(configuredPorts));
} else if (ret.isEmpty() && !configuredPorts.isEmpty()) {
ret.addAll(mirrorMissingTargetPorts(Collections.singletonList(configuredPorts.get(0))));
}
return ret;
}
Aggregations