Skip to content

Commit b4536b6

Browse files
jshum2479ddsharpe
authored andcommitted
Provide options for specifying inventory file and location #103 (#107)
* Add support for specifying inventory location and file * update documentation * bug fixes * Copy the user provided inventory pointer file as oraInst.loc * remove INV_LOC and change final oraInst layer copy * optimize inventory files copying
1 parent 931b297 commit b4536b6

File tree

7 files changed

+200
-10
lines changed

7 files changed

+200
-10
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.io.File;
77
import java.time.Duration;
88
import java.time.Instant;
9+
import java.util.ArrayList;
910
import java.util.List;
1011
import java.util.Properties;
1112
import java.util.UUID;
@@ -76,8 +77,22 @@ public CommandResponse call() throws Exception {
7677

7778
// Copy wls response file to tmpDir
7879
WLSInstallHelper.copyResponseFilesToDir(tmpDir, installerResponseFile);
80+
7981
Utils.setOracleHome(installerResponseFile, dockerfileOptions);
8082

83+
// Set where the user want to install the inventor oraInst.loc file
84+
85+
if (inventoryPointerInstallLoc != null) {
86+
dockerfileOptions.setInventoryPointerFileSet(true);
87+
dockerfileOptions.setInvLoc(inventoryPointerInstallLoc);
88+
}
89+
90+
// Set the inventory location, so that it will be copied
91+
if (inventoryPointerFile != null) {
92+
Utils.setInventoryLocation(inventoryPointerFile, dockerfileOptions);
93+
Utils.copyLocalFile(inventoryPointerFile, tmpDir + "/oraInst.loc", false);
94+
}
95+
8196
// Create Dockerfile
8297
String dockerfile = Utils.writeDockerfile(tmpDir + File.separator + "Dockerfile",
8398
"Create_Image.mustache", dockerfileOptions, dryRun);
@@ -154,6 +169,18 @@ String getInstallerVersion() {
154169
)
155170
private String installerResponseFile;
156171

172+
@Option(
173+
names = {"--inventoryPointerFile"},
174+
description = "path to a user provided inventory pointer file as input"
175+
)
176+
private String inventoryPointerFile;
177+
178+
@Option(
179+
names = {"--inventoryPointerInstallLoc"},
180+
description = "path to where the inventory pointer file (oraInst.loc) should be stored in the image"
181+
)
182+
private String inventoryPointerInstallLoc;
183+
157184
@ArgGroup(exclusive = false, heading = "WDT Options%n")
158185
private WdtOptions wdtOptions = new WdtOptions();
159186
}

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

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
package com.oracle.weblogic.imagetool.util;
55

6+
import java.io.File;
67
import java.util.ArrayList;
78
import java.util.List;
89
import java.util.Map;
@@ -15,6 +16,10 @@ public class DockerfileOptions {
1516
private static final String DEFAULT_JAVA_HOME = "/u01/jdk";
1617
private static final String DEFAULT_ORACLE_HOME = "/u01/oracle";
1718
private static final String DEFAULT_DOMAIN_HOME = "/u01/domains/base_domain";
19+
// Default location for the oraInst.loc
20+
private static final String DEFAULT_INV_LOC = "/u01/oracle";
21+
22+
private static final String DEFAULT_ORAINV_DIR = "/u01/oracle/oraInventory";
1823

1924
final String buildId;
2025
boolean useYum = false;
@@ -26,13 +31,16 @@ public class DockerfileOptions {
2631
private boolean applyPatches;
2732
private boolean updateOpatch;
2833
private boolean skipJavaInstall;
34+
private boolean inventoryPointerFileSet = false;
2935
private boolean isRebaseToTarget;
3036
private boolean isRebaseToNew;
3137

3238
private String username;
3339
private String groupname;
3440
private String javaHome;
3541
private String oracleHome;
42+
private String invLoc;
43+
private String oraInvDir;
3644
private String domainHome;
3745
private String tempDirectory;
3846
private String baseImageName;
@@ -70,6 +78,9 @@ public DockerfileOptions(String buildId) {
7078
javaHome = DEFAULT_JAVA_HOME;
7179
oracleHome = DEFAULT_ORACLE_HOME;
7280
domainHome = DEFAULT_DOMAIN_HOME;
81+
invLoc = DEFAULT_INV_LOC;
82+
oraInvDir = DEFAULT_ORAINV_DIR;
83+
7384
tempDirectory = "/tmp/imagetool";
7485

7586
baseImageName = "oraclelinux:7-slim";
@@ -245,6 +256,16 @@ public String oracle_home() {
245256
return oracleHome;
246257
}
247258

259+
260+
public String inv_loc() {
261+
return invLoc;
262+
}
263+
264+
public String orainv_dir() {
265+
return oraInvDir;
266+
}
267+
268+
248269
@SuppressWarnings("unused")
249270
public String domain_home() {
250271
return domainHome;
@@ -277,6 +298,29 @@ public void setOracleHome(String value) {
277298
}
278299
}
279300

301+
302+
/**
303+
* Set the INV_LOC environment variable for the Dockerfile to be written.
304+
*
305+
* @param value the folder where Oracle Middleware is or should be installed, aka INV_LOC.
306+
*/
307+
public void setInvLoc(String value) {
308+
if (value != null) {
309+
invLoc = value;
310+
} else {
311+
invLoc = DEFAULT_INV_LOC;
312+
}
313+
}
314+
315+
316+
public void setOraInvDir(String value) {
317+
if (value != null) {
318+
oraInvDir = value;
319+
} else {
320+
oraInvDir = DEFAULT_ORAINV_DIR;
321+
}
322+
}
323+
280324
/**
281325
* Set the Domain directory to be used by WDT domain creation.
282326
* WDT -domain_home.
@@ -391,6 +435,42 @@ public boolean isWdtEnabled() {
391435
return useWdt;
392436
}
393437

438+
439+
/**
440+
* copyOraInst check if it needs to copy the oraInst.loc file.
441+
* @return true if it needs to copy
442+
*/
443+
444+
public boolean copyOraInst() {
445+
return !isSubDirectoryOrSame(invLoc, oracleHome);
446+
}
447+
448+
/**
449+
* copyOraInventoryDir check if it needs to copy the oraInventory Directory.
450+
* @return true if it needs to copy
451+
*/
452+
453+
public boolean copyOraInventoryDir() {
454+
return !isSubDirectoryOrSame(oraInvDir, oracleHome);
455+
}
456+
457+
/**
458+
* isSubDirectoryOrSame compare if the child is a subdirectory of parent (non java.io implementation).
459+
* @param child child directory name
460+
* @param parent parent directory name
461+
* @return true if child is a subdirectory of parent otherwise false
462+
*/
463+
464+
private static boolean isSubDirectoryOrSame(String child, String parent) {
465+
boolean result = true;
466+
child = child.endsWith(File.separator) ? child.substring(0, child.length() - 1) : child;
467+
parent = parent.endsWith(File.separator) ? parent.substring(0, parent.length() - 1) : parent;
468+
if (!child.equals(parent)) {
469+
result = child.startsWith(parent);
470+
}
471+
return result;
472+
}
473+
394474
/**
395475
* If WDT is enabled, and the model is not in the archive, the model file argument must be set.
396476
* @param value a model filename, or comma-separated model filenames.
@@ -403,6 +483,19 @@ public DockerfileOptions setWdtModels(List<String> value) {
403483
return this;
404484
}
405485

486+
/**
487+
* If inventoryPointerFileSet is set.
488+
*
489+
* @return true if inventoryPointerFileSet is set
490+
*/
491+
public boolean isInventoryPointerFileSet() {
492+
return inventoryPointerFileSet;
493+
}
494+
495+
public void setInventoryPointerFileSet(boolean value) {
496+
this.inventoryPointerFileSet = value;
497+
}
498+
406499
/**
407500
* Referenced by Dockerfile template, a simple list of model filenames.
408501
*

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

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,27 @@ public static void copyResourceAsFile(String resourcePath, String destPath, bool
8383
}
8484
}
8585

86+
/**
87+
* Utility method to copy a local file to another local file system location.
88+
*
89+
* @param sourcePath resource path in the local directory
90+
* @param destPath local file to copy to.
91+
* @param markExec sets the executable flag if true
92+
* @throws IOException in case of error
93+
*/
94+
public static void copyLocalFile(String sourcePath, String destPath, boolean markExec) throws IOException {
95+
Objects.requireNonNull(sourcePath);
96+
Objects.requireNonNull(destPath);
97+
Files.copy(Paths.get(sourcePath), Paths.get(destPath),
98+
StandardCopyOption.REPLACE_EXISTING);
99+
if (markExec) {
100+
if (!System.getProperty("os.name").toLowerCase().startsWith("windows")) {
101+
Files.setPosixFilePermissions(Paths.get(destPath), PosixFilePermissions.fromString("r-xr-xr-x"));
102+
}
103+
}
104+
}
105+
106+
86107
/**
87108
* Create a file with the given path.
88109
*
@@ -728,6 +749,46 @@ public static void setOracleHome(String installerResponse, DockerfileOptions opt
728749
}
729750
}
730751

752+
753+
/**
754+
* Set the Inventory Location directory based on the inventory pointer file.
755+
*
756+
* @param inventoryLocFile installer response file to parse.
757+
* @param options Dockerfile options to use for the build (holds the Oracle Home argument)
758+
*/
759+
public static void setInventoryLocation(String inventoryLocFile, DockerfileOptions options) throws IOException {
760+
if (inventoryLocFile == null) {
761+
return;
762+
}
763+
Path inventoryLoc = Paths.get(inventoryLocFile);
764+
Pattern pattern = Pattern.compile("^\\s*inventory_loc=(.*)?");
765+
Matcher matcher = pattern.matcher("");
766+
logger.finer("Reading inventory location file: {0}", inventoryLoc.getFileName());
767+
768+
try {
769+
BufferedReader reader = new BufferedReader(new FileReader(inventoryLoc.toFile()));
770+
String line;
771+
while ((line = reader.readLine()) != null) {
772+
logger.finest("Read inventory loc file line: {0}", line);
773+
774+
matcher.reset(line);
775+
if (matcher.find()) {
776+
String invLoc = matcher.group(1);
777+
if (invLoc != null) {
778+
options.setOraInvDir(invLoc);
779+
}
780+
break;
781+
}
782+
}
783+
} catch (FileNotFoundException notFound) {
784+
logger.severe("IMG-0036", inventoryLoc);
785+
throw notFound;
786+
}
787+
}
788+
789+
790+
791+
731792
private static boolean validFile(Path file) throws IOException {
732793
return file != null && Files.isRegularFile(file) && Files.size(file) > 0;
733794
}

imagetool/src/main/resources/ImageTool.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ IMG-0032=Failed to find latest PSU for {0}, version {1}
3434
IMG-0033=No credentials provided, skipping validation of patches
3535
IMG-0034=There are multiple patches found with id {0}, please specify the format as one of the following for the release you want
3636
IMG-0035=Multiple patches with the same patch number detected
37+
IMG-0036=Unable to find installer inventory file: {0}

imagetool/src/main/resources/docker-files/Create_Image.mustache

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,19 @@ RUN tar xzf {{{tempDir}}}/$JAVA_PKG -C /u01 \
6565
FROM OS_UPDATE as WLS_BUILD
6666
LABEL com.oracle.weblogic.imagetool.buildid="{{buildId}}"
6767
ARG WLS_PKG
68-
ARG INV_LOC
69-
ARG ORAINST
7068

7169
ENV WLS_PKG=${WLS_PKG:-fmw_12.2.1.3.0_wls_Disk1_1of1.zip} \
7270
JAVA_HOME={{{java_home}}} \
7371
ORACLE_HOME={{{oracle_home}}} \
74-
INV_LOC=${INV_LOC:-/u01/oracle/oraInventory} \
75-
ORAINST=${ORAINST:-oraInst.loc} \
7672
OPATCH_NO_FUSER=true
7773

7874
RUN mkdir -p {{{oracle_home}}} \
75+
{{#isInventoryPointerFileSet}}
76+
&& mkdir -p {{inv_loc}} \
77+
&& chown {{userid}}:{{groupid}} {{inv_loc}} \
78+
{{/isInventoryPointerFileSet}}
79+
&& mkdir -p {{orainv_dir}} \
80+
&& chown {{userid}}:{{groupid}} {{orainv_dir}} \
7981
&& chown {{userid}}:{{groupid}} {{{oracle_home}}}
8082

8183
# Install base WLS
@@ -84,7 +86,7 @@ RUN mkdir -p {{{oracle_home}}} \
8486
{{/installJava}}
8587

8688
COPY --chown={{userid}}:{{groupid}} $WLS_PKG wls.rsp {{{tempDir}}}/
87-
COPY --chown={{userid}}:{{groupid}} $ORAINST $INV_LOC/
89+
COPY --chown={{userid}}:{{groupid}} oraInst.loc {{inv_loc}}/
8890

8991
{{#isOpatchPatchingEnabled}}
9092
COPY --chown={{userid}}:{{groupid}} {{{opatchFileName}}} {{{tempDir}}}/opatch/
@@ -102,7 +104,7 @@ USER {{userid}}
102104

103105
RUN unzip -q {{{tempDir}}}/$WLS_PKG -d {{{tempDir}}} \
104106
&& {{{java_home}}}/bin/java -Xmx1024m -jar {{{tempDir}}}/fmw_*.jar -silent ORACLE_HOME={{{oracle_home}}} \
105-
-responseFile {{{tempDir}}}/wls.rsp -invPtrLoc $INV_LOC/$ORAINST -ignoreSysPrereqs -force -novalidation \
107+
-responseFile {{{tempDir}}}/wls.rsp -invPtrLoc {{inv_loc}}/oraInst.loc -ignoreSysPrereqs -force -novalidation \
106108
{{#isOpatchPatchingEnabled}}
107109
&& cd {{{tempDir}}}/opatch \
108110
&& {{{java_home}}}/bin/jar -xf {{{tempDir}}}/opatch/{{{opatchFileName}}} \
@@ -214,6 +216,12 @@ LABEL com.oracle.weblogic.imagetool.buildid="{{buildId}}"
214216
{{/installJava}}
215217

216218
COPY --from=WLS_BUILD --chown={{userid}}:{{groupid}} {{{oracle_home}}} {{{oracle_home}}}/
219+
{{#copyOraInst}}
220+
COPY --from=WLS_BUILD --chown={{userid}}:{{groupid}} {{inv_loc}}/oraInst.loc {{inv_loc}}/oraInst.loc
221+
{{/copyOraInst}}
222+
{{#copyOraInventoryDir}}
223+
COPY --from=WLS_BUILD --chown={{userid}}:{{groupid}} {{orainv_dir}} {{orainv_dir}}/
224+
{{/copyOraInventoryDir}}
217225

218226
{{#isWdtEnabled}}
219227
{{#modelOnly}}

imagetool/src/main/resources/docker-files/Rebase_Image.mustache

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,11 @@ COPY --from=SOURCE_IMAGE --chown={{userid}}:{{groupid}} {{domain_home}} {{domain
9191
LABEL com.oracle.weblogic.imagetool.buildid="{{buildId}}"
9292
ARG WLS_PKG
9393
ARG INV_LOC
94-
ARG ORAINST
9594

9695
ENV WLS_PKG=${WLS_PKG:-fmw_12.2.1.3.0_wls_Disk1_1of1.zip} \
9796
JAVA_HOME={{{java_home}}} \
9897
ORACLE_HOME={{{oracle_home}}} \
9998
INV_LOC=${INV_LOC:-/u01/oracle/oraInventory} \
100-
ORAINST=${ORAINST:-oraInst.loc} \
10199
OPATCH_NO_FUSER=true
102100

103101
RUN mkdir -p {{{oracle_home}}} \
@@ -109,7 +107,7 @@ COPY --from=SOURCE_IMAGE --chown={{userid}}:{{groupid}} {{domain_home}} {{domain
109107
{{/installJava}}
110108

111109
COPY --chown={{userid}}:{{groupid}} $WLS_PKG wls.rsp {{{tempDir}}}/
112-
COPY --chown={{userid}}:{{groupid}} $ORAINST $INV_LOC/
110+
COPY --chown={{userid}}:{{groupid}} oraInst.loc $INV_LOC/
113111

114112
{{#isOpatchPatchingEnabled}}
115113
COPY --chown={{userid}}:{{groupid}} {{{opatchFileName}}} {{{tempDir}}}/opatch/
@@ -127,7 +125,7 @@ COPY --from=SOURCE_IMAGE --chown={{userid}}:{{groupid}} {{domain_home}} {{domain
127125

128126
RUN unzip -q {{{tempDir}}}/$WLS_PKG -d {{{tempDir}}} \
129127
&& {{{java_home}}}/bin/java -Xmx1024m -jar {{{tempDir}}}/fmw_*.jar -silent ORACLE_HOME={{{oracle_home}}} \
130-
-responseFile {{{tempDir}}}/wls.rsp -invPtrLoc $INV_LOC/$ORAINST -ignoreSysPrereqs -force -novalidation \
128+
-responseFile {{{tempDir}}}/wls.rsp -invPtrLoc $INV_LOC/oraInst.loc -ignoreSysPrereqs -force -novalidation \
131129
{{#isOpatchPatchingEnabled}}
132130
&& cd {{{tempDir}}}/opatch \
133131
&& {{{java_home}}}/bin/jar -xf {{{tempDir}}}/opatch/{{{opatchFileName}}} \

site/create-image.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ Usage: imagetool create [OPTIONS]
3737
| `--wdtStrictValidation` | Use strict validation for the WDT validation method. Only applies when using model only. | `false` |
3838
| `--wdtVariables` | Path to the WDT variables file for use with the WDT model. | |
3939
| `--wdtVersion` | WDT tool version to use. | |
40+
| `--inventoryPointerFile` | Path to inventory pointer file. | |
41+
| `--inventoryPointerInstallLoc` | Path to where to store the inventory pointer file. | |
4042

4143
## Additional information
4244

0 commit comments

Comments
 (0)