use of io.fabric8.maven.docker.config.ImageConfiguration in project docker-maven-plugin by fabric8io.
the class PropertyConfigHandlerTest method testPortsFromConfigAndProperties.
@Test
public void testPortsFromConfigAndProperties() {
imageConfiguration = new ImageConfiguration.Builder().externalConfig(new HashMap<String, String>()).buildConfig(new BuildImageConfiguration.Builder().ports(Arrays.asList("1234")).build()).runConfig(new RunImageConfiguration.Builder().ports(Arrays.asList("jolokia.port:1234")).build()).build();
makeExternalConfigUse(PropertyMode.Override);
List<ImageConfiguration> configs = resolveImage(imageConfiguration, props("docker.name", "demo", "docker.ports.1", "9090", "docker.ports.2", "0.0.0.0:80:80", "docker.from", "busybox"));
assertEquals(1, configs.size());
RunImageConfiguration runConfig = configs.get(0).getRunConfiguration();
List<String> portsAsList = runConfig.getPorts();
String[] ports = new ArrayList<>(portsAsList).toArray(new String[portsAsList.size()]);
assertArrayEquals(new String[] { "9090", "0.0.0.0:80:80", "jolokia.port:1234" }, ports);
BuildImageConfiguration buildConfig = configs.get(0).getBuildConfiguration();
ports = new ArrayList<>(buildConfig.getPorts()).toArray(new String[buildConfig.getPorts().size()]);
assertArrayEquals(new String[] { "9090", "80", "1234" }, ports);
}
use of io.fabric8.maven.docker.config.ImageConfiguration in project docker-maven-plugin by fabric8io.
the class PropertyConfigHandlerTest method testNoOptimise.
@Test
public void testNoOptimise() throws Exception {
String[] testData = new String[] { k(ConfigKey.NAME), "image", k(ConfigKey.OPTIMISE), "false", k(ConfigKey.FROM), "base" };
ImageConfiguration config = resolveExternalImageConfig(testData);
assertEquals(false, config.getBuildConfiguration().optimise());
}
use of io.fabric8.maven.docker.config.ImageConfiguration in project fabric8-maven-plugin by fabric8io.
the class DockerBuildServiceTest method testSuccessfulBuild.
@Test
public void testSuccessfulBuild() throws Exception {
new Expectations() {
{
hub.getBuildService();
result = buildService;
}
};
final BuildService.BuildContext context = new BuildService.BuildContext.Builder().build();
final io.fabric8.maven.core.service.BuildService.BuildServiceConfig config = new io.fabric8.maven.core.service.BuildService.BuildServiceConfig.Builder().dockerBuildContext(context).build();
final String imageName = "image-name";
final ImageConfiguration image = new ImageConfiguration.Builder().name(imageName).buildConfig(new BuildImageConfiguration.Builder().from("from").build()).build();
DockerBuildService service = new DockerBuildService(hub, config);
service.build(image);
new FullVerificationsInOrder() {
{
buildService.buildImage(image, context);
buildService.tagImage(imageName, image);
}
};
}
use of io.fabric8.maven.docker.config.ImageConfiguration 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.maven.docker.config.ImageConfiguration in project fabric8-maven-plugin by fabric8io.
the class DefaultControllerEnricherTest method setupExpectations.
protected void setupExpectations(final BuildImageConfiguration buildConfig, final TreeMap controllerConfig) {
new Expectations() {
{
project.getArtifactId();
result = "fmp-controller-test";
project.getBuild().getOutputDirectory();
result = Files.createTempDir().getAbsolutePath();
context.getProject();
result = project;
context.getConfig();
result = new ProcessorConfig(null, null, Collections.singletonMap("fmp-controller", controllerConfig));
imageConfiguration.getBuildConfiguration();
result = buildConfig;
imageConfiguration.getName();
result = "helloworld";
context.getImages();
result = Arrays.asList(imageConfiguration);
}
};
}
Aggregations