Skip to content

Commit 3cec205

Browse files
authored
Added support to override FMW installer response file. (#57)
* Added support to override FMW installer response file. * Set Oracle Home based on contents of installer response file
1 parent 9501f8e commit 3cec205

File tree

8 files changed

+110
-42
lines changed

8 files changed

+110
-42
lines changed

imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/menu/CreateImage.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ public CommandResponse call() throws Exception {
6767
return result;
6868
}
6969

70-
List<String> cmdBuilder = getInitialBuildCmd();
7170
tmpDir = getTempDirectory();
7271

7372
if (!Utils.validatePatchIds(patches, false)) {
@@ -109,6 +108,8 @@ public CommandResponse call() throws Exception {
109108
dockerfileOptions.setPackageInstaller(Constants.YUM);
110109
}
111110

111+
List<String> cmdBuilder = getInitialBuildCmd();
112+
112113
// this handles wls, jdk and wdt install files.
113114
cmdBuilder.addAll(handleInstallerFiles(tmpDir));
114115

@@ -120,6 +121,7 @@ public CommandResponse call() throws Exception {
120121

121122
// Copy wls response file to tmpDir
122123
copyResponseFilesToDir(tmpDir);
124+
Utils.setOracleHome(installerResponseFile, dockerfileOptions);
123125

124126
// Create Dockerfile
125127
Utils.writeDockerfile(tmpDir + File.separator + "Dockerfile", "Create_Image.mustache",
@@ -192,7 +194,7 @@ List<String> handlePatchFiles(String tmpDir, Path tmpPatchesDir) throws Exceptio
192194
new ArrayList<>(toValidateSet), installerType.toString(), installerVersion, userId,
193195
password);
194196
if (validationResult.isSuccess()) {
195-
logger.info("patch conflict check successful");
197+
logger.info("IMG-0006");
196198
} else {
197199
String error = validationResult.getErrorMessage();
198200
logger.severe(error);
@@ -329,7 +331,7 @@ private List<InstallerFile> gatherRequiredInstallers() throws Exception {
329331
* @throws Exception in case of error
330332
*/
331333
private void addWdtUrl(String wdtKey) throws Exception {
332-
logger.finer("Entering CreateImage.wdtKey: ");
334+
logger.entering(wdtKey);
333335
String wdtUrlKey = wdtKey + "_url";
334336
if (cacheStore.getValueFromCache(wdtKey) == null) {
335337
if (userId == null || password == null) {
@@ -340,13 +342,13 @@ private void addWdtUrl(String wdtKey) throws Exception {
340342
"weblogic-deploy-tooling-" + wdtVersion;
341343
if (wdtTags.contains(tagToMatch)) {
342344
String downloadLink = String.format(Constants.WDT_URL_FORMAT, tagToMatch);
343-
logger.info("WDT Download link = " + downloadLink);
345+
logger.info("IMG-0007", downloadLink);
344346
cacheStore.addToCache(wdtUrlKey, downloadLink);
345347
} else {
346348
throw new Exception("Couldn't find WDT download url for version:" + wdtVersion);
347349
}
348350
}
349-
logger.finer("Exiting CreateImage.wdtKey: ");
351+
logger.exiting();
350352
}
351353

352354
/**
@@ -356,7 +358,16 @@ private void addWdtUrl(String wdtKey) throws Exception {
356358
* @throws IOException in case of error
357359
*/
358360
private void copyResponseFilesToDir(String dirPath) throws IOException {
359-
Utils.copyResourceAsFile("/response-files/wls.rsp", dirPath, false);
361+
if (installerResponseFile != null && Files.isRegularFile(installerResponseFile)) {
362+
logger.fine("IMG-0005", installerResponseFile);
363+
Path target = Paths.get(dirPath, "wls.rsp");
364+
Files.copy(installerResponseFile, target);
365+
} else {
366+
final String responseFile = "/response-files/wls.rsp";
367+
logger.fine("IMG-0005", responseFile);
368+
Utils.copyResourceAsFile(responseFile, dirPath, false);
369+
}
370+
360371
Utils.copyResourceAsFile("/response-files/oraInst.loc", dirPath, false);
361372
}
362373

@@ -447,4 +458,9 @@ private void copyResponseFilesToDir(String dirPath) throws IOException {
447458
private String opatchBugNumber;
448459

449460

461+
@Option(
462+
names = {"--installerResponseFile"},
463+
description = "path to a response file. Override the default responses for the Oracle installer"
464+
)
465+
private Path installerResponseFile;
450466
}

imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/menu/ImageOperation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ List<String> handlePatchFiles(String tmpDir, Path tmpPatchesDir) throws Exceptio
146146
*/
147147
List<String> getInitialBuildCmd() {
148148

149-
logger.finer("Entering ImageOperation.getInitialBuildCmd");
149+
logger.entering();
150150
List<String> cmdBuilder = Stream.of("docker", "build",
151151
"--force-rm=true", "--no-cache").collect(Collectors.toList());
152152

@@ -171,7 +171,7 @@ List<String> getInitialBuildCmd() {
171171
if (dockerPath != null && Files.isExecutable(dockerPath)) {
172172
cmdBuilder.set(0, dockerPath.toAbsolutePath().toString());
173173
}
174-
logger.finer("Exiting ImageOperation.getInitialBuildCmd");
174+
logger.exiting();
175175
return cmdBuilder;
176176
}
177177

imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/menu/UpdateImage.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ public CommandResponse call() throws Exception {
8989
String opatchFile = cacheStore.getValueFromCache(opatchBugNumber + "_opatch");
9090
if (opatchFile != null) {
9191
opatchBugNumberVersion = Utils.getOpatchVersionFromZip(opatchFile);
92-
logger.info(String.format("OPatch patch number %s cached file %s version %s", opatchBugNumber,
93-
opatchFile, opatchBugNumberVersion));
92+
logger.info("IMG-0008", opatchBugNumber, opatchFile, opatchBugNumberVersion);
9493
} else {
9594
String msg = String.format("OPatch patch number --opatchBugNumber %s cannot be found in cache",
9695
opatchBugNumber);
@@ -111,7 +110,7 @@ public CommandResponse call() throws Exception {
111110
if (latestPSU || !patches.isEmpty()) {
112111
logger.finer("Verifying Patches to WLS ");
113112
if (userId == null) {
114-
logger.warning("skipping patch conflict check, no support credentials provided ");
113+
logger.warning("IMG-0009");
115114
} else {
116115

117116
if (!Utils.validatePatchIds(patches, false)) {
@@ -152,7 +151,7 @@ public CommandResponse call() throws Exception {
152151
if (!validationResult.isSuccess()) {
153152
return new CommandResponse(-1, validationResult.getErrorMessage());
154153
} else {
155-
logger.info("patch conflict check successful");
154+
logger.info("IMG-0006");
156155
}
157156
} else {
158157
return new CommandResponse(-1, "lsinventory missing. required to check for conflicts");

imagetool/src/main/java/com/oracle/weblogic/imagetool/util/DockerfileOptions.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
package com.oracle.weblogic.imagetool.util;
55

66
import java.util.ArrayList;
7-
import java.util.Arrays;
87
import java.util.List;
98
import java.util.StringJoiner;
109

@@ -23,6 +22,7 @@ public class DockerfileOptions {
2322
private String username;
2423
private String groupname;
2524
private String javaHome;
25+
private String oracleHome;
2626
private String tempDirectory;
2727
private String baseImageName;
2828
private ArrayList<String> wdtModelList;
@@ -42,6 +42,7 @@ public DockerfileOptions() {
4242
groupname = "oracle";
4343

4444
javaHome = "/u01/jdk";
45+
oracleHome = "/u01/oracle";
4546
tempDirectory = "/tmp/delme";
4647

4748
baseImageName = "oraclelinux:7-slim";
@@ -128,6 +129,14 @@ public String java_home() {
128129
return javaHome;
129130
}
130131

132+
public String oracle_home() {
133+
return oracleHome;
134+
}
135+
136+
public void setOracleHome(String value) {
137+
oracleHome = value;
138+
}
139+
131140
/**
132141
* Set the JAVA_HOME environment variable for the Dockerfile to be written.
133142
*

imagetool/src/main/java/com/oracle/weblogic/imagetool/util/Utils.java

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import java.io.BufferedReader;
77
import java.io.File;
8+
import java.io.FileNotFoundException;
89
import java.io.FileOutputStream;
910
import java.io.FileReader;
1011
import java.io.FileWriter;
@@ -29,7 +30,6 @@
2930
import java.util.List;
3031
import java.util.Objects;
3132
import java.util.Properties;
32-
import java.util.logging.Logger;
3333
import java.util.regex.Matcher;
3434
import java.util.regex.Pattern;
3535
import java.util.stream.Collectors;
@@ -532,7 +532,7 @@ public static String getPasswordFromInputs(String passwordStr, Path passwordFile
532532
throws IOException {
533533
if (!isEmptyString(passwordStr)) {
534534
return passwordStr;
535-
} else if (passwordFile != null && Files.isRegularFile(passwordFile) && Files.size(passwordFile) > 0) {
535+
} else if (validFile(passwordFile)) {
536536
try (BufferedReader bufferedReader = new BufferedReader(new FileReader(passwordFile.toFile()))) {
537537
return bufferedReader.readLine();
538538
}
@@ -674,4 +674,45 @@ public static boolean validatePatchIds(List<String> patches, boolean rigid) {
674674

675675
return result;
676676
}
677+
678+
/**
679+
* Set the Oracle Home directory based on the installer response file.
680+
* If no Oracle Home is provided in the response file, do nothing and accept the default value.
681+
* @param installerResponseFile installer response file to parse.
682+
* @param options Dockerfile options to use for the build (holds the Oracle Home argument)
683+
*/
684+
public static void setOracleHome(Path installerResponseFile, DockerfileOptions options) throws IOException {
685+
if (installerResponseFile == null) {
686+
return;
687+
}
688+
689+
Pattern pattern = Pattern.compile("^ORACLE_HOME=(.*)?");
690+
Matcher matcher = pattern.matcher("");
691+
logger.finest("Reading installer response file: {0}", installerResponseFile.getFileName());
692+
693+
try {
694+
BufferedReader reader = new BufferedReader(new FileReader(installerResponseFile.toFile()));
695+
String line;
696+
while ((line = reader.readLine()) != null) {
697+
logger.finest("Read response file line: {0}", line);
698+
699+
matcher.reset(line);
700+
if (matcher.find()) {
701+
String oracleHome = matcher.group(1);
702+
if (oracleHome != null) {
703+
options.setOracleHome(oracleHome);
704+
logger.info("IMG-0010", oracleHome);
705+
}
706+
break;
707+
}
708+
}
709+
} catch (FileNotFoundException notFound) {
710+
logger.severe("Unable to find installer response file: {0}", installerResponseFile);
711+
throw notFound;
712+
}
713+
}
714+
715+
private static boolean validFile(Path file) throws IOException {
716+
return file != null && Files.isRegularFile(file) && Files.size(file) > 0;
717+
}
677718
}

imagetool/src/main/resources/ImageTool.properties

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,10 @@ IMG-0000=JAVA_HOME detected in base image, skipping JDK install: {0}
22
IMG-0001=Gathering installer {0}:{1}
33
IMG-0002=User specified fromImage {0}
44
IMG-0003=Temporary directory used for docker build context: {0}
5-
IMG-0004=Invalid patch id {0}. The patch id must be in the format of {1}. Where the first part is the 8 digit patch ID, and the second half, after the underscore, is the release version for the patch. The release version needs to be specified with 5 places such as 12.2.1.3.0 or 12.2.1.3.190416. Release version is required when adding a patch to the cache or when multiple versions of the same patch number exist for different versions.
5+
IMG-0004=Invalid patch id {0}. The patch id must be in the format of {1}. Where the first part is the 8 digit patch ID, and the second half, after the underscore, is the release version for the patch. The release version needs to be specified with 5 places such as 12.2.1.3.0 or 12.2.1.3.190416. Release version is required when adding a patch to the cache or when multiple versions of the same patch number exist for different versions.
6+
IMG-0005=Installer response file: {0}
7+
IMG-0006=patch conflict check successful
8+
IMG-0007=WDT Download link = {0}
9+
IMG-0008=OPatch patch number {0} cached file {1} version {2}
10+
IMG-0009=skipping patch conflict check, no support credentials provided
11+
IMG-0010=Oracle Home will be set to {0}

0 commit comments

Comments
 (0)