Skip to content

Commit

Permalink
cleanup 2 phases build
Browse files Browse the repository at this point in the history
  • Loading branch information
jfdenise committed Mar 13, 2024
1 parent 0758f81 commit 84d8a5f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ private static void createAppDeployment(GlowMessageWriter writer, Path target, O
}

static void deploy(GlowMessageWriter writer, Path target, String appName, Map<String, String> env, Set<Layer> layers, Set<AddOn> addOns, boolean ha,
Map<String, String> extraEnv, Set<String> disabledDeployers) throws Exception {
Map<String, String> extraEnv, Set<String> disabledDeployers, Path initScript) throws Exception {
Map<String, String> actualEnv = new TreeMap<>();
OpenShiftClient osClient = new KubernetesClientBuilder().build().adapt(OpenShiftClient.class);
writer.info("\nConnected to OpenShift cluster");
Expand Down Expand Up @@ -232,7 +232,7 @@ static void deploy(GlowMessageWriter writer, Path target, String appName, Map<St
}
}

createBuild(writer, target, osClient, appName);
createBuild(writer, target, osClient, appName, initScript);
actualEnv.put("APPLICATION_ROUTE_HOST", host);
actualEnv.putAll(extraEnv);
if (!actualEnv.isEmpty()) {
Expand All @@ -249,7 +249,12 @@ static void deploy(GlowMessageWriter writer, Path target, String appName, Map<St
writer.info("\nApplication route: https://" + host + ("ROOT.war".equals(appName) ? "" : "/" + appName));
}

public static void packageInitScript(Path initScript, Path target) throws Exception {
static void createBuild(GlowMessageWriter writer, Path target, OpenShiftClient osClient, String name, Path initScript) throws Exception {
String serverImageName = doServerImageBuild(writer, target, osClient);
doAppImageBuild(serverImageName, writer, target, osClient, name, initScript);
}

private static void packageInitScript(Path initScript, Path target) throws Exception {
Path extensions = target.resolve("extensions");
Files.createDirectories(extensions);
Path postconfigure = extensions.resolve("postconfigure.sh");
Expand All @@ -272,7 +277,7 @@ private static String bytesToHex(byte[] hash) {
return hexString.toString();
}

static void createBuild(GlowMessageWriter writer, Path target, OpenShiftClient osClient, String name) throws Exception {
static String doServerImageBuild(GlowMessageWriter writer, Path target, OpenShiftClient osClient) throws Exception {
Path provisioning = target.resolve("galleon").resolve("provisioning.xml");
byte[] content = Files.readAllBytes(provisioning);
MessageDigest digest = MessageDigest.getInstance("SHA-256");
Expand All @@ -284,7 +289,6 @@ static void createBuild(GlowMessageWriter writer, Path target, OpenShiftClient o
endMetadata().withNewSpec().withLookupPolicy(new ImageLookupPolicy(Boolean.TRUE)).endSpec().build();
// check if it exists
ImageStream existingStream = osClient.imageStreams().resource(stream).get();
writer.info("\nCreating and starting application image build on OpenShift...");
if (existingStream == null) {
writer.info("\nBuilding server image (this can take up to few minutes the first time)...");
// zip deployment and provisioning.xml to be pushed to OpenShift
Expand Down Expand Up @@ -325,6 +329,10 @@ static void createBuild(GlowMessageWriter writer, Path target, OpenShiftClient o
latch.await();
}
}
return serverImageName;
}

static void doAppImageBuild(String serverImageName, GlowMessageWriter writer, Path target, OpenShiftClient osClient, String name, Path initScript) 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("step-two");
Expand All @@ -334,9 +342,8 @@ static void createBuild(GlowMessageWriter writer, Path target, OpenShiftClient o
dockerFileBuilder.append("COPY --chown=jboss:root /server $JBOSS_HOME\n");
dockerFileBuilder.append("COPY --chown=jboss:root deployments/* $JBOSS_HOME/standalone/deployments\n");

Path extensions = target.resolve("extensions");
if(Files.exists(extensions)) {
IoUtils.copy(extensions, stepTwo.resolve("extensions"));
if (initScript != null) {
packageInitScript(initScript, stepTwo);
dockerFileBuilder.append("COPY --chown=jboss:root extensions $JBOSS_HOME/extensions\n");
dockerFileBuilder.append("RUN chmod ug+rwx $JBOSS_HOME/extensions/postconfigure.sh\n");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,17 +341,14 @@ public Integer call() throws Exception {
int ext = p.getFileName().toString().indexOf(".");
name = p.getFileName().toString().substring(0, ext);
}
if (initScriptFile.isPresent()) {
OpenShiftSupport.packageInitScript(initScriptFile.get(), target);
}
Map<String, String> envMap = new HashMap<>();
for(Set<Env> 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);
scanResults.getEnabledAddOns(), haProfile.orElse(false), extraEnv, disableDeployers, initScriptFile.orElse(null));
print("@|bold Openshift build and deploy DONE.|@");
}
if (content.getDockerImageName() != null) {
Expand Down

0 comments on commit 84d8a5f

Please sign in to comment.