From 83a07e65f7493fd9b886ef7c27d95d6939cb5b0a Mon Sep 17 00:00:00 2001 From: Jean Francois Denise Date: Thu, 28 Mar 2024 12:11:50 +0100 Subject: [PATCH 1/9] Extract openshift support from cli. use amq instead of artemis --- cli/pom.xml | 2 +- .../wildfly/glow/cli/commands/Constants.java | 2 +- .../glow/cli/commands/ScanCommand.java | 47 +++++---- docs/guide/intro/index.adoc | 2 +- .../{artemis-broker => amq-broker}/pom.xml | 2 +- .../openshift/amq/AMQDeployer.java} | 12 +-- ...fly.glow.deployment.openshift.api.Deployer | 1 + .../openshift/api/OpenShiftConfiguration.java | 99 +++++++++++++++++++ .../openshift/api}/OpenShiftSupport.java | 83 ++++++++-------- ...fly.glow.deployment.openshift.api.Deployer | 1 - openshift-deployment/pom.xml | 2 +- pom.xml | 14 ++- 12 files changed, 193 insertions(+), 74 deletions(-) rename openshift-deployment/{artemis-broker => amq-broker}/pom.xml (91%) rename openshift-deployment/{artemis-broker/src/main/java/org/wildfly/glow/deployment/openshift/artemis/ArtemisDeployer.java => amq-broker/src/main/java/org/wildfly/glow/deployment/openshift/amq/AMQDeployer.java} (94%) create mode 100644 openshift-deployment/amq-broker/src/main/resources/META-INF/services/org.wildfly.glow.deployment.openshift.api.Deployer create mode 100644 openshift-deployment/api/src/main/java/org/wildfly/glow/deployment/openshift/api/OpenShiftConfiguration.java rename {cli/src/main/java/org/wildfly/glow/cli/commands => openshift-deployment/api/src/main/java/org/wildfly/glow/deployment/openshift/api}/OpenShiftSupport.java (89%) delete mode 100644 openshift-deployment/artemis-broker/src/main/resources/META-INF/services/org.wildfly.glow.deployment.openshift.api.Deployer diff --git a/cli/pom.xml b/cli/pom.xml index fff66323..7f0a2b49 100644 --- a/cli/pom.xml +++ b/cli/pom.xml @@ -47,7 +47,7 @@ ${project.groupId} - wildfly-glow-openshift-deployment-artemis + wildfly-glow-openshift-deployment-amq ${project.groupId} diff --git a/cli/src/main/java/org/wildfly/glow/cli/commands/Constants.java b/cli/src/main/java/org/wildfly/glow/cli/commands/Constants.java index 8053f7e8..e6d8b4fc 100644 --- a/cli/src/main/java/org/wildfly/glow/cli/commands/Constants.java +++ b/cli/src/main/java/org/wildfly/glow/cli/commands/Constants.java @@ -64,7 +64,7 @@ public interface Constants { String NO_DOCKER_IMAGE_OPTION = "--no-docker-image"; String NO_DOCKER_IMAGE_OPTION_SHORT = "-nd"; String PROVISION_OPTION = "--provision"; - String PROVISION_OPTION_LABEL = ""; + String PROVISION_OPTION_LABEL = ""; String PROVISION_OPTION_SHORT = "-p"; String SERVER_VERSION_OPTION = "--server-version"; String SERVER_VERSION_OPTION_SHORT = "-sv"; diff --git a/cli/src/main/java/org/wildfly/glow/cli/commands/ScanCommand.java b/cli/src/main/java/org/wildfly/glow/cli/commands/ScanCommand.java index ba81ad32..3abb86dc 100644 --- a/cli/src/main/java/org/wildfly/glow/cli/commands/ScanCommand.java +++ b/cli/src/main/java/org/wildfly/glow/cli/commands/ScanCommand.java @@ -16,6 +16,8 @@ */ package org.wildfly.glow.cli.commands; +import org.wildfly.glow.deployment.openshift.api.OpenShiftSupport; +import org.wildfly.glow.deployment.openshift.api.OpenShiftConfiguration; import java.nio.file.Files; import org.jboss.galleon.util.IoUtils; import org.wildfly.glow.Arguments; @@ -64,9 +66,9 @@ public Stability convert(String value) throws Exception { } } - private static final String ADD_ADD_ONS_MSG="@|bold To enable add-ons, add the|@ @|fg(yellow) " + - Constants.ADD_ONS_OPTION + "=|@ @|bold option to the|@ @|fg(yellow) " + - Constants.SCAN_COMMAND + "|@ @|bold command|@"; + private static final String ADD_ADD_ONS_MSG = "@|bold To enable add-ons, add the|@ @|fg(yellow) " + + Constants.ADD_ONS_OPTION + "=|@ @|bold option to the|@ @|fg(yellow) " + + Constants.SCAN_COMMAND + "|@ @|bold command|@"; @CommandLine.Option(names = {Constants.CLOUD_OPTION_SHORT, Constants.CLOUD_OPTION}) Optional cloud; @@ -118,10 +120,10 @@ public Stability convert(String value) throws Exception { Optional configStability; @CommandLine.Option(names = {Constants.ENV_FILE_OPTION_SHORT, Constants.ENV_FILE_OPTION}, paramLabel = Constants.ENV_FILE_OPTION_LABEL) - Optional envFile; + Optional envFile; @CommandLine.Option(names = {Constants.INIT_SCRIPT_OPTION_SHORT, Constants.INIT_SCRIPT_OPTION}, paramLabel = Constants.INIT_SCRIPT_OPTION_LABEL) - Optional initScriptFile; + Optional initScriptFile; @CommandLine.Option(names = Constants.DISABLE_DEPLOYERS, split = ",", paramLabel = Constants.ADD_ONS_OPTION_LABEL) Set disableDeployers = new LinkedHashSet<>(); @@ -146,7 +148,7 @@ public Integer call() throws Exception { } System.setProperty(propName, value); } else { - throw new Exception("Invalid system property " + p +". A property must start with -D"); + throw new Exception("Invalid system property " + p + ". A property must start with -D"); } } } @@ -189,13 +191,13 @@ public Integer call() throws Exception { if (!Files.exists(p)) { throw new Exception(p + " file doesn't exist"); } - for(String l : Files.readAllLines(p)) { + for (String l : Files.readAllLines(p)) { if (!l.startsWith("#")) { int i = l.indexOf("="); if (i < 0 || i == l.length() - 1) { throw new Exception("Invalid environment variable " + l + " in " + p); } - extraEnv.put(l.substring(0, i), l.substring(i+1)); + extraEnv.put(l.substring(0, i), l.substring(i + 1)); } } } @@ -271,13 +273,13 @@ public Integer call() throws Exception { if (scanResults.getErrorSession().hasErrors()) { if (!suggest.orElse(false)) { boolean hasAddOn = false; - // Do we have errors and add-ons to set? - for(IdentifiedError err : scanResults.getErrorSession().getErrors()) { - if (!err.getPossibleAddons().isEmpty()) { - hasAddOn = true; - break; - } - } + // Do we have errors and add-ons to set? + for (IdentifiedError err : scanResults.getErrorSession().getErrors()) { + if (!err.getPossibleAddons().isEmpty()) { + hasAddOn = true; + break; + } + } if (hasAddOn) { System.out.println(CommandLine.Help.Ansi.AUTO.string(ADD_ADD_ONS_MSG)); } @@ -383,13 +385,20 @@ public Integer call() throws Exception { name = p.getFileName().toString().substring(0, ext); } Map envMap = new HashMap<>(); - for(Set envs : scanResults.getSuggestions().getStronglySuggestedConfigurations().values()) { - for(Env env : envs) { + for (Set envs : scanResults.getSuggestions().getStronglySuggestedConfigurations().values()) { + for (Env env : envs) { envMap.put(env.getName(), env.getDescription()); } } - OpenShiftSupport.deploy(GlowMessageWriter.DEFAULT, target, name == null ? "app-from-wildfly-glow" : name.toLowerCase(), envMap, scanResults.getDiscoveredLayers(), - scanResults.getEnabledAddOns(), haProfile.orElse(false), extraEnv, disableDeployers, initScriptFile.orElse(null)); + OpenShiftSupport.deploy(GlowMessageWriter.DEFAULT, + target, name == null ? "app-from-wildfly-glow" : name.toLowerCase(), + envMap, + scanResults.getDiscoveredLayers(), + scanResults.getEnabledAddOns(), + haProfile.orElse(false), + extraEnv, + disableDeployers, + initScriptFile.orElse(null), new OpenShiftConfiguration.Builder().build()); print("@|bold \nOpenshift build and deploy DONE.|@"); } if (content.getDockerImageName() != null) { diff --git a/docs/guide/intro/index.adoc b/docs/guide/intro/index.adoc index 041e46a2..9f24b750 100644 --- a/docs/guide/intro/index.adoc +++ b/docs/guide/intro/index.adoc @@ -71,7 +71,7 @@ Note: The OpenShift resources yaml files are generated in the directory `server- Note: the support for OpenShift is currently specified by this WildFly Glow project link:https://github.com/wildfly/wildfly-glow/issues/49[GitHub Issue]. -###### Automatic deployment of PostGreSQL, MySQL, MariaDB, Artemis JMS Broker and Keycloak +###### Automatic deployment of PostGreSQL, MySQL, MariaDB, AMQ JMS Broker and Keycloak If WildFly Glow detects the need for these technologies, it will automatically deploy the required servers and will bound the application to them. diff --git a/openshift-deployment/artemis-broker/pom.xml b/openshift-deployment/amq-broker/pom.xml similarity index 91% rename from openshift-deployment/artemis-broker/pom.xml rename to openshift-deployment/amq-broker/pom.xml index f07a7083..892e89da 100644 --- a/openshift-deployment/artemis-broker/pom.xml +++ b/openshift-deployment/amq-broker/pom.xml @@ -8,7 +8,7 @@ 1.0.0.Beta12-SNAPSHOT - wildfly-glow-openshift-deployment-artemis + wildfly-glow-openshift-deployment-amq jar diff --git a/openshift-deployment/artemis-broker/src/main/java/org/wildfly/glow/deployment/openshift/artemis/ArtemisDeployer.java b/openshift-deployment/amq-broker/src/main/java/org/wildfly/glow/deployment/openshift/amq/AMQDeployer.java similarity index 94% rename from openshift-deployment/artemis-broker/src/main/java/org/wildfly/glow/deployment/openshift/artemis/ArtemisDeployer.java rename to openshift-deployment/amq-broker/src/main/java/org/wildfly/glow/deployment/openshift/amq/AMQDeployer.java index 09deefa8..a83eb858 100644 --- a/openshift-deployment/artemis-broker/src/main/java/org/wildfly/glow/deployment/openshift/artemis/ArtemisDeployer.java +++ b/openshift-deployment/amq-broker/src/main/java/org/wildfly/glow/deployment/openshift/amq/AMQDeployer.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.wildfly.glow.deployment.openshift.artemis; +package org.wildfly.glow.deployment.openshift.amq; import io.fabric8.kubernetes.api.model.Container; import io.fabric8.kubernetes.api.model.ContainerPort; @@ -43,9 +43,9 @@ * * @author jdenise */ -public class ArtemisDeployer implements Deployer { +public class AMQDeployer implements Deployer { - private static final String REMOTE_BROKER_NAME = "artemis-broker"; + private static final String REMOTE_BROKER_NAME = "amq-broker"; private static final String REMOTE_BROKER_PASSWORD = "admin"; private static final String REMOTE_BROKER_USER = "admin"; @@ -69,7 +69,7 @@ public class ArtemisDeployer implements Deployer { @Override public Map deploy(GlowMessageWriter writer, Path target, OpenShiftClient osClient, Map env, String appHost, String appName, String matching) throws Exception { - writer.info("\nDeploying Artemis Messaging Broker"); + writer.info("\nDeploying AMQ Messaging Broker"); Map labels = new HashMap<>(); labels.put(LABEL, REMOTE_BROKER_NAME); ContainerPort port = new ContainerPort(); @@ -83,7 +83,7 @@ public Map deploy(GlowMessageWriter writer, Path target, OpenShi } Container container = new Container(); container.setName(REMOTE_BROKER_NAME); - container.setImage("quay.io/artemiscloud/activemq-artemis-broker-kubernetes"); + container.setImage("registry.redhat.io/amq7/amq-broker"); container.setPorts(ports); container.setEnv(vars); container.setImagePullPolicy("IfNotPresent"); @@ -146,7 +146,7 @@ public Set getSupportedAddOns() { @Override public String getName() { - return "artemis_jms_broker"; + return "amq_jms_broker"; } } diff --git a/openshift-deployment/amq-broker/src/main/resources/META-INF/services/org.wildfly.glow.deployment.openshift.api.Deployer b/openshift-deployment/amq-broker/src/main/resources/META-INF/services/org.wildfly.glow.deployment.openshift.api.Deployer new file mode 100644 index 00000000..9c40c634 --- /dev/null +++ b/openshift-deployment/amq-broker/src/main/resources/META-INF/services/org.wildfly.glow.deployment.openshift.api.Deployer @@ -0,0 +1 @@ +org.wildfly.glow.deployment.openshift.amq.AMQDeployer diff --git a/openshift-deployment/api/src/main/java/org/wildfly/glow/deployment/openshift/api/OpenShiftConfiguration.java b/openshift-deployment/api/src/main/java/org/wildfly/glow/deployment/openshift/api/OpenShiftConfiguration.java new file mode 100644 index 00000000..7796a6c2 --- /dev/null +++ b/openshift-deployment/api/src/main/java/org/wildfly/glow/deployment/openshift/api/OpenShiftConfiguration.java @@ -0,0 +1,99 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2024 Red Hat, Inc., and individual contributors + * as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.wildfly.glow.deployment.openshift.api; + +/** + * + * @author jdenise + */ +public class OpenShiftConfiguration { + + private final String labelRadical; + private final String serverImageNameRadical; + private final String builderImage; + private final String runtimeImage; + + private OpenShiftConfiguration(String labelRadical, + String serverImageNameRadical, + String builderImage, + String runtimeImage) { + this.labelRadical = labelRadical; + this.serverImageNameRadical = serverImageNameRadical; + this.builderImage = builderImage; + this.runtimeImage = runtimeImage; + } + + public static class Builder { + + private String labelRadical = "org.wildfly.glow"; + private String serverImageNameRadical = "wildfly-server-"; + private String builderImage = "quay.io/wildfly/wildfly-s2i:latest"; + private String runtimeImage = "quay.io/wildfly/wildfly-runtime:latest"; + + public Builder setLabelRadical(String radical) { + this.labelRadical = radical; + return this; + } + + public Builder setServerImageNameRadical(String radical) { + this.serverImageNameRadical = radical; + return this; + } + + public Builder setBuilderImage(String img) { + this.builderImage = img; + return this; + } + + public Builder setRuntimeImage(String img) { + this.runtimeImage = img; + return this; + } + + public OpenShiftConfiguration build() { + return new OpenShiftConfiguration(labelRadical, serverImageNameRadical, builderImage, runtimeImage); + } + } + + /** + * @return the labelRadical + */ + public String getLabelRadical() { + return labelRadical; + } + + /** + * @return the serverImageNameRadical + */ + public String getServerImageNameRadical() { + return serverImageNameRadical; + } + + /** + * @return the builderImage + */ + public String getBuilderImage() { + return builderImage; + } + + /** + * @return the runtimeImage + */ + public String getRuntimeImage() { + return runtimeImage; + } +} diff --git a/cli/src/main/java/org/wildfly/glow/cli/commands/OpenShiftSupport.java b/openshift-deployment/api/src/main/java/org/wildfly/glow/deployment/openshift/api/OpenShiftSupport.java similarity index 89% rename from cli/src/main/java/org/wildfly/glow/cli/commands/OpenShiftSupport.java rename to openshift-deployment/api/src/main/java/org/wildfly/glow/deployment/openshift/api/OpenShiftSupport.java index 2c4b7df7..5912edf1 100644 --- a/cli/src/main/java/org/wildfly/glow/cli/commands/OpenShiftSupport.java +++ b/openshift-deployment/api/src/main/java/org/wildfly/glow/deployment/openshift/api/OpenShiftSupport.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.wildfly.glow.cli.commands; +package org.wildfly.glow.deployment.openshift.api; import io.fabric8.kubernetes.api.model.Container; import io.fabric8.kubernetes.api.model.ContainerPort; @@ -23,7 +23,6 @@ import io.fabric8.kubernetes.api.model.HTTPGetAction; import io.fabric8.kubernetes.api.model.IntOrString; import io.fabric8.kubernetes.api.model.ObjectReference; -import io.fabric8.kubernetes.api.model.ObjectReferenceBuilder; import io.fabric8.kubernetes.api.model.Probe; import io.fabric8.kubernetes.api.model.Service; import io.fabric8.kubernetes.api.model.ServiceBuilder; @@ -49,7 +48,6 @@ import io.fabric8.openshift.api.model.RouteBuilder; import io.fabric8.openshift.api.model.RouteTargetReference; import io.fabric8.openshift.api.model.TLSConfig; -import io.fabric8.openshift.api.model.TagReferenceBuilder; import io.fabric8.openshift.client.OpenShiftClient; import java.nio.file.Files; import java.nio.file.Path; @@ -75,13 +73,12 @@ import org.wildfly.glow.AddOn; import org.wildfly.glow.GlowMessageWriter; import org.wildfly.glow.Layer; -import org.wildfly.glow.deployment.openshift.api.Deployer; -import org.wildfly.glow.deployment.openshift.api.Utils; + /** * * @author jdenise */ -class OpenShiftSupport { +public class OpenShiftSupport { private static void createAppDeployment(GlowMessageWriter writer, Path target, OpenShiftClient osClient, String name, Map env, boolean ha) throws Exception { writer.info("Deploying application image on OpenShift"); @@ -178,8 +175,16 @@ private static void createAppDeployment(GlowMessageWriter writer, Path target, O osClient.resources(Deployment.class).resource(deployment).waitUntilReady(5, TimeUnit.MINUTES); } - static void deploy(GlowMessageWriter writer, Path target, String appName, Map env, Set layers, Set addOns, boolean ha, - Map extraEnv, Set disabledDeployers, Path initScript) throws Exception { + public static void deploy(GlowMessageWriter writer, + Path target, + String appName, + Map env, + Set layers, + Set addOns, + boolean ha, + Map extraEnv, + Set disabledDeployers, + Path initScript, OpenShiftConfiguration config) throws Exception { Map actualEnv = new TreeMap<>(); OpenShiftClient osClient = new KubernetesClientBuilder().build().adapt(OpenShiftClient.class); writer.info("\nConnected to OpenShift cluster"); @@ -236,7 +241,7 @@ static void deploy(GlowMessageWriter writer, Path target, String appName, Map createLabels(Path target, Path provisioning) throws Exception { + private static Map createLabels(Path target, Path provisioning, OpenShiftConfiguration osConfig) throws Exception { GalleonBuilder provider = new GalleonBuilder(); Path dir = target.resolve("tmp").resolve("tmpHome"); Files.createDirectory(dir); @@ -291,11 +301,11 @@ static Map createLabels(Path target, Path provisioning) throws E 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.getIncludedLayers()) { + labels.put(osConfig.getLabelRadical() + ".layer." + s, ""); } - for(String s : cl.getExcludedLayers()) { - labels.put("org.wildfly.glow.excluded.layer."+s,""); + for (String s : cl.getExcludedLayers()) { + labels.put(osConfig.getLabelRadical() + ".excluded.layer." + s, ""); } for (GalleonFeaturePackConfig gfpc : config.getFeaturePackDeps()) { if (fps.length() != 0) { @@ -304,23 +314,23 @@ static Map createLabels(Path target, Path provisioning) throws E String producerName = gfpc.getLocation().getProducerName(); producerName = producerName.replaceAll("::zip", ""); int i = producerName.indexOf(":"); - if(i > 0) { - producerName = producerName.substring(i+1); + if (i > 0) { + producerName = producerName.substring(i + 1); } producerName = producerName.replaceAll(":", "-"); - labels.put("org.wildfly.glow.feature-pack."+producerName,""); + labels.put(osConfig.getLabelRadical() + ".feature-pack." + producerName, ""); } } return labels; } - static String doServerImageBuild(GlowMessageWriter writer, Path target, OpenShiftClient osClient) throws Exception { + private static String doServerImageBuild(GlowMessageWriter writer, Path target, OpenShiftClient osClient, OpenShiftConfiguration config) throws Exception { Path provisioning = target.resolve("galleon").resolve("provisioning.xml"); byte[] content = Files.readAllBytes(provisioning); MessageDigest digest = MessageDigest.getInstance("MD5"); byte[] encodedhash = digest.digest(content); String key = bytesToHex(encodedhash); - String serverImageName = "wildfly-server-" + key; + String serverImageName = config.getServerImageNameRadical() + key; ImageStream stream = new ImageStreamBuilder().withNewMetadata().withName(serverImageName). endMetadata().withNewSpec().withLookupPolicy(new ImageLookupPolicy(Boolean.TRUE)).endSpec().build(); @@ -338,7 +348,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(target, provisioning)).endMetadata().build(); + stream = stream.toBuilder().editOrNewMetadata().withLabels(createLabels(target, provisioning, config)).endMetadata().build(); osClient.imageStreams().resource(stream).createOr(NonDeletingOperation::update); Utils.persistResource(target, stream, serverImageName + "-image-stream.yaml"); BuildConfigBuilder builder = new BuildConfigBuilder(); @@ -352,7 +362,7 @@ static String doServerImageBuild(GlowMessageWriter writer, Path target, OpenShif withKind("ImageStreamTag"). withName(serverImageName + ":latest").endTo(). endOutput().withNewStrategy().withNewSourceStrategy().withNewFrom().withKind("DockerImage"). - withName("quay.io/wildfly/wildfly-s2i:latest").endFrom(). + withName(config.getBuilderImage()).endFrom(). withIncremental(true). withEnv(new EnvVar().toBuilder().withName("GALLEON_USE_LOCAL_FILE").withValue("true").build()). endSourceStrategy().endStrategy().withNewSource(). @@ -369,13 +379,19 @@ static String doServerImageBuild(GlowMessageWriter writer, Path target, OpenShif return serverImageName; } - static void doAppImageBuild(String serverImageName, GlowMessageWriter writer, Path target, OpenShiftClient osClient, String name, Path initScript) throws Exception { + private static void doAppImageBuild(String serverImageName, + GlowMessageWriter writer, + Path target, + OpenShiftClient osClient, + String name, + Path initScript, + OpenShiftConfiguration config) throws Exception { // Now step 2 // From the server image, do a docker build, copy the server and copy in it the deployments and init file. Path stepTwo = target.resolve("tmp").resolve("step-two"); IoUtils.copy(target.resolve("deployments"), stepTwo.resolve("deployments")); StringBuilder dockerFileBuilder = new StringBuilder(); - dockerFileBuilder.append("FROM wildfly-runtime:latest\n"); + dockerFileBuilder.append("FROM " + config.getRuntimeImage() + "\n"); dockerFileBuilder.append("COPY --chown=jboss:root /server $JBOSS_HOME\n"); dockerFileBuilder.append("COPY --chown=jboss:root deployments/* $JBOSS_HOME/standalone/deployments\n"); @@ -395,17 +411,6 @@ static void doAppImageBuild(String serverImageName, GlowMessageWriter writer, Pa } ZipUtils.zip(stepTwo, file2); writer.info("\nBuilding application image..."); - ImageStream runtimeStream = new ImageStreamBuilder().withNewMetadata().withName("wildfly-runtime"). - endMetadata().withNewSpec(). - addToTags(0, new TagReferenceBuilder() - .withName("latest") - .withFrom(new ObjectReferenceBuilder() - .withKind("DockerImage") - .withName("quay.io/wildfly/wildfly-runtime:latest") - .build()) - .build()). - withLookupPolicy(new ImageLookupPolicy(Boolean.TRUE)).endSpec().build(); - osClient.imageStreams().resource(runtimeStream).createOr(NonDeletingOperation::update); ImageStream appStream = new ImageStreamBuilder().withNewMetadata().withName(name). endMetadata().withNewSpec().withLookupPolicy(new ImageLookupPolicy(Boolean.TRUE)).endSpec().build(); osClient.imageStreams().resource(appStream).createOr(NonDeletingOperation::update); @@ -423,8 +428,8 @@ static void doAppImageBuild(String serverImageName, GlowMessageWriter writer, Pa withName(name + ":latest").endTo(). endOutput(). withNewSource().withType("Binary").withImages(imageSource).endSource(). - withNewStrategy().withNewDockerStrategy().withNewFrom().withKind("ImageStream"). - withName("wildfly-runtime").endFrom(). + withNewStrategy().withNewDockerStrategy().withNewFrom().withKind("DockerImage"). + withName("quay.io/wildfly/wildfly-runtime:latest").endFrom(). withDockerfilePath("./Dockerfile"). endDockerStrategy().endStrategy().endSpec().build(); osClient.buildConfigs().resource(buildConfig2).createOr(NonDeletingOperation::update); diff --git a/openshift-deployment/artemis-broker/src/main/resources/META-INF/services/org.wildfly.glow.deployment.openshift.api.Deployer b/openshift-deployment/artemis-broker/src/main/resources/META-INF/services/org.wildfly.glow.deployment.openshift.api.Deployer deleted file mode 100644 index 6d475194..00000000 --- a/openshift-deployment/artemis-broker/src/main/resources/META-INF/services/org.wildfly.glow.deployment.openshift.api.Deployer +++ /dev/null @@ -1 +0,0 @@ -org.wildfly.glow.deployment.openshift.artemis.ArtemisDeployer diff --git a/openshift-deployment/pom.xml b/openshift-deployment/pom.xml index 9a99c228..6bc6d59b 100644 --- a/openshift-deployment/pom.xml +++ b/openshift-deployment/pom.xml @@ -22,6 +22,6 @@ mariadb mysql postgresql - artemis-broker + amq-broker \ No newline at end of file diff --git a/pom.xml b/pom.xml index 77dcc15f..8c6b61c4 100644 --- a/pom.xml +++ b/pom.xml @@ -241,7 +241,7 @@ ${project.groupId} - wildfly-glow-openshift-deployment-artemis + wildfly-glow-openshift-deployment-amq ${project.version} @@ -299,9 +299,15 @@ - org.wildfly.core - wildfly-version - ${version.org.wildfly.core} + org.wildfly.core + wildfly-version + ${version.org.wildfly.core} + + + * + * + + org.wildfly.galleon-plugins From f7bc55c936f1e6576450107ce1be5241a23ebbf3 Mon Sep 17 00:00:00 2001 From: Jean Francois Denise Date: Thu, 28 Mar 2024 12:32:50 +0100 Subject: [PATCH 2/9] Enforce cloud for Openshift, introduce fails-on-error --- .../org/wildfly/glow/cli/commands/Constants.java | 2 ++ .../wildfly/glow/cli/commands/ScanCommand.java | 16 +++++++++++----- cli/src/main/resources/UsageMessages.properties | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/cli/src/main/java/org/wildfly/glow/cli/commands/Constants.java b/cli/src/main/java/org/wildfly/glow/cli/commands/Constants.java index e6d8b4fc..ef95af4a 100644 --- a/cli/src/main/java/org/wildfly/glow/cli/commands/Constants.java +++ b/cli/src/main/java/org/wildfly/glow/cli/commands/Constants.java @@ -52,6 +52,8 @@ public interface Constants { String EXCLUDE_ARCHIVES_FROM_SCAN_OPTION = "--exclude-archives-from-scan"; String EXCLUDE_ARCHIVES_FROM_SCAN_OPTION_LABEL = ""; String EXCLUDE_ARCHIVES_FROM_SCAN_OPTION_SHORT = "-ea"; + String FAILS_ON_ERROR_OPTION = "--fails-on-error"; + String FAILS_ON_ERROR_OPTION_SHORT = "-foe"; String HA_OPTION = "--ha"; String HELP_OPTION = "--help"; diff --git a/cli/src/main/java/org/wildfly/glow/cli/commands/ScanCommand.java b/cli/src/main/java/org/wildfly/glow/cli/commands/ScanCommand.java index 3abb86dc..5aef0e01 100644 --- a/cli/src/main/java/org/wildfly/glow/cli/commands/ScanCommand.java +++ b/cli/src/main/java/org/wildfly/glow/cli/commands/ScanCommand.java @@ -132,6 +132,9 @@ public Stability convert(String value) throws Exception { split = " ", paramLabel = Constants.SYSTEM_PROPERTIES_LABEL) Set systemProperties = new HashSet<>(); + @CommandLine.Option(names = {Constants.FAILS_ON_ERROR_OPTION_SHORT, Constants.FAILS_ON_ERROR_OPTION}, defaultValue = "true") + Optional failsOnError; + @Override public Integer call() throws Exception { if (!systemProperties.isEmpty()) { @@ -158,9 +161,6 @@ public Integer call() throws Exception { print("Wildfly Glow is scanning..."); } Builder builder = Arguments.scanBuilder(); - if (cloud.orElse(false)) { - builder.setExecutionContext(CLOUD_EXECUTION_CONTEXT); - } if (haProfile.orElse(false)) { Set profiles = new HashSet<>(); profiles.add(Constants.HA); @@ -232,10 +232,13 @@ public Integer call() throws Exception { throw new Exception("Can't produce a Docker image if cloud is not enabled. Use the " + Constants.CLOUD_OPTION + " option."); } if (OPENSHIFT.equals(provision.get()) && !cloud.orElse(false)) { - throw new Exception("Can't build/deploy on openShift if cloud is not enabled. Use the " + Constants.CLOUD_OPTION + " option."); + cloud = Optional.of(Boolean.TRUE); } builder.setOutput(provision.get()); } + if (cloud.orElse(false)) { + builder.setExecutionContext(CLOUD_EXECUTION_CONTEXT); + } builder.setExcludeArchivesFromScan(excludeArchivesFromScan); if (stability.isPresent()) { if (configStability.isPresent()) { @@ -286,11 +289,14 @@ public Integer call() throws Exception { } print("@|bold Some errors have been reported. You should fix them prior provisioning a server with the|@ @|fg(yellow) " + Constants.PROVISION_OPTION + "|@ @|bold option of the|@ @|fg(yellow) " + Constants.SCAN_COMMAND + "|@ @|bold command|@"); } else { - print("@|bold If you had included a|@ @|fg(yellow) " + Constants.PROVISION_OPTION + "|@ @|bold option to the|@ @|fg(yellow) " + Constants.SCAN_COMMAND + "|@ @|bold command, after outputting this report, WildFly Glow will continue on to provisioning your WildFly server, bootable jar or Docker image.|@"); + print("@|bold If you had included a|@ @|fg(yellow) " + Constants.PROVISION_OPTION+"="+Constants.PROVISION_OPTION_LABEL + "|@ @|bold option to the|@ @|fg(yellow) " + Constants.SCAN_COMMAND + "|@ @|bold command, after outputting this report, WildFly Glow will continue on to provisioning your WildFly server, bootable jar, a Docker image or deploy your application to OpenShift.|@"); } } } else { print(); + if (failsOnError.orElse(false) && scanResults.getErrorSession().hasErrors()) { + throw new Exception("Your are provisioning although errors have been reported. If you want to enforce provisioning, set --fails-on-error=false to ignore errors."); + } String vers = wildflyServerVersion.orElse(null) == null ? FeaturePacks.getLatestVersion() : wildflyServerVersion.get(); Path target = Paths.get(provisionOutputDir.orElse("server-" + vers)); IoUtils.recursiveDelete(target); diff --git a/cli/src/main/resources/UsageMessages.properties b/cli/src/main/resources/UsageMessages.properties index 07365694..b5f28635 100644 --- a/cli/src/main/resources/UsageMessages.properties +++ b/cli/src/main/resources/UsageMessages.properties @@ -42,7 +42,7 @@ init-script = The path to a script that contains commands (JBoss CLI, add-user, disable-deployers = A comma separated list of deployer names to disable. To retrieve all the deployer names call the @|fg(yellow) show-configuration|@ operation. To disable them all, use @|fg(yellow) ALL|@ value. Can only be used with @|fg(yellow) OPENSHIFT|@ kind of provisioning. properties = A space separated list of Java system properties. When multiple system properties are set, the list must be enclosed in double quotes. For example: "-Dfoo=bar -DmyProp" - +fails-on-error= By default provisioning will be aborted if an error is reported by WildFly Glow. Set this option to false to not fail and process with the provisioning. usage.synopsisHeading = %nUsage:\u0020 # for the main command do not prepend with new line character: wildfly-glow.usage.synopsisHeading = Usage:\u0020 From 8bc7e13de21b4a7d9c2da06639649496973aa55e Mon Sep 17 00:00:00 2001 From: Jean Francois Denise Date: Thu, 28 Mar 2024 12:41:12 +0100 Subject: [PATCH 3/9] Fix docker message, implies cloud for docker image --- .../main/java/org/wildfly/glow/cli/commands/ScanCommand.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/src/main/java/org/wildfly/glow/cli/commands/ScanCommand.java b/cli/src/main/java/org/wildfly/glow/cli/commands/ScanCommand.java index 5aef0e01..13ba2cea 100644 --- a/cli/src/main/java/org/wildfly/glow/cli/commands/ScanCommand.java +++ b/cli/src/main/java/org/wildfly/glow/cli/commands/ScanCommand.java @@ -229,7 +229,7 @@ public Integer call() throws Exception { throw new Exception("Can't produce a Bootable JAR for cloud. Use the " + Constants.PROVISION_OPTION + "=SERVER option for cloud."); } if (DOCKER_IMAGE.equals(provision.get()) && !cloud.orElse(false)) { - throw new Exception("Can't produce a Docker image if cloud is not enabled. Use the " + Constants.CLOUD_OPTION + " option."); + cloud = Optional.of(Boolean.TRUE); } if (OPENSHIFT.equals(provision.get()) && !cloud.orElse(false)) { cloud = Optional.of(Boolean.TRUE); @@ -408,7 +408,7 @@ public Integer call() throws Exception { print("@|bold \nOpenshift build and deploy DONE.|@"); } if (content.getDockerImageName() != null) { - print("@|bold To run the image call: 'docker run " + content.getDockerImageName() + "'|@"); + print("@|bold To run the image call: '[docker | podman] run -p 8080:8080 -p 9990:9990 " + content.getDockerImageName() + "'|@"); } } return 0; From 04a043c9317955c408c8830e5accff1ea248979f Mon Sep 17 00:00:00 2001 From: Jean Francois Denise Date: Thu, 28 Mar 2024 13:02:52 +0100 Subject: [PATCH 4/9] Do not duplicate env variables in the output --- core/src/main/java/org/wildfly/glow/Utils.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/core/src/main/java/org/wildfly/glow/Utils.java b/core/src/main/java/org/wildfly/glow/Utils.java index 0da80332..28d21691 100644 --- a/core/src/main/java/org/wildfly/glow/Utils.java +++ b/core/src/main/java/org/wildfly/glow/Utils.java @@ -637,10 +637,7 @@ public static String getAddOnFix(AddOn ao, String fixContent) throws URISyntaxEx } } if (envBuilder.length() != 0) { - builder.append(" and expects (at least) the following env variables:\n").append(envBuilder.toString()); - if (fixContent != null && !fixContent.isEmpty()) { - builder.append(" - ").append(fixContent); - } + builder.append(" but you need to set the strongly suggested configuration."); } else { if (fixContent == null || fixContent.isEmpty()) { builder.append(" fully"); From 2c7570dd6698758bffa40dc4461594f1e69b6c10 Mon Sep 17 00:00:00 2001 From: Jean Francois Denise Date: Thu, 28 Mar 2024 13:27:30 +0100 Subject: [PATCH 5/9] Better message to export env variables --- .../glow/cli/commands/ScanCommand.java | 42 ++++++++++++------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/cli/src/main/java/org/wildfly/glow/cli/commands/ScanCommand.java b/cli/src/main/java/org/wildfly/glow/cli/commands/ScanCommand.java index 13ba2cea..73763d73 100644 --- a/cli/src/main/java/org/wildfly/glow/cli/commands/ScanCommand.java +++ b/cli/src/main/java/org/wildfly/glow/cli/commands/ScanCommand.java @@ -327,34 +327,35 @@ public Integer call() throws Exception { } OutputContent content = scanResults.outputConfig(target, dockerImageName.orElse(null)); Path base = Paths.get("").toAbsolutePath(); + String envMessage = null; + String completedMessage = null; for (OutputContent.OutputFile f : content.getFiles().keySet()) { Path rel = base.relativize(content.getFiles().get(f)); switch (f) { case BOOTABLE_JAR_FILE: { - print("@|bold Bootable JAR build DONE.|@"); - print("@|bold To run the jar call: 'java -jar " + rel + "'|@"); + completedMessage = "@|bold To run the jar call: 'java -jar " + rel + "'|@"; break; } case DOCKER_FILE: { - print("@|bold Image generation DONE.|@."); print("@|bold Docker file generated in %s|@.", rel); break; } case ENV_FILE: { - if (!OutputFormat.OPENSHIFT.equals(provision.get())) { - print("@|bold The file " + rel + " contains the list of environment variables that you must set prior to start the server.|@"); - } + // Exposing this file seems to create confusion +// if (!OutputFormat.OPENSHIFT.equals(provision.get())) { +// print("@|bold The file " + rel + " contains the list of environment variables that you must set prior to start the server.|@"); +// } switch (provision.get()) { case SERVER: { - print("@|bold Export the suggested env variables for the server to take them into account.|@"); + envMessage = "WARNING: You have to export the suggested env variables prior to start the server."; break; } case BOOTABLE_JAR: { - print("@|bold Export the suggested env variables for the bootable JAR to take them into account.|@"); + envMessage="WARNING: You have to export the suggested env variables prior to start the bootable JAR."; break; } case DOCKER_IMAGE: { - print("@|bold For each env variable add `-e =` to the `docker run` command.|@"); + envMessage = "WARNING: For each suggested env variable add `-e =` to the `[docker | podman] run` command."; break; } } @@ -363,7 +364,6 @@ public Integer call() throws Exception { case PROVISIONING_XML_FILE: { switch (provision.get()) { case PROVISIONING_XML: { - print("@|bold Generation DONE.|@"); print("@|bold Galleon Provisioning configuration is located in " + rel + " file|@"); } } @@ -371,11 +371,10 @@ public Integer call() throws Exception { } case SERVER_DIR: { - print("@|bold Provisioning DONE.|@"); if (cloud.orElse(false)) { - print("@|bold To run the server call: 'JBOSS_HOME=" + rel + " sh " + rel + "/bin/openshift-launch.sh'|@"); + completedMessage = "@|bold To run the server call: 'JBOSS_HOME=" + rel + " sh " + rel + "/bin/openshift-launch.sh'|@"; } else { - print("@|bold To run the server call: 'sh " + rel + "/bin/standalone.sh'|@"); + completedMessage = "@|bold To run the server call: 'sh " + rel + "/bin/standalone.sh'|@"; } break; } @@ -406,9 +405,20 @@ public Integer call() throws Exception { disableDeployers, initScriptFile.orElse(null), new OpenShiftConfiguration.Builder().build()); print("@|bold \nOpenshift build and deploy DONE.|@"); - } - if (content.getDockerImageName() != null) { - print("@|bold To run the image call: '[docker | podman] run -p 8080:8080 -p 9990:9990 " + content.getDockerImageName() + "'|@"); + } else { + if (content.getDockerImageName() != null) { + print("@|bold To run the image call: '[docker | podman] run -p 8080:8080 -p 9990:9990 " + content.getDockerImageName() + "'|@"); + if (envMessage != null) { + GlowMessageWriter.DEFAULT.warn(envMessage); + } + } else { + if (completedMessage != null) { + print(completedMessage); + if (envMessage != null) { + GlowMessageWriter.DEFAULT.warn(envMessage); + } + } + } } } return 0; From 5b8cda5c0feeffa119a53a90b44bda4cc43bcee2 Mon Sep 17 00:00:00 2001 From: Jean Francois Denise Date: Thu, 28 Mar 2024 14:21:45 +0100 Subject: [PATCH 6/9] Better message for suggest --- .../org/wildfly/glow/cli/commands/ScanCommand.java | 1 + core/src/main/java/org/wildfly/glow/Arguments.java | 13 ++++++++++++- .../java/org/wildfly/glow/BaseArgumentsBuilder.java | 4 +++- .../main/java/org/wildfly/glow/ScanArguments.java | 5 +++++ .../java/org/wildfly/glow/ScanResultsPrinter.java | 2 +- 5 files changed, 22 insertions(+), 3 deletions(-) diff --git a/cli/src/main/java/org/wildfly/glow/cli/commands/ScanCommand.java b/cli/src/main/java/org/wildfly/glow/cli/commands/ScanCommand.java index 73763d73..ac741e82 100644 --- a/cli/src/main/java/org/wildfly/glow/cli/commands/ScanCommand.java +++ b/cli/src/main/java/org/wildfly/glow/cli/commands/ScanCommand.java @@ -261,6 +261,7 @@ public Integer call() throws Exception { throw new Exception("Can only set a docker image name when provisioning a docker image. Remove the " + Constants.DOCKER_IMAGE_NAME_OPTION + " option"); } } + builder.setIsCli(true); ScanResults scanResults = GlowSession.scan(MavenResolver.newMavenResolver(), builder.build(), GlowMessageWriter.DEFAULT); scanResults.outputInformation(); if (provision.isEmpty()) { diff --git a/core/src/main/java/org/wildfly/glow/Arguments.java b/core/src/main/java/org/wildfly/glow/Arguments.java index c1b41742..c348307a 100644 --- a/core/src/main/java/org/wildfly/glow/Arguments.java +++ b/core/src/main/java/org/wildfly/glow/Arguments.java @@ -35,6 +35,7 @@ public class Arguments implements GoOfflineArguments, ScanArguments { private final Set excludeArchivesFromScan; private final Stability configStability; private final Stability packageStability; + private final boolean isCli; protected Arguments( String executionContext, @@ -51,7 +52,8 @@ protected Arguments( boolean techPreview, Set excludeArchivesFromScan, Stability configStability, - Stability packageStability) { + Stability packageStability, + boolean isCli) { this.executionProfiles = executionProfiles; this.userEnabledAddOns = userEnabledAddOns; this.binaries = binaries; @@ -76,6 +78,7 @@ protected Arguments( } else { this.manualLayers = new HashSet<>(Arrays.asList(manualLayers.split(","))); } + this.isCli = isCli; } /** @@ -191,6 +194,14 @@ public Stability getPackageStability() { return packageStability; } + /** + * @return the isCli + */ + @Override + public boolean isCli() { + return isCli; + } + static GoOfflineArguments.Builder goOfflineBuilder() { return new GoOfflineArguments.Builder(); } diff --git a/core/src/main/java/org/wildfly/glow/BaseArgumentsBuilder.java b/core/src/main/java/org/wildfly/glow/BaseArgumentsBuilder.java index 53f7a8fb..3bf80155 100644 --- a/core/src/main/java/org/wildfly/glow/BaseArgumentsBuilder.java +++ b/core/src/main/java/org/wildfly/glow/BaseArgumentsBuilder.java @@ -42,6 +42,7 @@ public class BaseArgumentsBuilder { protected Set excludeJarsFromScan = Collections.emptySet(); protected Stability packageStability; protected Stability configStability; + protected boolean isCli; protected BaseArgumentsBuilder() { @@ -67,6 +68,7 @@ public Arguments build() { techPreview, excludeJarsFromScan, configStability, - packageStability); + packageStability, + isCli); } } diff --git a/core/src/main/java/org/wildfly/glow/ScanArguments.java b/core/src/main/java/org/wildfly/glow/ScanArguments.java index 83fcce44..ff6eac3d 100644 --- a/core/src/main/java/org/wildfly/glow/ScanArguments.java +++ b/core/src/main/java/org/wildfly/glow/ScanArguments.java @@ -76,6 +76,7 @@ public interface ScanArguments { Stability getConfigStability(); Stability getPackageStability(); + boolean isCli(); default Builder createScanArgumentsBuilder() { return new Builder(); @@ -163,5 +164,9 @@ public Builder setConfigStability(Stability stability) { this.configStability = stability; return this; } + public Builder setIsCli(boolean isCli) { + this.isCli = isCli; + return this; + } } } diff --git a/core/src/main/java/org/wildfly/glow/ScanResultsPrinter.java b/core/src/main/java/org/wildfly/glow/ScanResultsPrinter.java index ae1ed8a5..a47c067e 100644 --- a/core/src/main/java/org/wildfly/glow/ScanResultsPrinter.java +++ b/core/src/main/java/org/wildfly/glow/ScanResultsPrinter.java @@ -277,7 +277,7 @@ private void detailed(ScanArguments arguments, ScanResults scanResults) throws E } } else { if (!scanResults.getSuggestions().getPossibleAddOns().isEmpty() || !scanResults.getSuggestions().getPossibleAddOns().isEmpty() || !suggestedConfigs.isEmpty() || !suggestedBuildTimeConfigs.isEmpty()) { - writer.info("Some suggestions have been found. You could enable suggestions with the --suggest option (if using the WildFly Glow CLI) or true (if using the WildFly Maven Plugin)."); + writer.info("Some suggestions have been found. You could enable suggestions with the " + (arguments.isCli() ? "--suggest" : "true") + " option."); } } } From 51972de56a0f9f243ca6196e1d4bb91a4f3fe042 Mon Sep 17 00:00:00 2001 From: Jean Francois Denise Date: Thu, 28 Mar 2024 17:00:12 +0100 Subject: [PATCH 7/9] Provided user env can be used to setup deployers --- .../glow/cli/commands/ScanCommand.java | 3 +- .../deployment/openshift/amq/AMQDeployer.java | 30 ++++++++++++++----- .../api/AbstractDatabaseDeployer.java | 6 ++-- .../deployment/openshift/api/Deployer.java | 2 +- .../openshift/api/OpenShiftSupport.java | 9 +++--- .../openshift/keycloak/KeycloakDeployer.java | 8 +++-- 6 files changed, 39 insertions(+), 19 deletions(-) diff --git a/cli/src/main/java/org/wildfly/glow/cli/commands/ScanCommand.java b/cli/src/main/java/org/wildfly/glow/cli/commands/ScanCommand.java index ac741e82..9fcbbacb 100644 --- a/cli/src/main/java/org/wildfly/glow/cli/commands/ScanCommand.java +++ b/cli/src/main/java/org/wildfly/glow/cli/commands/ScanCommand.java @@ -192,7 +192,8 @@ public Integer call() throws Exception { throw new Exception(p + " file doesn't exist"); } for (String l : Files.readAllLines(p)) { - if (!l.startsWith("#")) { + l = l.trim(); + if (!l.isEmpty() && !l.startsWith("#")) { int i = l.indexOf("="); if (i < 0 || i == l.length() - 1) { throw new Exception("Invalid environment variable " + l + " in " + p); diff --git a/openshift-deployment/amq-broker/src/main/java/org/wildfly/glow/deployment/openshift/amq/AMQDeployer.java b/openshift-deployment/amq-broker/src/main/java/org/wildfly/glow/deployment/openshift/amq/AMQDeployer.java index a83eb858..3b6b2ea5 100644 --- a/openshift-deployment/amq-broker/src/main/java/org/wildfly/glow/deployment/openshift/amq/AMQDeployer.java +++ b/openshift-deployment/amq-broker/src/main/java/org/wildfly/glow/deployment/openshift/amq/AMQDeployer.java @@ -52,23 +52,27 @@ public class AMQDeployer implements Deployer { private static final Map REMOTE_BROKER_CONNECTION_MAP = new HashMap<>(); private static final Map REMOTE_BROKER_APP_MAP = new HashMap<>(); + private static final String AMQ_USER_ENV = "AMQ_USER"; + private static final String AMQ_PASSWORD_ENV = "AMQ_PASSWORD"; + private static final String BROKER_AMQ_USERNAME_ENV = "BROKER_AMQ_USERNAME"; + private static final String BROKER_AMQ_PASSWORD_ENV = "BROKER_AMQ_PASSWORD"; static { - REMOTE_BROKER_CONNECTION_MAP.put("AMQ_USER", REMOTE_BROKER_USER); - REMOTE_BROKER_CONNECTION_MAP.put("AMQ_PASSWORD", REMOTE_BROKER_PASSWORD); + REMOTE_BROKER_CONNECTION_MAP.put(AMQ_USER_ENV, REMOTE_BROKER_USER); + REMOTE_BROKER_CONNECTION_MAP.put(AMQ_PASSWORD_ENV, REMOTE_BROKER_PASSWORD); REMOTE_BROKER_CONNECTION_MAP.put("AMQ_DATA_DIR", "/home/jboss/data"); REMOTE_BROKER_APP_MAP.put("MQ_SERVICE_PREFIX_MAPPING", "broker-amq7=BROKER_AMQ"); REMOTE_BROKER_APP_MAP.put("MQ_SERVICE_PREFIX_MAPPING", "broker-amq7=BROKER_AMQ"); REMOTE_BROKER_APP_MAP.put("BROKER_AMQ_TCP_SERVICE_HOST", REMOTE_BROKER_NAME); REMOTE_BROKER_APP_MAP.put("BROKER_AMQ_TCP_SERVICE_PORT", "61616"); - REMOTE_BROKER_APP_MAP.put("BROKER_AMQ_PASSWORD", REMOTE_BROKER_PASSWORD); - REMOTE_BROKER_APP_MAP.put("BROKER_AMQ_USERNAME", REMOTE_BROKER_USER); + REMOTE_BROKER_APP_MAP.put(BROKER_AMQ_PASSWORD_ENV, REMOTE_BROKER_PASSWORD); + REMOTE_BROKER_APP_MAP.put(BROKER_AMQ_USERNAME_ENV, REMOTE_BROKER_USER); } @Override public Map deploy(GlowMessageWriter writer, Path target, OpenShiftClient osClient, - Map env, String appHost, String appName, String matching) throws Exception { + Map env, String appHost, String appName, String matching, Map extraEnv) throws Exception { writer.info("\nDeploying AMQ Messaging Broker"); Map labels = new HashMap<>(); labels.put(LABEL, REMOTE_BROKER_NAME); @@ -79,7 +83,16 @@ public Map deploy(GlowMessageWriter writer, Path target, OpenShi ports.add(port); List vars = new ArrayList<>(); for (Map.Entry entry : REMOTE_BROKER_CONNECTION_MAP.entrySet()) { - vars.add(new EnvVar().toBuilder().withName(entry.getKey()).withValue(entry.getValue()).build()); + // In case user overrides the default values. + String val = extraEnv.get(entry.getKey()); + if (val != null) { + if (AMQ_USER_ENV.equals(entry.getKey())) { + REMOTE_BROKER_APP_MAP.put(BROKER_AMQ_USERNAME_ENV, val); + } else if (AMQ_PASSWORD_ENV.equals(entry.getKey())) { + REMOTE_BROKER_APP_MAP.put(BROKER_AMQ_PASSWORD_ENV, val); + } + } + vars.add(new EnvVar().toBuilder().withName(entry.getKey()).withValue(val == null ? entry.getValue() : val).build()); } Container container = new Container(); container.setName(REMOTE_BROKER_NAME); @@ -108,6 +121,7 @@ public Map deploy(GlowMessageWriter writer, Path target, OpenShi ret.putAll(REMOTE_BROKER_APP_MAP); return REMOTE_BROKER_APP_MAP; } + @Override public Map disabledDeploy(String appHost, String appName, String matching, Map env) { Map ret = new HashMap<>(); @@ -122,7 +136,7 @@ public Map disabledDeploy(String appHost, String appName, String String k = entry.getKey().replace("{SERVICE-NAME}", "SERVICE-NAME"); ret.put(k, entry.getValue() + descriptionServiceName); } else { - if(entry.getKey().startsWith("MQ_SERVICE_PREFIX_MAPPING")) { + if (entry.getKey().startsWith("MQ_SERVICE_PREFIX_MAPPING")) { ret.put(entry.getKey(), entry.getValue()); } @@ -146,7 +160,7 @@ public Set getSupportedAddOns() { @Override public String getName() { - return "amq_jms_broker"; + return REMOTE_BROKER_NAME; } } diff --git a/openshift-deployment/api/src/main/java/org/wildfly/glow/deployment/openshift/api/AbstractDatabaseDeployer.java b/openshift-deployment/api/src/main/java/org/wildfly/glow/deployment/openshift/api/AbstractDatabaseDeployer.java index 9335cf87..bf77941b 100644 --- a/openshift-deployment/api/src/main/java/org/wildfly/glow/deployment/openshift/api/AbstractDatabaseDeployer.java +++ b/openshift-deployment/api/src/main/java/org/wildfly/glow/deployment/openshift/api/AbstractDatabaseDeployer.java @@ -100,7 +100,7 @@ private Map getExistingEnv(Map env) { @Override public Map deploy(GlowMessageWriter writer, Path target, OpenShiftClient osClient, - Map env, String appHost, String appName, String matching) throws Exception { + Map env, String appHost, String appName, String matching, Map extraEnv) throws Exception { Map labels = new HashMap<>(); labels.put(LABEL, dbName); ContainerPort port = new ContainerPort(); @@ -110,7 +110,9 @@ public Map deploy(GlowMessageWriter writer, Path target, OpenShi ports.add(port); List vars = new ArrayList<>(); for (Map.Entry entry : CONNECTION_MAP.entrySet()) { - vars.add(new EnvVar().toBuilder().withName(entry.getKey()).withValue(entry.getValue()).build()); + // In case user overrides the default values. + String val = extraEnv.get(entry.getKey()); + vars.add(new EnvVar().toBuilder().withName(entry.getKey()).withValue(val == null ? entry.getValue() : val).build()); } Container container = new Container(); container.setName(dbName); diff --git a/openshift-deployment/api/src/main/java/org/wildfly/glow/deployment/openshift/api/Deployer.java b/openshift-deployment/api/src/main/java/org/wildfly/glow/deployment/openshift/api/Deployer.java index 9429cbd6..89023f29 100644 --- a/openshift-deployment/api/src/main/java/org/wildfly/glow/deployment/openshift/api/Deployer.java +++ b/openshift-deployment/api/src/main/java/org/wildfly/glow/deployment/openshift/api/Deployer.java @@ -33,7 +33,7 @@ public interface Deployer { String getName(); - Map deploy(GlowMessageWriter writer, Path target, OpenShiftClient osClient, Map env, String appHost, String appName, String matching) throws Exception; + Map deploy(GlowMessageWriter writer, Path target, OpenShiftClient osClient, Map env, String appHost, String appName, String matching, Map extraEnv) throws Exception; default Map disabledDeploy(String appHost, String appName, String matching, Map env) { return Collections.emptyMap(); diff --git a/openshift-deployment/api/src/main/java/org/wildfly/glow/deployment/openshift/api/OpenShiftSupport.java b/openshift-deployment/api/src/main/java/org/wildfly/glow/deployment/openshift/api/OpenShiftSupport.java index 5912edf1..bb7d81b4 100644 --- a/openshift-deployment/api/src/main/java/org/wildfly/glow/deployment/openshift/api/OpenShiftSupport.java +++ b/openshift-deployment/api/src/main/java/org/wildfly/glow/deployment/openshift/api/OpenShiftSupport.java @@ -53,6 +53,7 @@ import java.nio.file.Path; import java.security.MessageDigest; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -221,7 +222,7 @@ public static void deploy(GlowMessageWriter writer, } else { writer.warn("The deployer " + d.getName() + " has been disabled"); } - actualEnv.putAll(isDisabled ? d.disabledDeploy(host, appName, l.getName(), env) : d.deploy(writer, target, osClient, env, host, appName, l.getName())); + actualEnv.putAll(isDisabled ? Collections.emptyMap(): d.deploy(writer, target, osClient, env, host, appName, l.getName(), extraEnv)); break; } } @@ -234,7 +235,7 @@ public static void deploy(GlowMessageWriter writer, } else { writer.warn("The deployer " + d.getName() + " has been disabled"); } - actualEnv.putAll(isDisabled ? d.disabledDeploy(host, appName, ao.getName(), env) : d.deploy(writer, target, osClient, env, host, appName, ao.getName())); + actualEnv.putAll(isDisabled ? Collections.emptyMap() : d.deploy(writer, target, osClient, env, host, appName, ao.getName(), extraEnv)); break; } } @@ -246,7 +247,7 @@ public static void deploy(GlowMessageWriter writer, actualEnv.putAll(extraEnv); if (!actualEnv.isEmpty()) { if (!disabledDeployers.isEmpty()) { - writer.warn("\nThe following environment variables have been set in the " + appName + " deployment. WARN: Some of them need possibly to be updated in the deployment:\n"); + writer.warn("\nThe following environment variables have been set in the " + appName + " deployment. Make sure that the required env variables for the disabled deployer(s) have been set:\n"); } else { writer.warn("\nThe following environment variables have been set in the " + appName + " deployment:\n"); } @@ -337,7 +338,7 @@ private static String doServerImageBuild(GlowMessageWriter writer, Path target, // check if it exists ImageStream existingStream = osClient.imageStreams().resource(stream).get(); if (existingStream == null) { - writer.info("\nBuilding server image (this can take up to few minutes the first time)..."); + writer.info("\nBuilding server image (this can take up to few minutes)..."); // zip deployment and provisioning.xml to be pushed to OpenShift Path file = target.resolve("tmp").resolve("openshiftServer.zip"); if (Files.exists(file)) { diff --git a/openshift-deployment/keycloak/src/main/java/org/wildfly/glow/deployment/openshift/keycloak/KeycloakDeployer.java b/openshift-deployment/keycloak/src/main/java/org/wildfly/glow/deployment/openshift/keycloak/KeycloakDeployer.java index e0fc3d5d..20241956 100644 --- a/openshift-deployment/keycloak/src/main/java/org/wildfly/glow/deployment/openshift/keycloak/KeycloakDeployer.java +++ b/openshift-deployment/keycloak/src/main/java/org/wildfly/glow/deployment/openshift/keycloak/KeycloakDeployer.java @@ -80,11 +80,13 @@ private Map getExistingEnv(Map env) { @Override public Map deploy(GlowMessageWriter writer, Path target, OpenShiftClient osClient, Map env, - String appHost, String appName, String matching) throws Exception { + String appHost, String appName, String matching, Map extraEnv) throws Exception { writer.info("\nDeploying Keycloak server"); Map parameters = new HashMap<>(); - parameters.put(KEYCLOAK_ADMIN_ENV, KEYCLOAK_ADMIN); - parameters.put(KEYCLOAK_ADMIN_PASSWORD_ENV, KEYCLOAK_ADMIN_PASSWORD); + String adminVal = extraEnv.get(KEYCLOAK_ADMIN_ENV); + parameters.put(KEYCLOAK_ADMIN_ENV, adminVal == null ? KEYCLOAK_ADMIN : adminVal); + String adminPassword = extraEnv.get(KEYCLOAK_ADMIN_PASSWORD_ENV); + parameters.put(KEYCLOAK_ADMIN_PASSWORD_ENV, adminPassword == null ? KEYCLOAK_ADMIN_PASSWORD : adminPassword); parameters.put(NAMESPACE_ENV, osClient.getNamespace()); Template t = osClient.templates(). load(new URL(KEYCLOAK_TEMPLATE_URL)).createOr(NonDeletingOperation::update); From 0e7db91b8e208cce425cbd59960bde106c5f3710 Mon Sep 17 00:00:00 2001 From: Jean Francois Denise Date: Thu, 28 Mar 2024 17:11:08 +0100 Subject: [PATCH 8/9] Fix init-script short name --- cli/src/main/java/org/wildfly/glow/cli/commands/Constants.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/src/main/java/org/wildfly/glow/cli/commands/Constants.java b/cli/src/main/java/org/wildfly/glow/cli/commands/Constants.java index ef95af4a..073e5ebf 100644 --- a/cli/src/main/java/org/wildfly/glow/cli/commands/Constants.java +++ b/cli/src/main/java/org/wildfly/glow/cli/commands/Constants.java @@ -59,7 +59,7 @@ public interface Constants { String HELP_OPTION = "--help"; String HELP_OPTION_SHORT = "-h"; String INIT_SCRIPT_OPTION = "--init-script"; - String INIT_SCRIPT_OPTION_SHORT = "-id"; + String INIT_SCRIPT_OPTION_SHORT = "-is"; String INIT_SCRIPT_OPTION_LABEL = ""; String INPUT_FEATURE_PACKS_FILE_OPTION = "--input-feature-packs-file"; String INPUT_FEATURE_PACKS_FILE_OPTION_LABEL = ""; From 4d3affcfc7ec91185ff17dfc878bdb1ffd0d6667 Mon Sep 17 00:00:00 2001 From: Jean Francois Denise Date: Thu, 28 Mar 2024 18:03:20 +0100 Subject: [PATCH 9/9] Introduce a cli-script option for openshift --- .../wildfly/glow/cli/commands/Constants.java | 3 ++ .../glow/cli/commands/ScanCommand.java | 7 +++- .../main/resources/UsageMessages.properties | 1 + .../openshift/api/OpenShiftSupport.java | 42 ++++++++++++++----- 4 files changed, 41 insertions(+), 12 deletions(-) diff --git a/cli/src/main/java/org/wildfly/glow/cli/commands/Constants.java b/cli/src/main/java/org/wildfly/glow/cli/commands/Constants.java index 073e5ebf..0219e4cc 100644 --- a/cli/src/main/java/org/wildfly/glow/cli/commands/Constants.java +++ b/cli/src/main/java/org/wildfly/glow/cli/commands/Constants.java @@ -58,6 +58,9 @@ public interface Constants { String HELP_OPTION = "--help"; String HELP_OPTION_SHORT = "-h"; + String CLI_SCRIPT_OPTION = "--cli-script"; + String CLI_SCRIPT_OPTION_SHORT = "-cs"; + String CLI_SCRIPT_OPTION_LABEL = ""; String INIT_SCRIPT_OPTION = "--init-script"; String INIT_SCRIPT_OPTION_SHORT = "-is"; String INIT_SCRIPT_OPTION_LABEL = ""; diff --git a/cli/src/main/java/org/wildfly/glow/cli/commands/ScanCommand.java b/cli/src/main/java/org/wildfly/glow/cli/commands/ScanCommand.java index 9fcbbacb..c0c3f9cb 100644 --- a/cli/src/main/java/org/wildfly/glow/cli/commands/ScanCommand.java +++ b/cli/src/main/java/org/wildfly/glow/cli/commands/ScanCommand.java @@ -125,6 +125,9 @@ public Stability convert(String value) throws Exception { @CommandLine.Option(names = {Constants.INIT_SCRIPT_OPTION_SHORT, Constants.INIT_SCRIPT_OPTION}, paramLabel = Constants.INIT_SCRIPT_OPTION_LABEL) Optional initScriptFile; + @CommandLine.Option(names = {Constants.CLI_SCRIPT_OPTION_SHORT, Constants.CLI_SCRIPT_OPTION}, paramLabel = Constants.CLI_SCRIPT_OPTION_LABEL) + Optional cliScriptFile; + @CommandLine.Option(names = Constants.DISABLE_DEPLOYERS, split = ",", paramLabel = Constants.ADD_ONS_OPTION_LABEL) Set disableDeployers = new LinkedHashSet<>(); @@ -405,7 +408,9 @@ public Integer call() throws Exception { haProfile.orElse(false), extraEnv, disableDeployers, - initScriptFile.orElse(null), new OpenShiftConfiguration.Builder().build()); + initScriptFile.orElse(null), + cliScriptFile.orElse(null), + new OpenShiftConfiguration.Builder().build()); print("@|bold \nOpenshift build and deploy DONE.|@"); } else { if (content.getDockerImageName() != null) { diff --git a/cli/src/main/resources/UsageMessages.properties b/cli/src/main/resources/UsageMessages.properties index b5f28635..159f8092 100644 --- a/cli/src/main/resources/UsageMessages.properties +++ b/cli/src/main/resources/UsageMessages.properties @@ -39,6 +39,7 @@ config-stability-level = Specify a stability to be used when provisioning the se package-stability-level = Specify a stability to be used when provisioning server packages. The stability is also used to identify server packages that would be not provisioned by the specified stability. The stability is by default the minimum stability of each Galleon feature-packs. The stability can be @|fg(yellow) default|@, @|fg(yellow) community|@, @|fg(yellow) preview|@, @|fg(yellow) experimental|@. env-file = The path to a file that contains environment variables (in the form env=value) to be passed to the OpenShift deployment. Can only be used with @|fg(yellow) OPENSHIFT|@ kind of provisioning. init-script = The path to a script that contains commands (JBoss CLI, add-user, ...) to fine tune the server on OpenShift deployment. Can only be used with @|fg(yellow) OPENSHIFT|@ kind of provisioning. +cli-script = The path to a CLI script file that only contains CLI commands in order to fine tune the server on OpenShift deployment. Can only be used with @|fg(yellow) OPENSHIFT|@ kind of provisioning. disable-deployers = A comma separated list of deployer names to disable. To retrieve all the deployer names call the @|fg(yellow) show-configuration|@ operation. To disable them all, use @|fg(yellow) ALL|@ value. Can only be used with @|fg(yellow) OPENSHIFT|@ kind of provisioning. properties = A space separated list of Java system properties. When multiple system properties are set, the list must be enclosed in double quotes. For example: "-Dfoo=bar -DmyProp" diff --git a/openshift-deployment/api/src/main/java/org/wildfly/glow/deployment/openshift/api/OpenShiftSupport.java b/openshift-deployment/api/src/main/java/org/wildfly/glow/deployment/openshift/api/OpenShiftSupport.java index bb7d81b4..aa3f10e0 100644 --- a/openshift-deployment/api/src/main/java/org/wildfly/glow/deployment/openshift/api/OpenShiftSupport.java +++ b/openshift-deployment/api/src/main/java/org/wildfly/glow/deployment/openshift/api/OpenShiftSupport.java @@ -185,7 +185,9 @@ public static void deploy(GlowMessageWriter writer, boolean ha, Map extraEnv, Set disabledDeployers, - Path initScript, OpenShiftConfiguration config) throws Exception { + Path initScript, + Path cliScript, + OpenShiftConfiguration config) throws Exception { Map actualEnv = new TreeMap<>(); OpenShiftClient osClient = new KubernetesClientBuilder().build().adapt(OpenShiftClient.class); writer.info("\nConnected to OpenShift cluster"); @@ -242,7 +244,7 @@ public static void deploy(GlowMessageWriter writer, } } - createBuild(writer, target, osClient, appName, initScript, config); + createBuild(writer, target, osClient, appName, initScript, cliScript, config); actualEnv.put("APPLICATION_ROUTE_HOST", host); actualEnv.putAll(extraEnv); if (!actualEnv.isEmpty()) { @@ -265,16 +267,35 @@ private static void createBuild(GlowMessageWriter writer, OpenShiftClient osClient, String name, Path initScript, + Path cliScript, OpenShiftConfiguration config) throws Exception { String serverImageName = doServerImageBuild(writer, target, osClient, config); - doAppImageBuild(serverImageName, writer, target, osClient, name, initScript, config); + doAppImageBuild(serverImageName, writer, target, osClient, name, initScript, cliScript, config); } - private static void packageInitScript(Path initScript, Path target) throws Exception { - Path extensions = target.resolve("extensions"); - Files.createDirectories(extensions); - Path postconfigure = extensions.resolve("postconfigure.sh"); - Files.copy(initScript, postconfigure); + private static boolean packageInitScript(Path initScript, Path cliScript, Path target) throws Exception { + if (initScript != null || cliScript != null) { + Path extensions = target.resolve("extensions"); + Files.createDirectories(extensions); + StringBuilder initExecution = new StringBuilder(); + initExecution.append("#!/bin/bash").append("\n"); + if (initScript != null) { + initExecution.append("echo \"Calling initialization script\"").append("\n"); + Path init = extensions.resolve("init-script.sh"); + Files.copy(initScript, init); + initExecution.append("sh $JBOSS_HOME/extensions/init-script.sh").append("\n"); + } + if (cliScript != null) { + initExecution.append("echo \"Calling CLI script\"").append("\n"); + Path cli = extensions.resolve("cli-script.cli"); + Files.copy(cliScript, cli); + initExecution.append("cat $JBOSS_HOME/extensions/cli-script.cli >> \"${CLI_SCRIPT_FILE}\""); + } + Path postconfigure = extensions.resolve("postconfigure.sh"); + Files.write(postconfigure, initExecution.toString().getBytes()); + return true; + } + return false; } private static boolean isDisabled(String name, Set disabledDeployers) { @@ -386,6 +407,7 @@ private static void doAppImageBuild(String serverImageName, OpenShiftClient osClient, String name, Path initScript, + Path cliScript, OpenShiftConfiguration config) throws Exception { // Now step 2 // From the server image, do a docker build, copy the server and copy in it the deployments and init file. @@ -395,9 +417,7 @@ private static void doAppImageBuild(String serverImageName, dockerFileBuilder.append("FROM " + config.getRuntimeImage() + "\n"); dockerFileBuilder.append("COPY --chown=jboss:root /server $JBOSS_HOME\n"); dockerFileBuilder.append("COPY --chown=jboss:root deployments/* $JBOSS_HOME/standalone/deployments\n"); - - if (initScript != null) { - packageInitScript(initScript, stepTwo); + if (packageInitScript(initScript, cliScript, stepTwo)) { dockerFileBuilder.append("COPY --chown=jboss:root extensions $JBOSS_HOME/extensions\n"); dockerFileBuilder.append("RUN chmod ug+rwx $JBOSS_HOME/extensions/postconfigure.sh\n"); }