diff --git a/cli/src/main/java/org/wildfly/glow/cli/commands/OpenShiftSupport.java b/cli/src/main/java/org/wildfly/glow/cli/commands/OpenShiftSupport.java index 85a3e166..af692ee1 100644 --- a/cli/src/main/java/org/wildfly/glow/cli/commands/OpenShiftSupport.java +++ b/cli/src/main/java/org/wildfly/glow/cli/commands/OpenShiftSupport.java @@ -66,6 +66,12 @@ import java.util.TreeMap; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import org.jboss.galleon.api.GalleonBuilder; +import org.jboss.galleon.api.Provisioning; +import org.jboss.galleon.api.config.GalleonConfigurationWithLayers; +import org.jboss.galleon.api.config.GalleonFeaturePackConfig; +import org.jboss.galleon.api.config.GalleonProvisioningConfig; +import org.jboss.galleon.config.ConfigId; import org.jboss.galleon.util.IoUtils; import org.jboss.galleon.util.ZipUtils; import org.wildfly.glow.AddOn; @@ -277,6 +283,47 @@ private static String bytesToHex(byte[] hash) { return hexString.toString(); } + static Map createLabels(Path provisioning) throws Exception { + GalleonBuilder provider = new GalleonBuilder(); + Path dir = provisioning.getParent().resolve("tmpHome"); + Files.createDirectory(dir); + StringBuilder layers = new StringBuilder(); + StringBuilder excludedLayers = new StringBuilder(); + StringBuilder fps = new StringBuilder(); + Map labels = new HashMap<>(); + try (Provisioning p = provider.newProvisioningBuilder(provisioning).setInstallationHome(dir).build()) { + GalleonProvisioningConfig config = provider.newProvisioningBuilder(provisioning).setInstallationHome(dir).build().loadProvisioningConfig(provisioning); + GalleonConfigurationWithLayers cl = config.getDefinedConfig(new ConfigId("standalone", "standalone.xml")); + for(String s : cl.getIncludedLayers()) { + labels.put("org.wildfly.glow.layer."+s,""); + } + for(String s : cl.getExcludedLayers()) { + labels.put("org.wildfly.glow.excluded.layer."+s,""); + } + for (GalleonFeaturePackConfig gfpc : config.getFeaturePackDeps()) { + if (fps.length() != 0) { + fps.append("_"); + } + String producerName = gfpc.getLocation().getProducerName(); + producerName = producerName.replaceAll("::zip", ""); + int i = producerName.indexOf(":"); + if(i > 0) { + producerName = producerName.substring(i+1); + } + producerName = producerName.replaceAll(":", "-"); + labels.put("org.wildfly.glow.feature-pack."+producerName,""); + } + } + return labels; + } + + private static String format(String label) { + if (label.length() > 63) { + label = label.substring(0, 56); + label += ".trunc"; + } + return label; + } static String doServerImageBuild(GlowMessageWriter writer, Path target, OpenShiftClient osClient) throws Exception { Path provisioning = target.resolve("galleon").resolve("provisioning.xml"); byte[] content = Files.readAllBytes(provisioning); @@ -302,6 +349,7 @@ static String doServerImageBuild(GlowMessageWriter writer, Path target, OpenShif Files.createDirectories(stepOne); IoUtils.copy(target.resolve("galleon"), stepOne.resolve("galleon")); ZipUtils.zip(stepOne, file); + stream = stream.toBuilder().editOrNewMetadata().withLabels(createLabels(provisioning)).endMetadata().build(); osClient.imageStreams().resource(stream).createOr(NonDeletingOperation::update); Files.write(target.resolve(serverImageName + "-image-stream.yaml"), Serialization.asYaml(stream).getBytes()); BuildConfigBuilder builder = new BuildConfigBuilder(); diff --git a/openshift-deployment/api/pom.xml b/openshift-deployment/api/pom.xml index 40098953..0a184124 100644 --- a/openshift-deployment/api/pom.xml +++ b/openshift-deployment/api/pom.xml @@ -15,6 +15,10 @@ ${project.groupId} wildfly-glow-core + + org.jboss.galleon + galleon-api + io.fabric8 openshift-client