9
9
import java .nio .file .Files ;
10
10
import java .nio .file .Path ;
11
11
import java .nio .file .Paths ;
12
- import java .nio .file .attribute .PosixFilePermissions ;
13
12
import java .time .Duration ;
14
13
import java .time .Instant ;
15
14
import java .util .ArrayList ;
@@ -57,8 +56,7 @@ public CommandResponse call() throws Exception {
57
56
logger .finer ("Entering CreateImage call " );
58
57
Instant startTime = Instant .now ();
59
58
60
- Path tmpDir = null ;
61
- Path tmpDir2 = null ;
59
+ String tmpDir = null ;
62
60
63
61
try {
64
62
@@ -68,13 +66,7 @@ public CommandResponse call() throws Exception {
68
66
}
69
67
70
68
List <String > cmdBuilder = getInitialBuildCmd ();
71
- tmpDir = Files .createTempDirectory (Paths .get (Utils .getBuildWorkingDir ()),
72
- "wlsimgbuilder_temp" ,
73
- PosixFilePermissions .asFileAttribute (PosixFilePermissions .fromString ("rwxr-xr-x" )));
74
- String tmpDirPath = tmpDir .toAbsolutePath ().toString ();
75
- logger .info ("tmp directory used for build context: " + tmpDirPath );
76
- Path tmpPatchesDir = Files .createDirectory (Paths .get (tmpDirPath , "patches" ));
77
- Files .createFile (Paths .get (tmpPatchesDir .toAbsolutePath ().toString (), "dummy.txt" ));
69
+ tmpDir = getTempDirectory ();
78
70
79
71
// this handles wls, jdk and wdt install files.
80
72
cmdBuilder .addAll (handleInstallerFiles (tmpDir ));
@@ -88,7 +80,7 @@ public CommandResponse call() throws Exception {
88
80
dockerfileOptions .setBaseImage (fromImage );
89
81
90
82
Utils .copyResourceAsFile ("/probe-env/test-create-env.sh" ,
91
- tmpDir . toAbsolutePath (). toString () + File .separator + "test-env.sh" , true );
83
+ tmpDir + File .separator + "test-env.sh" , true );
92
84
93
85
List <String > imageEnvCmd = Utils .getDockerRunCmd (tmpDir , fromImage , "test-env.sh" );
94
86
Properties baseImageProperties = Utils .runDockerCommand (imageEnvCmd );
@@ -111,20 +103,20 @@ public CommandResponse call() throws Exception {
111
103
}
112
104
113
105
// build wdt args if user passes --wdtModelPath
114
- cmdBuilder .addAll (handleWDTArgsIfRequired (tmpDir ));
106
+ cmdBuilder .addAll (handleWdtArgsIfRequired (tmpDir ));
115
107
116
108
// resolve required patches
117
- cmdBuilder .addAll (handlePatchFiles (tmpDir , tmpPatchesDir ));
109
+ cmdBuilder .addAll (handlePatchFiles (tmpDir , createPatchesTempDirectory ( tmpDir ) ));
118
110
119
111
// Copy wls response file to tmpDir
120
- copyResponseFilesToDir (tmpDirPath );
112
+ copyResponseFilesToDir (tmpDir );
121
113
122
114
// Create Dockerfile
123
- Utils .writeDockerfile (tmpDirPath + File .separator + "Dockerfile" , "Create_Image.mustache" ,
115
+ Utils .writeDockerfile (tmpDir + File .separator + "Dockerfile" , "Create_Image.mustache" ,
124
116
dockerfileOptions );
125
117
126
118
// add directory to pass the context
127
- cmdBuilder .add (tmpDirPath );
119
+ cmdBuilder .add (tmpDir );
128
120
logger .info ("docker cmd = " + String .join (" " , cmdBuilder ));
129
121
Utils .runDockerCommand (isCLIMode , cmdBuilder , dockerLog );
130
122
} catch (Exception ex ) {
@@ -146,19 +138,18 @@ public CommandResponse call() throws Exception {
146
138
* @return list of strings
147
139
* @throws Exception in case of error
148
140
*/
149
- private List <String > handleInstallerFiles (Path tmpDir ) throws Exception {
141
+ private List <String > handleInstallerFiles (String tmpDir ) throws Exception {
150
142
151
- logger .finer ("Entering CreateImage.handleInstallerFiles: " + tmpDir . toAbsolutePath (). toString () );
143
+ logger .finer ("Entering CreateImage.handleInstallerFiles: " + tmpDir );
152
144
List <String > retVal = new LinkedList <>();
153
- String tmpDirPath = tmpDir .toAbsolutePath ().toString ();
154
145
List <InstallerFile > requiredInstallers = gatherRequiredInstallers ();
155
- for (InstallerFile eachInstaller : requiredInstallers ) {
156
- String targetFilePath = eachInstaller .resolve (cacheStore );
157
- logger .finer ("Entering CreateImage.handleInstallerFiles targetFilePath: " + targetFilePath );
158
- File targetFile = new File (targetFilePath );
146
+ for (InstallerFile installerFile : requiredInstallers ) {
147
+ String targetFilePath = installerFile .resolve (cacheStore );
148
+ logger .finer ("CreateImage.handleInstallerFiles copying targetFilePath: " + targetFilePath );
149
+ String filename = new File (targetFilePath ). getName ( );
159
150
try {
160
- Path targetLink = Files .copy (Paths .get (targetFilePath ), Paths .get (tmpDirPath , targetFile . getName () ));
161
- retVal .addAll (eachInstaller .getBuildArg (tmpDir . relativize ( targetLink ). toString () ));
151
+ Files .copy (Paths .get (targetFilePath ), Paths .get (tmpDir , filename ));
152
+ retVal .addAll (installerFile .getBuildArg (filename ));
162
153
} catch (Exception ee ) {
163
154
ee .printStackTrace ();
164
155
}
@@ -168,8 +159,8 @@ private List<String> handleInstallerFiles(Path tmpDir) throws Exception {
168
159
}
169
160
170
161
@ Override
171
- List <String > handlePatchFiles (Path tmpDir , Path tmpPatchesDir ) throws Exception {
172
- logger .finer ("Entering CreateImage.handlePatchFiles: " + tmpDir . toAbsolutePath (). toString () );
162
+ List <String > handlePatchFiles (String tmpDir , Path tmpPatchesDir ) throws Exception {
163
+ logger .finer ("Entering CreateImage.handlePatchFiles: " + tmpDir );
173
164
if ((latestPSU || !patches .isEmpty ()) && Utils .compareVersions (installerVersion ,
174
165
Constants .DEFAULT_WLS_VERSION ) == 0 ) {
175
166
addOPatch1394ToImage (tmpDir , opatchBugNumber );
@@ -213,10 +204,9 @@ List<String> handlePatchFiles(Path tmpDir, Path tmpPatchesDir) throws Exception
213
204
* @return list of build args
214
205
* @throws IOException in case of error
215
206
*/
216
- private List <String > handleWDTArgsIfRequired ( Path tmpDir ) throws IOException {
217
- logger .finer ("Entering CreateImage.handleWDTArgsIfRequired : " + tmpDir . toAbsolutePath (). toString () );
207
+ private List <String > handleWdtArgsIfRequired ( String tmpDir ) throws IOException {
208
+ logger .finer ("Entering CreateImage.handleWdtArgsIfRequired : " + tmpDir );
218
209
List <String > retVal = new LinkedList <>();
219
- String tmpDirPath = tmpDir .toAbsolutePath ().toString ();
220
210
if (wdtModelPath != null ) {
221
211
if (Files .isRegularFile (wdtModelPath )) {
222
212
if (wdtDomainType != DomainType .WLS ) {
@@ -231,17 +221,16 @@ private List<String> handleWDTArgsIfRequired(Path tmpDir) throws IOException {
231
221
}
232
222
}
233
223
dockerfileOptions .setWdtEnabled ();
234
- Path targetLink = Files . copy ( wdtModelPath , Paths . get ( tmpDirPath , wdtModelPath . getFileName ().toString ())
235
- );
224
+ String modelFilename = wdtModelPath . getFileName ().toString ();
225
+ Files . copy ( wdtModelPath , Paths . get ( tmpDir , modelFilename ) );
236
226
retVal .add (Constants .BUILD_ARG );
237
- retVal .add ("WDT_MODEL=" + tmpDir . relativize ( targetLink ). toString () );
227
+ retVal .add ("WDT_MODEL=" + modelFilename );
238
228
239
229
if (wdtArchivePath != null && Files .isRegularFile (wdtArchivePath )) {
240
- targetLink = Files .copy (wdtArchivePath , Paths .get (tmpDirPath ,
241
- wdtArchivePath .getFileName ().toString ())
242
- );
230
+ String archiveFilename = wdtArchivePath .getFileName ().toString ();
231
+ Files .copy (wdtArchivePath , Paths .get (tmpDir , archiveFilename ));
243
232
retVal .add (Constants .BUILD_ARG );
244
- retVal .add ("WDT_ARCHIVE=" + tmpDir . relativize ( targetLink ). toString () );
233
+ retVal .add ("WDT_ARCHIVE=" + archiveFilename );
245
234
}
246
235
247
236
if (wdtDomainHome != null ) {
@@ -251,15 +240,14 @@ private List<String> handleWDTArgsIfRequired(Path tmpDir) throws IOException {
251
240
252
241
253
242
if (wdtVariablesPath != null && Files .isRegularFile (wdtVariablesPath )) {
254
- targetLink = Files .copy (wdtVariablesPath , Paths .get (tmpDirPath ,
255
- wdtVariablesPath .getFileName ().toString ())
256
- );
243
+ String variableFileName = wdtVariablesPath .getFileName ().toString ();
244
+ Files .copy (wdtVariablesPath , Paths .get (tmpDir , variableFileName ));
257
245
retVal .add (Constants .BUILD_ARG );
258
- retVal .add ("WDT_VARIABLE=" + tmpDir . relativize ( targetLink ). toString () );
259
- retVal .addAll (getWDTRequiredBuildArgs (wdtVariablesPath ));
246
+ retVal .add ("WDT_VARIABLE=" + variableFileName );
247
+ retVal .addAll (getWdtRequiredBuildArgs (wdtVariablesPath ));
260
248
}
261
249
262
- Path tmpScriptsDir = Files .createDirectory (Paths .get (tmpDirPath , "scripts" ));
250
+ Path tmpScriptsDir = Files .createDirectory (Paths .get (tmpDir , "scripts" ));
263
251
String toScriptsPath = tmpScriptsDir .toAbsolutePath ().toString ();
264
252
Utils .copyResourceAsFile ("/container-scripts/startAdminServer.sh" , toScriptsPath , true );
265
253
Utils .copyResourceAsFile ("/container-scripts/startManagedServer.sh" , toScriptsPath , true );
@@ -268,7 +256,7 @@ private List<String> handleWDTArgsIfRequired(Path tmpDir) throws IOException {
268
256
throw new IOException ("WDT model file " + wdtModelPath + " not found" );
269
257
}
270
258
}
271
- logger .finer ("Exiting CreateImage.handleWDTArgsIfRequired : " );
259
+ logger .finer ("Exiting CreateImage.handleWdtArgsIfRequired : " );
272
260
return retVal ;
273
261
}
274
262
@@ -279,8 +267,8 @@ private List<String> handleWDTArgsIfRequired(Path tmpDir) throws IOException {
279
267
* @return list of build args
280
268
* @throws IOException in case of error
281
269
*/
282
- private List <String > getWDTRequiredBuildArgs (Path wdtVariablesPath ) throws IOException {
283
- logger .finer ("Entering CreateImage.getWDTRequiredBuildArgs : " + wdtVariablesPath .toAbsolutePath ().toString ());
270
+ private List <String > getWdtRequiredBuildArgs (Path wdtVariablesPath ) throws IOException {
271
+ logger .finer ("Entering CreateImage.getWdtRequiredBuildArgs : " + wdtVariablesPath .toAbsolutePath ().toString ());
284
272
List <String > retVal = new LinkedList <>();
285
273
Properties variableProps = new Properties ();
286
274
variableProps .load (new FileInputStream (wdtVariablesPath .toFile ()));
@@ -292,7 +280,7 @@ private List<String> getWDTRequiredBuildArgs(Path wdtVariablesPath) throws IOExc
292
280
retVal .add (Constants .BUILD_ARG );
293
281
retVal .add (((String ) x ).toUpperCase () + "=" + variableProps .getProperty ((String ) x ));
294
282
});
295
- logger .finer ("Exiting CreateImage.getWDTRequiredBuildArgs : " );
283
+ logger .finer ("Exiting CreateImage.getWdtRequiredBuildArgs : " );
296
284
return retVal ;
297
285
}
298
286
@@ -309,7 +297,7 @@ private List<InstallerFile> gatherRequiredInstallers() throws Exception {
309
297
if (wdtModelPath != null && Files .isRegularFile (wdtModelPath )) {
310
298
InstallerFile wdtInstaller = new InstallerFile (useCache , InstallerType .WDT , wdtVersion , null , null );
311
299
retVal .add (wdtInstaller );
312
- addWDTURL (wdtInstaller .getKey ());
300
+ addWdtUrl (wdtInstaller .getKey ());
313
301
}
314
302
retVal .add (new InstallerFile (useCache , InstallerType .fromValue (installerType .toString ()), installerVersion ,
315
303
userId , password ));
@@ -326,9 +314,9 @@ private List<InstallerFile> gatherRequiredInstallers() throws Exception {
326
314
* @param wdtKey key in the format wdt_0.17
327
315
* @throws Exception in case of error
328
316
*/
329
- private void addWDTURL (String wdtKey ) throws Exception {
317
+ private void addWdtUrl (String wdtKey ) throws Exception {
330
318
logger .finer ("Entering CreateImage.wdtKey: " );
331
- String wdtURLKey = wdtKey + "_url" ;
319
+ String wdtUrlKey = wdtKey + "_url" ;
332
320
if (cacheStore .getValueFromCache (wdtKey ) == null ) {
333
321
if (userId == null || password == null ) {
334
322
throw new Exception ("CachePolicy prohibits download. Add the required wdt installer to cache" );
@@ -339,7 +327,7 @@ private void addWDTURL(String wdtKey) throws Exception {
339
327
if (wdtTags .contains (tagToMatch )) {
340
328
String downloadLink = String .format (Constants .WDT_URL_FORMAT , tagToMatch );
341
329
logger .info ("WDT Download link = " + downloadLink );
342
- cacheStore .addToCache (wdtURLKey , downloadLink );
330
+ cacheStore .addToCache (wdtUrlKey , downloadLink );
343
331
} else {
344
332
throw new Exception ("Couldn't find WDT download url for version:" + wdtVersion );
345
333
}
0 commit comments