Skip to content

Commit cec163f

Browse files
authored
Fix, exit code was zeroed out when cleanup operations failed (#427)
* remove unused return from docker run * catch the exceptions during process clean up to prevent losing return code of previous operations
1 parent 4d1fccc commit cec163f

File tree

4 files changed

+32
-20
lines changed

4 files changed

+32
-20
lines changed

imagetool/src/main/java/com/oracle/weblogic/imagetool/builder/BuildCommand.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
package com.oracle.weblogic.imagetool.builder;
55

66
import java.io.BufferedReader;
7-
import java.io.FileOutputStream;
87
import java.io.IOException;
98
import java.io.InputStream;
109
import java.io.InputStreamReader;
@@ -130,7 +129,7 @@ public BuildCommand pull(boolean value) {
130129
* @throws IOException if an error occurs reading from the process inputstream.
131130
* @throws InterruptedException when the process wait is interrupted.
132131
*/
133-
public BuildCommand run(Path dockerLog)
132+
public void run(Path dockerLog)
134133
throws IOException, InterruptedException {
135134
// process builder
136135
logger.entering(getCommand(false), dockerLog);
@@ -142,7 +141,7 @@ public BuildCommand run(Path dockerLog)
142141

143142
if (dockerLogPath != null) {
144143
logger.info("dockerLog: " + dockerLog);
145-
outputStreams.add(new FileOutputStream(dockerLogPath.toFile()));
144+
outputStreams.add(Files.newOutputStream(dockerLogPath));
146145
}
147146

148147
ProcessBuilder processBuilder = new ProcessBuilder(getCommand(true));
@@ -154,7 +153,6 @@ public BuildCommand run(Path dockerLog)
154153
if (process.waitFor() != 0) {
155154
Utils.processError(process);
156155
}
157-
return this;
158156
}
159157

160158
/**

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,16 +237,24 @@ public void copyOptionsFromImage() throws IOException, InterruptedException {
237237
/**
238238
* Delete build context directory and remove all intermediate build images.
239239
*
240-
* @throws IOException if an error occurs trying to delete the context directory files.
241240
* @throws InterruptedException when interrupted.
242241
*/
243-
public void cleanup() throws IOException, InterruptedException {
242+
public void cleanup() throws InterruptedException {
244243
if (skipcleanup) {
245244
return;
246245
}
247-
Utils.deleteFilesRecursively(buildDir());
246+
try {
247+
Utils.deleteFilesRecursively(buildDirectory);
248+
} catch (IOException e) {
249+
logger.severe("IMG-0080", buildDirectory);
250+
}
251+
248252
if (!dryRun) {
249-
Utils.removeIntermediateDockerImages(buildEngine, buildId());
253+
try {
254+
Utils.removeIntermediateDockerImages(buildEngine, buildId());
255+
} catch (IOException e) {
256+
logger.severe("IMG-0118", buildId());
257+
}
250258
}
251259
}
252260

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

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -282,19 +282,24 @@ public static void processError(Process process) throws IOException {
282282
* @throws IOException in case of error
283283
*/
284284
public static void deleteFilesRecursively(String pathDir) throws IOException {
285-
if (pathDir != null) {
286-
Path tmpDir = Paths.get(pathDir);
287-
try (Stream<Path> walk = Files.walk(tmpDir)) {
288-
walk.sorted(Comparator.reverseOrder())
289-
.map(Path::toFile)
290-
//.peek(System.out::println)
291-
.forEach(File::delete);
292-
}
285+
logger.entering(pathDir);
286+
if (pathDir == null) {
287+
logger.exiting();
288+
return;
289+
}
293290

294-
if (Files.exists(tmpDir)) {
295-
logger.warning("IMG-0038", tmpDir);
296-
}
291+
Path tmpDir = Paths.get(pathDir);
292+
try (Stream<Path> walk = Files.walk(tmpDir)) {
293+
walk.sorted(Comparator.reverseOrder())
294+
.map(Path::toFile)
295+
//.peek(System.out::println)
296+
.forEach(File::delete);
297297
}
298+
299+
if (Files.exists(tmpDir)) {
300+
logger.warning("IMG-0038", tmpDir);
301+
}
302+
logger.exiting();
298303
}
299304

300305
/**

imagetool/src/main/resources/ImageTool.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ IMG-0076=Invalid argument, the value provided for {0} is invalid or empty.
7878
IMG-0077=Skipping duplicate patch {0}. Patch file already exists in the build context folder. Did you accidentally list the patch twice?
7979
IMG-0078=Starting build: {0}
8080
IMG-0079=OS Package Manager override, changed from {0} to {1}
81-
IMG-0080=NOT USED
81+
IMG-0080=Failed to clean up build context folder {0}
8282
IMG-0081=Unable to retrieve list of Oracle releases from Oracle Updates (ARU). Try again later.
8383
IMG-0082=Version {0} did not contain {1}, skipping
8484
IMG-0083=Version {0} for patch ID {1} was not found in the available versions: {2}
@@ -116,3 +116,4 @@ IMG-0114=Unable to parse section {0} of additionalBuildCommands: {1}
116116
IMG-0115=Unable to reach Oracle patch server to check for patch conflicts, skipping online conflict check. OPatch will check patches locally during the build.
117117
IMG-0116=A patch conflict was detected. The patches listed within the brackets conflict with each other. These fixes cannot be applied without a merge patch from Oracle:
118118
IMG-0117=The value for --sourceImage must not be empty.
119+
IMG-0118=Failed to clean up intermediate container images for build ID {0}

0 commit comments

Comments
 (0)