use of io.fabric8.maven.docker.config.CopyConfiguration.Builder in project fabric8-maven-plugin by fabric8io.
the class ResourceMojo method generateResources.
private KubernetesList generateResources(List<ImageConfiguration> images) throws IOException, MojoExecutionException {
// Manager for calling enrichers.
openshiftDependencyResources = new OpenShiftDependencyResources(log);
loadOpenShiftOverrideResources();
EnricherContext.Builder ctxBuilder = new EnricherContext.Builder().project(project).session(session).goalFinder(goalFinder).config(extractEnricherConfig()).resources(resources).images(resolvedImages).log(log).useProjectClasspath(useProjectClasspath).openshiftDependencyResources(openshiftDependencyResources);
if (resources != null) {
ctxBuilder.namespace(resources.getNamespace());
}
EnricherManager enricherManager = new EnricherManager(resources, ctxBuilder.build());
// Generate all resources from the main resource diretory, configuration and enrich them accordingly
KubernetesListBuilder builder = generateAppResources(images, enricherManager);
// Add resources found in subdirectories of resourceDir, with a certain profile
// applied
addProfiledResourcesFromSubirectories(builder, resourceDir, enricherManager);
return builder.build();
}
use of io.fabric8.maven.docker.config.CopyConfiguration.Builder in project fabric8-maven-plugin by fabric8io.
the class PodAnnotationEnricher method adapt.
@Override
public void adapt(KubernetesListBuilder builder) {
super.adapt(builder);
List<HasMetadata> items = builder.getItems();
for (HasMetadata item : items) {
if (item instanceof Deployment) {
Deployment deployment = (Deployment) item;
ObjectMeta metadata = deployment.getMetadata();
DeploymentSpec spec = deployment.getSpec();
if (metadata != null && spec != null) {
PodTemplateSpec template = spec.getTemplate();
if (template != null) {
ObjectMeta templateMetadata = template.getMetadata();
if (templateMetadata == null) {
templateMetadata = new ObjectMeta();
template.setMetadata(templateMetadata);
}
templateMetadata.setAnnotations(MapUtil.mergeMaps(templateMetadata.getAnnotations(), metadata.getAnnotations()));
}
}
}
}
builder.withItems(items);
}
use of io.fabric8.maven.docker.config.CopyConfiguration.Builder in project fabric8-maven-plugin by fabric8io.
the class DockerRegistrySecretEnricherTest method testDockerRegistryWithBadAnnotation.
@Test
public void testDockerRegistryWithBadAnnotation() {
DockerRegistrySecretEnricher enricher = new DockerRegistrySecretEnricher(context);
new Expectations() {
{
{
context.getSettings();
returns(new Settings());
}
}
};
KubernetesListBuilder builder = new KubernetesListBuilder();
Secret secret = createBaseSecret(true);
secret.getMetadata().getAnnotations().put(annotation, "docker1.io");
builder.addToSecretItems(createBaseSecret(true));
KubernetesList expected = builder.build();
enricher.addMissingResources(builder);
assertEquals(expected, builder.build());
}
use of io.fabric8.maven.docker.config.CopyConfiguration.Builder in project fabric8-maven-plugin by fabric8io.
the class DockerRegistrySecretEnricherTest method testDockerRegistry.
@Test
public void testDockerRegistry() {
new Expectations() {
{
{
context.getSettings();
result = createSettings();
}
}
};
DockerRegistrySecretEnricher enricher = new DockerRegistrySecretEnricher(context);
KubernetesListBuilder builder = new KubernetesListBuilder();
builder.addToSecretItems(createBaseSecret(true));
enricher.addMissingResources(builder);
KubernetesListBuilder expectedBuilder = new KubernetesListBuilder();
Secret expectedSecret = createBaseSecret(false);
expectedSecret.getData().put(SecretConstants.DOCKER_DATA_KEY, "eyJkb2NrZXIuaW8iOnsicGFzc3dvcmQiOiJwYXNzd29yZCIsImVtYWlsIjoiZm9vQGZvby5jb20iLCJ1c2VybmFtZSI6InVzZXJuYW1lIn19");
expectedBuilder.addToSecretItems(expectedSecret);
assertEquals(expectedBuilder.build(), builder.build());
}
use of io.fabric8.maven.docker.config.CopyConfiguration.Builder in project fabric8-maven-plugin by fabric8io.
the class BaseGenerator method addFrom.
/**
* Add the base image either from configuration or from a given selector
*
* @param builder for the build image configuration to add the from to.
*/
protected void addFrom(BuildImageConfiguration.Builder builder) {
String fromMode = getConfigWithSystemFallbackAndDefault(Config.fromMode, "fabric8.generator.fromMode", getFromModeDefault(context.getMode()));
String from = getConfigWithSystemFallbackAndDefault(Config.from, "fabric8.generator.from", null);
if ("docker".equalsIgnoreCase(fromMode)) {
String fromImage = from;
if (fromImage == null) {
fromImage = fromSelector != null ? fromSelector.getFrom() : null;
}
builder.from(fromImage);
log.info("Using Docker image %s as base / builder", fromImage);
} else if ("istag".equalsIgnoreCase(fromMode)) {
Map<String, String> fromExt = new HashMap<>();
if (from != null) {
ImageName iName = new ImageName(from);
// user/project is considered to be the namespace
String tag = iName.getTag();
if (StringUtils.isBlank(tag)) {
tag = "latest";
}
fromExt.put(OpenShiftBuildStrategy.SourceStrategy.name.key(), iName.getSimpleName() + ":" + tag);
if (iName.getUser() != null) {
fromExt.put(OpenShiftBuildStrategy.SourceStrategy.namespace.key(), iName.getUser());
}
fromExt.put(OpenShiftBuildStrategy.SourceStrategy.kind.key(), "ImageStreamTag");
} else {
fromExt = fromSelector != null ? fromSelector.getImageStreamTagFromExt() : null;
}
if (fromExt != null) {
String namespace = fromExt.get(OpenShiftBuildStrategy.SourceStrategy.namespace.key());
if (namespace != null) {
log.info("Using ImageStreamTag '%s' from namespace '%s' as builder image", fromExt.get(OpenShiftBuildStrategy.SourceStrategy.name.key()), namespace);
} else {
log.info("Using ImageStreamTag '%s' as builder image", fromExt.get(OpenShiftBuildStrategy.SourceStrategy.name.key()));
}
builder.fromExt(fromExt);
}
} else {
throw new IllegalArgumentException(String.format("Invalid 'fromMode' in generator configuration for '%s'", getName()));
}
}
Aggregations