Skip to content

Commit fbb4779

Browse files
jshum2479Johnny Shumddsharpe
authored
#190 - support configurable model home location (#194)
* #190 - support configurable model home location * skip WDT validation when no models or archives are present Co-authored-by: Johnny Shum <[email protected]> Co-authored-by: Derek Sharpe <[email protected]>
1 parent 128ac15 commit fbb4779

File tree

4 files changed

+69
-34
lines changed

4 files changed

+69
-34
lines changed

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

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class WdtOptions {
3232
* @return true if WDT was selected by the user
3333
*/
3434
boolean isUsingWdt() {
35-
return wdtModelPath != null || wdtArchivePath != null;
35+
return wdtModelOnly || wdtModelPath != null || wdtArchivePath != null;
3636
}
3737

3838
/**
@@ -65,25 +65,24 @@ void handleWdtArgs(DockerfileOptions dockerfileOptions, DockerBuildCommand cmdBu
6565
cmdBuilder.buildArg("WDT_ENCRYPTION_KEY", encryptionKey, true);
6666
}
6767

68-
dockerfileOptions.setWdtEnabled();
69-
dockerfileOptions.setWdtModelOnly(wdtModelOnly);
68+
dockerfileOptions.setWdtEnabled()
69+
.setDomainHome(wdtDomainHome)
70+
.setJavaOptions(wdtJavaOptions)
71+
.setWdtDomainType(wdtDomainType)
72+
.setRunRcu(runRcu)
73+
.setWdtStrictValidation(wdtStrictValidation)
74+
.setWdtModelOnly(wdtModelOnly)
75+
.setWdtModelHome(wdtModelHome);
76+
7077
if (wdtModelPath != null) {
7178
List<String> modelList = addWdtFilesAsList(wdtModelPath, "model", tmpDir);
7279
dockerfileOptions.setWdtModels(modelList);
7380
}
7481

75-
dockerfileOptions.setWdtDomainType(wdtDomainType);
76-
dockerfileOptions.setRunRcu(runRcu);
77-
7882
if (wdtArchivePath != null) {
79-
8083
List<String> archiveList = addWdtFilesAsList(wdtArchivePath, "archive", tmpDir);
81-
8284
dockerfileOptions.setWdtArchives(archiveList);
8385
}
84-
dockerfileOptions.setDomainHome(wdtDomainHome);
85-
86-
dockerfileOptions.setJavaOptions(wdtJavaOptions);
8786

8887
if (wdtVariablesPath != null && Files.isRegularFile(wdtVariablesPath)) {
8988
String wdtVariableFilename = wdtVariablesPath.getFileName().toString();
@@ -92,8 +91,6 @@ void handleWdtArgs(DockerfileOptions dockerfileOptions, DockerBuildCommand cmdBu
9291
dockerfileOptions.setWdtVariables(Collections.singletonList(wdtVariableFilename));
9392
}
9493

95-
dockerfileOptions.setWdtStrictValidation(wdtStrictValidation);
96-
9794
CachedFile wdtInstaller = new CachedFile(InstallerType.WDT, wdtVersion);
9895
Path wdtfile = wdtInstaller.copyFile(cache(), tmpDir);
9996
dockerfileOptions.setWdtInstallerFilename(wdtfile.getFileName().toString());
@@ -180,6 +177,13 @@ private List<String> addWdtFilesAsList(Path fileArg, String type, String tmpDir)
180177
@SuppressWarnings("FieldCanBeLocal")
181178
private boolean wdtModelOnly = false;
182179

180+
@Option(
181+
names = {"--wdtModelHome"},
182+
description = "Copy the models to the location in the image Default: ${DEFAULT-VALUE}.",
183+
defaultValue = "/u01/wdt/models"
184+
)
185+
private String wdtModelHome;
186+
183187
@Option(
184188
names = {"--wdtStrictValidation"},
185189
description = "Use strict validation for the WDT validation method. Only applies when using model only. "

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

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
import com.oracle.weblogic.imagetool.installer.MiddlewareInstallPackage;
1616
import com.oracle.weblogic.imagetool.wdt.WdtOperation;
1717

18+
/**
19+
* Provides the data used by the Dockerfile templates (in mustache).
20+
*/
1821
public class DockerfileOptions {
1922

2023
private static final String DEFAULT_JAVA_HOME = "/u01/jdk";
@@ -51,6 +54,7 @@ public class DockerfileOptions {
5154

5255
// WDT values
5356
private String wdtHome;
57+
private String wdtModelHome;
5458
private ArrayList<String> wdtModelList;
5559
private ArrayList<String> wdtArchiveList;
5660
private ArrayList<String> wdtVariableList;
@@ -91,6 +95,7 @@ public DockerfileOptions(String buildId) {
9195
// WDT values
9296
useWdt = false;
9397
wdtHome = "/u01/wdt";
98+
wdtModelHome = wdtHome + "/models";
9499
wdtOperation = WdtOperation.CREATE;
95100
wdtModelList = new ArrayList<>();
96101
wdtArchiveList = new ArrayList<>();
@@ -191,6 +196,18 @@ public DockerfileOptions setTargetImage(String value) {
191196
return this;
192197
}
193198

199+
/**
200+
* The location where the wdt models will be copied to.
201+
*
202+
* @return this DockerfileOptions object
203+
*/
204+
public DockerfileOptions setWdtModelHome(String value) {
205+
if (value != null) {
206+
wdtModelHome = value;
207+
}
208+
return this;
209+
}
210+
194211
/**
195212
* Return if the rebase to existing target image.
196213
* @return true or false
@@ -285,6 +302,15 @@ public String wdt_home() {
285302
return wdtHome;
286303
}
287304

305+
@SuppressWarnings("unused")
306+
public String wdt_model_home() {
307+
return wdtModelHome;
308+
}
309+
310+
public boolean isWdtValidateEnabled() {
311+
return isWdtEnabled() && modelOnly() && (!wdtModelList.isEmpty() || !wdtArchiveList.isEmpty());
312+
}
313+
288314
/**
289315
* The directory for the WORKDIR in the Docker build.
290316
* @return the value for the WORKDIR
@@ -342,25 +368,27 @@ public void setOraInvDir(String value) {
342368
* WDT -domain_home.
343369
* @param value the full path to the domain directory
344370
*/
345-
public void setDomainHome(String value) {
371+
public DockerfileOptions setDomainHome(String value) {
346372
if (value != null) {
347373
domainHome = value;
348374
} else {
349375
domainHome = DEFAULT_DOMAIN_HOME;
350376
}
377+
return this;
351378
}
352379

353380
/**
354381
* Set the JAVA_HOME environment variable for the Dockerfile to be written.
355382
*
356383
* @param value the folder where JAVA is or should be installed, aka JAVA_HOME.
357384
*/
358-
public void setJavaHome(String value) {
385+
public DockerfileOptions setJavaHome(String value) {
359386
if (value != null) {
360387
javaHome = value;
361388
} else {
362389
javaHome = DEFAULT_JAVA_HOME;
363390
}
391+
return this;
364392
}
365393

366394
/**
@@ -583,7 +611,7 @@ private String wdtGetFileArgument(String wdtParameterName, List<String> filename
583611
StringJoiner result = new StringJoiner(",", wdtParameterName,"");
584612
result.setEmptyValue("");
585613
for (String name : filenames) {
586-
result.add(wdtHome + "/models/" + name);
614+
result.add(wdtModelHome + "/" + name);
587615
}
588616
return result.toString();
589617
}

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,28 +140,28 @@ RUN {{{oracle_home}}}/OPatch/opatch napply -silent -oh {{{oracle_home}}} -phBase
140140
USER {{userid}}
141141

142142
RUN cd {{{wdt_home}}} \
143-
&& mkdir models \
143+
&& mkdir -p {{{wdt_model_home}}} \
144144
&& mkdir -p $(dirname {{{domain_home}}})
145145

146146
{{#wdtModels}}
147-
COPY --chown={{userid}}:{{groupid}} {{{.}}} {{{wdt_home}}}/models/
147+
COPY --chown={{userid}}:{{groupid}} {{{.}}} {{{wdt_model_home}}}/
148148
{{/wdtModels}}
149149

150150
{{#wdtArchives}}
151-
COPY --chown={{userid}}:{{groupid}} {{{.}}} {{{wdt_home}}}/models/
151+
COPY --chown={{userid}}:{{groupid}} {{{.}}} {{{wdt_model_home}}}/
152152
{{/wdtArchives}}
153153

154154
{{#wdtVariables}}
155-
COPY --chown={{userid}}:{{groupid}} {{{.}}} {{{wdt_home}}}/models/
155+
COPY --chown={{userid}}:{{groupid}} {{{.}}} {{{wdt_model_home}}}/
156156
{{/wdtVariables}}
157157

158158
{{#beforeWdtCommand}}
159159
{{{.}}}
160160
{{/beforeWdtCommand}}
161161

162-
RUN unzip -q {{{tempDir}}}/{{{wdtInstaller}}} -d {{{wdt_home}}} \
163-
&& cd {{{wdt_home}}}/weblogic-deploy/bin \
162+
RUN unzip -q {{{tempDir}}}/{{{wdtInstaller}}} -d {{{wdt_home}}}
164163
{{^modelOnly}}
164+
RUN cd {{{wdt_home}}}/weblogic-deploy/bin \
165165
&& {{#isWdtUseEncryption}}echo $WDT_ENCRYPTION_KEY | {{/isWdtUseEncryption}} ./createDomain.sh \
166166
-oracle_home {{{oracle_home}}} \
167167
-domain_home {{{domain_home}}} \
@@ -174,13 +174,14 @@ RUN {{{oracle_home}}}/OPatch/opatch napply -silent -oh {{{oracle_home}}} -phBase
174174
{{/runRcu}}
175175
{{{wdtVariableFileArgument}}} {{{wdtModelFileArgument}}} {{{wdtArchiveFileArgument}}}
176176
{{/modelOnly}}
177-
{{#modelOnly}}
177+
{{#isWdtValidateEnabled}}
178+
RUN cd {{{wdt_home}}}/weblogic-deploy/bin \
178179
&& chmod u+x ./*.sh \
179180
&& ./validateModel.sh {{^strictValidation}}-method lax{{/strictValidation}} \
180181
-oracle_home {{{oracle_home}}} \
181182
-domain_type {{domainType}} \
182183
{{{wdtVariableFileArgument}}} {{{wdtModelFileArgument}}} {{{wdtArchiveFileArgument}}}
183-
{{/modelOnly}}
184+
{{/isWdtValidateEnabled}}
184185

185186
{{#afterWdtCommand}}
186187
{{{.}}}
@@ -227,6 +228,8 @@ COPY --from=WLS_BUILD --chown={{userid}}:{{groupid}} {{{oracle_home}}} {{{oracle
227228
{{#isWdtEnabled}}
228229
{{#modelOnly}}
229230
COPY --from=WDT_BUILD --chown={{userid}}:{{groupid}} {{wdt_home}} {{wdt_home}}/
231+
RUN mkdir -p {{{wdt_model_home}}}
232+
COPY --from=WDT_BUILD --chown={{userid}}:{{groupid}} {{wdt_model_home}} {{wdt_model_home}}/
230233
{{/modelOnly}}
231234
{{^modelOnly}}
232235
COPY --from=WDT_BUILD --chown={{userid}}:{{groupid}} {{{domain_home}}} {{{domain_home}}}/

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@
2424
USER {{userid}}
2525

2626
RUN cd {{{wdt_home}}} \
27-
&& mkdir models \
27+
&& mkdir -p {{{wdt_model_home}}} \
2828
&& mkdir -p $(dirname {{{domain_home}}})
2929

3030
{{#wdtModels}}
31-
COPY --chown={{userid}}:{{groupid}} {{.}} {{{wdt_home}}}/models/
31+
COPY --chown={{userid}}:{{groupid}} {{.}} {{{wdt_model_home}}}/
3232
{{/wdtModels}}
3333

3434
{{#wdtArchives}}
35-
COPY --chown={{userid}}:{{groupid}} {{.}} {{{wdt_home}}}/models/
35+
COPY --chown={{userid}}:{{groupid}} {{.}} {{{wdt_model_home}}}/
3636
{{/wdtArchives}}
3737

3838
{{#wdtVariables}}
39-
COPY --chown={{userid}}:{{groupid}} {{.}} {{{wdt_home}}}/models/
39+
COPY --chown={{userid}}:{{groupid}} {{.}} {{{wdt_model_home}}}/
4040
{{/wdtVariables}}
4141

4242
{{#beforeWdtCommand}}
@@ -47,8 +47,7 @@
4747
&& jar xf {{{tempDir}}}/{{{wdtInstaller}}}
4848

4949
{{^modelOnly}}
50-
RUN cd {{{wdt_home}}} \
51-
&& cd weblogic-deploy/bin \
50+
RUN cd {{{wdt_home}}}/weblogic-deploy/bin \
5251
&& chmod u+x ./*.sh \
5352
&& {{#isWdtUseEncryption}}echo $WDT_ENCRYPTION_KEY | {{/isWdtUseEncryption}} ./{{wdtCommand}} \
5453
-oracle_home {{{oracle_home}}} \
@@ -62,15 +61,14 @@
6261
{{/runRcu}}
6362
{{{wdtVariableFileArgument}}} {{{wdtModelFileArgument}}} {{{wdtArchiveFileArgument}}}
6463
{{/modelOnly}}
65-
{{#modelOnly}}
66-
RUN cd {{{wdt_home}}} \
67-
&& cd weblogic-deploy/bin \
64+
{{#isWdtValidateEnabled}}
65+
RUN cd {{{wdt_home}}}/weblogic-deploy/bin \
6866
&& chmod u+x ./*.sh \
6967
&& ./validateModel.sh {{^strictValidation}}-method lax{{/strictValidation}} \
7068
-oracle_home {{{oracle_home}}} \
7169
-domain_type {{domainType}} \
7270
{{{wdtVariableFileArgument}}} {{{wdtModelFileArgument}}} {{{wdtArchiveFileArgument}}}
73-
{{/modelOnly}}
71+
{{/isWdtValidateEnabled}}
7472

7573
{{#afterWdtCommand}}
7674
{{{.}}}
@@ -115,6 +113,8 @@ USER {{userid}}
115113
{{#isWdtEnabled}}
116114
{{#modelOnly}}
117115
COPY --from=WDT_BUILD --chown={{userid}}:{{groupid}} {{wdt_home}} {{wdt_home}}/
116+
RUN mkdir -p {{{wdt_model_home}}}
117+
COPY --from=WDT_BUILD --chown={{userid}}:{{groupid}} {{wdt_model_home}} {{wdt_model_home}}/
118118
{{/modelOnly}}
119119
{{^modelOnly}}
120120
COPY --from=WDT_BUILD --chown={{userid}}:{{groupid}} {{{domain_home}}} {{{domain_home}}}/

0 commit comments

Comments
 (0)