Skip to content

Commit 24608e6

Browse files
authored
Allow createAuxImage to install the WDT installer and the WDT model files separately (#345)
1 parent 4440286 commit 24608e6

File tree

7 files changed

+61
-34
lines changed

7 files changed

+61
-34
lines changed

imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/cache/AddInstallerEntry.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ public class AddInstallerEntry extends CacheAddOperation {
1919

2020
@Override
2121
public CommandResponse call() throws CacheStoreException {
22+
if ("NONE".equalsIgnoreCase(version)) {
23+
throw new IllegalArgumentException("IMG-0105");
24+
}
2225
String key = String.format("%s%s%s", type, CacheStore.CACHE_KEY_SEPARATOR, version);
2326
return addToCache(key);
2427
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public CommandResponse call() throws Exception {
6464
}
6565
dockerfileOptions.setOracleHome(oracleHome);
6666

67-
if (wdtOptions.isUsingWdt() && !wdtOptions.modelOnly()) {
67+
if (wdtOptions.userProvidedFiles() && !wdtOptions.modelOnly()) {
6868
String domainHome = baseImageProperties.getProperty("domainHome", null);
6969
if (domainHome == null && wdtOperation == WdtOperation.UPDATE) {
7070
return CommandResponse.error("IMG-0071", fromImage());

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

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import com.oracle.weblogic.imagetool.logging.LoggingFacade;
1717
import com.oracle.weblogic.imagetool.logging.LoggingFactory;
1818
import com.oracle.weblogic.imagetool.util.DockerfileOptions;
19+
import com.oracle.weblogic.imagetool.util.Utils;
1920
import picocli.CommandLine.Option;
2021

2122
import static com.oracle.weblogic.imagetool.cachestore.CacheStoreFactory.cache;
@@ -26,13 +27,21 @@ public class WdtBaseOptions {
2627
public static final String WDT_HOME_LABEL = "<WDT home directory>";
2728

2829
/**
29-
* Return true if the user provided a WDT model or WDT archive on the command line.
30-
* @return true if the user provided a WDT file as input on the command line.
30+
* Return true if the user provided WDT models, WDT archives, or WDT variables on the command line.
31+
* @return true if the user provided at least one WDT file as input on the command line.
3132
*/
32-
public boolean isWdtModelProvided() {
33+
public boolean userProvidedFiles() {
3334
return wdtModelPath != null || wdtArchivePath != null || wdtVariablesPath != null;
3435
}
3536

37+
/**
38+
* Return true if the user did not specify --wdtVersion=NONE.
39+
* @return true if the tool should install WDT binaries.
40+
*/
41+
public boolean skipWdtInstaller() {
42+
return wdtVersion.equalsIgnoreCase("NONE");
43+
}
44+
3645
/**
3746
* Return the value provided for --wdtModelHome.
3847
* This value is used as the location to install the provided WDT models, archives, and variable files.
@@ -51,9 +60,11 @@ public String wdtModelHome() {
5160
public void handleWdtArgs(DockerfileOptions dockerfileOptions, String tmpDir) throws IOException {
5261
logger.entering(tmpDir);
5362

54-
if (isWdtModelProvided()) {
55-
dockerfileOptions.setWdtEnabled();
63+
if (!userProvidedFiles() && skipWdtInstaller()) {
64+
// if user did not provide models, variables, archives, or a WDT installer, there is nothing to do.
65+
throw new IllegalArgumentException(Utils.getMessage("IMG-0104"));
5666
}
67+
dockerfileOptions.setWdtEnabled();
5768

5869
dockerfileOptions.setWdtHome(wdtHome).setWdtModelHome(wdtModelHome);
5970

@@ -72,10 +83,11 @@ public void handleWdtArgs(DockerfileOptions dockerfileOptions, String tmpDir) th
7283
dockerfileOptions.setWdtVariables(variablesList);
7384
}
7485

75-
CachedFile wdtInstaller = new CachedFile(InstallerType.WDT, wdtVersion);
76-
Path wdtfile = wdtInstaller.copyFile(cache(), tmpDir);
77-
dockerfileOptions.setWdtInstallerFilename(wdtfile.getFileName().toString());
78-
86+
if (!skipWdtInstaller()) {
87+
CachedFile wdtInstaller = new CachedFile(InstallerType.WDT, wdtVersion);
88+
Path wdtfile = wdtInstaller.copyFile(cache(), tmpDir);
89+
dockerfileOptions.setWdtInstallerFilename(wdtfile.getFileName().toString());
90+
}
7991
logger.exiting();
8092
}
8193

@@ -91,8 +103,7 @@ private List<String> addWdtFilesAsList(Path fileArg, String type, String tmpDir)
91103
Files.copy(individualPath, Paths.get(tmpDir, modelFilename));
92104
fileList.add(modelFilename);
93105
} else {
94-
String errMsg = String.format("WDT %s file %s not found ", type, individualFile);
95-
throw new FileNotFoundException(errMsg);
106+
throw new FileNotFoundException(Utils.getMessage("IMG-0102",type, individualFile));
96107
}
97108
}
98109
return fileList;

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,6 @@ public class WdtFullOptions extends WdtBaseOptions {
1919

2020
private static final LoggingFacade logger = LoggingFactory.getLogger(WdtFullOptions.class);
2121

22-
/**
23-
* Return true if the user specified a WDT model or WDT archive on the command line.
24-
* @return true if WDT was selected by the user
25-
*/
26-
public boolean isUsingWdt() {
27-
return wdtModelOnly || isWdtModelProvided();
28-
}
29-
3022
/**
3123
* Return true if the user specified the wdtModelOnly option, and
3224
* WDT should not run a create or update script.
@@ -46,10 +38,16 @@ public boolean modelOnly() {
4638
@Override
4739
public void handleWdtArgs(DockerfileOptions dockerfileOptions, String tmpDir) throws IOException {
4840
logger.entering(tmpDir);
49-
if (!isUsingWdt()) {
41+
if (!userProvidedFiles()) {
42+
// user did not provide any WDT files, nothing to do for WDT.
5043
logger.exiting();
5144
return;
5245
}
46+
if (skipWdtInstaller()) {
47+
// user provided model files but specified WDT version NONE. NONE is only valid for Aux images.
48+
throw new IllegalArgumentException(Utils.getMessage("IMG-0103"));
49+
}
50+
// user provided WDT files and a WDT installer, so call WdtBaseOptions.handleWdtArgs
5351
super.handleWdtArgs(dockerfileOptions, tmpDir);
5452

5553
String encryptionKey = Utils.getPasswordFromInputs(encryptionKeyStr, encryptionKeyFile, encryptionKeyEnv);
@@ -78,7 +76,7 @@ public void handleResourceTemplates(String imageName) throws IOException {
7876
DomainHomeSourceType domainType = DomainHomeSourceType.PV;
7977
if (modelOnly()) {
8078
domainType = DomainHomeSourceType.MODEL;
81-
} else if (isUsingWdt()) {
79+
} else if (userProvidedFiles()) {
8280
domainType = DomainHomeSourceType.IMAGE;
8381
}
8482

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,10 @@ public boolean isWdtEnabled() {
601601
return useWdt;
602602
}
603603

604+
public boolean installWdt() {
605+
return wdtInstallerFilename != null;
606+
}
607+
604608
/**
605609
* Referenced by the Dockerfile template to determine which command to use to install WDT.
606610
*
@@ -716,6 +720,11 @@ public List<String> wdtVariables() {
716720
return wdtVariableList;
717721
}
718722

723+
@SuppressWarnings("unused")
724+
public boolean hasWdtFiles() {
725+
return !wdtModelList.isEmpty() || !wdtVariableList.isEmpty() || !wdtArchiveList.isEmpty();
726+
}
727+
719728
/**
720729
* Referenced by Dockerfile template, provides the WDT argument for 1..n variable files.
721730
*

imagetool/src/main/resources/ImageTool.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,7 @@ IMG-0098=Patch [[red: {0}]] is a Stack Patch Bundle, not a patch. Remove {0} fro
100100
IMG-0099=Patch [[red: {0}]] is only for version {1} and may not be applicable to the target version {2}. Check Oracle Support, there may be another patch number for version {2}. Or check the OPatch output for results for this image.
101101
IMG-0100=Missing argument --fromImage. Update requires an image to be updated. Use --fromImage to specify the image to build on.
102102
IMG-0101=The version of OPatch that you requested is not available: {0}
103+
IMG-0102=WDT {0} file [[brightred: {1}]] could not be found.
104+
IMG-0103=wdtVersion cannot be none, a valid version from the Image Tool cache is required.
105+
IMG-0104=You must provide at least one of: a WDT installer file, a WDT model file, a WDT variable file, or a WDT archive file.
106+
IMG-0105=Installer version cannot use keyword of 'none'.

imagetool/src/main/resources/docker-files/aux-image.mustache

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,17 @@ RUN mkdir -p {{{wdt_home}}} \
2222
&& mkdir -p {{{wdt_model_home}}} \
2323
&& chown {{userid}}:{{groupid}} {{{wdt_home}}}
2424

25-
COPY --chown={{userid}}:{{groupid}} {{{wdtInstaller}}} {{{tempDir}}}/
26-
27-
RUN test -d {{{wdt_home}}}/weblogic-deploy && rm -rf {{{wdt_home}}}/weblogic-deploy || echo Initial WDT install \
28-
{{#usingWdtTarGzInstaller}}
29-
&& tar zxf {{{tempDir}}}/{{{wdtInstaller}}} -C {{{wdt_home}}}
30-
{{/usingWdtTarGzInstaller}}
31-
{{^usingWdtTarGzInstaller}}
32-
&& unzip -q {{{tempDir}}}/{{{wdtInstaller}}} -d {{{wdt_home}}}
33-
{{/usingWdtTarGzInstaller}}
25+
{{#installWdt}}
26+
COPY --chown={{userid}}:{{groupid}} {{{wdtInstaller}}} {{{tempDir}}}/
27+
28+
RUN test -d {{{wdt_home}}}/weblogic-deploy && rm -rf {{{wdt_home}}}/weblogic-deploy || echo Initial WDT install \
29+
{{#usingWdtTarGzInstaller}}
30+
&& tar zxf {{{tempDir}}}/{{{wdtInstaller}}} -C {{{wdt_home}}}
31+
{{/usingWdtTarGzInstaller}}
32+
{{^usingWdtTarGzInstaller}}
33+
&& unzip -q {{{tempDir}}}/{{{wdtInstaller}}} -d {{{wdt_home}}}
34+
{{/usingWdtTarGzInstaller}}
35+
{{/installWdt}}
3436

3537
FROM os_update as final
3638

@@ -54,9 +56,9 @@ COPY --from=wdt_build --chown={{userid}}:{{groupid}} {{wdt_home}} {{wdt_home}}/
5456
COPY --chown={{userid}}:{{groupid}} {{{.}}} {{{wdt_model_home}}}/
5557
{{/wdtVariables}}
5658

57-
{{#isWdtEnabled}}
58-
RUN chmod -R 640 {{{wdt_model_home}}}/*
59-
{{/isWdtEnabled}}
59+
{{#hasWdtFiles}}
60+
RUN chmod -R 640 {{{wdt_model_home}}}/*
61+
{{/hasWdtFiles}}
6062

6163
USER {{userid}}
6264

0 commit comments

Comments
 (0)