Skip to content

Commit e28ebd5

Browse files
authored
added support for folders using additionalBuildFiles feature (#136)
1 parent 0013512 commit e28ebd5

File tree

8 files changed

+55
-13
lines changed

8 files changed

+55
-13
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,16 @@ private void handleAdditionalBuildCommands() throws IOException {
7676
final String FILES_DIR = "files";
7777
Files.createDirectory(Paths.get(getTempDirectory(), FILES_DIR));
7878
for (Path additionalFile : additionalBuildFiles) {
79-
if (!Files.isRegularFile(additionalFile)) {
79+
if (!Files.isReadable(additionalFile)) {
8080
throw new FileNotFoundException(Utils.getMessage("IMG-0030", additionalFile));
8181
}
8282
Path targetFile = Paths.get(getTempDirectory(), FILES_DIR, additionalFile.getFileName().toString());
8383
logger.info("IMG-0043", additionalFile);
84-
Utils.copyLocalFile(additionalFile.toString(), targetFile.toString(), false);
84+
if (Files.isDirectory(additionalFile)) {
85+
Utils.copyLocalDirectory(additionalFile, targetFile, false);
86+
} else {
87+
Utils.copyLocalFile(additionalFile, targetFile, false);
88+
}
8589
}
8690
}
8791
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import java.io.File;
77
import java.nio.file.Path;
8+
import java.nio.file.Paths;
89
import java.time.Duration;
910
import java.time.Instant;
1011
import java.util.List;
@@ -82,7 +83,7 @@ public CommandResponse call() throws Exception {
8283
// Set the inventory location, so that it will be copied
8384
if (inventoryPointerFile != null) {
8485
Utils.setInventoryLocation(inventoryPointerFile, dockerfileOptions);
85-
Utils.copyLocalFile(inventoryPointerFile, tmpDir + "/oraInst.loc", false);
86+
Utils.copyLocalFile(Paths.get(inventoryPointerFile), Paths.get(tmpDir,"/oraInst.loc"), false);
8687
} else {
8788
Utils.copyResourceAsFile("/response-files/oraInst.loc", tmpDir, false);
8889
}
@@ -95,6 +96,7 @@ public CommandResponse call() throws Exception {
9596
cmdBuilder.add(tmpDir);
9697
runDockerCommand(dockerfile, cmdBuilder);
9798
} catch (Exception ex) {
99+
logger.fine("**ERROR**", ex);
98100
return new CommandResponse(-1, ex.getMessage());
99101
} finally {
100102
if (!skipcleanup) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import java.io.File;
77
import java.nio.file.Path;
8+
import java.nio.file.Paths;
89
import java.time.Duration;
910
import java.time.Instant;
1011
import java.util.List;
@@ -145,7 +146,7 @@ public CommandResponse call() throws Exception {
145146
// Set the inventory pointer
146147
if (inventoryPointerFile != null) {
147148
Utils.setInventoryLocation(inventoryPointerFile, dockerfileOptions);
148-
Utils.copyLocalFile(inventoryPointerFile, tmpDir + "/oraInst.loc", false);
149+
Utils.copyLocalFile(Paths.get(inventoryPointerFile), Paths.get(tmpDir,"/oraInst.loc"), false);
149150
} else {
150151
Utils.copyResourceAsFile("/response-files/oraInst.loc", tmpDir, false);
151152
}

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

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import java.io.PrintWriter;
1818
import java.io.StringWriter;
1919
import java.net.URL;
20+
import java.nio.file.DirectoryStream;
2021
import java.nio.file.Files;
2122
import java.nio.file.LinkOption;
2223
import java.nio.file.Path;
@@ -91,18 +92,52 @@ public static void copyResourceAsFile(String resourcePath, String destPath, bool
9192
* @param markExec sets the executable flag if true
9293
* @throws IOException in case of error
9394
*/
94-
public static void copyLocalFile(String sourcePath, String destPath, boolean markExec) throws IOException {
95+
public static void copyLocalFile(Path sourcePath, Path destPath, boolean markExec) throws IOException {
9596
Objects.requireNonNull(sourcePath);
9697
Objects.requireNonNull(destPath);
97-
Files.copy(Paths.get(sourcePath), Paths.get(destPath),
98-
StandardCopyOption.REPLACE_EXISTING);
98+
logger.fine("copyLocalFile: copying file {0}->{1}", sourcePath, destPath);
99+
Files.copy(sourcePath, destPath, StandardCopyOption.REPLACE_EXISTING);
99100
if (markExec) {
100101
if (!System.getProperty("os.name").toLowerCase().startsWith("windows")) {
101-
Files.setPosixFilePermissions(Paths.get(destPath), PosixFilePermissions.fromString("r-xr-xr-x"));
102+
Files.setPosixFilePermissions(destPath, PosixFilePermissions.fromString("r-xr-xr-x"));
102103
}
103104
}
104105
}
105106

107+
/**
108+
* Utility method to copy a local directory to another local file system location.
109+
*
110+
* @param sourcePath path to the local directory
111+
* @param destPath local directory to copy to.
112+
* @param markExec sets the executable flag if true
113+
* @throws IOException in case of error
114+
*/
115+
public static void copyLocalDirectory(Path sourcePath, Path destPath, boolean markExec) throws IOException {
116+
Objects.requireNonNull(sourcePath);
117+
Objects.requireNonNull(destPath);
118+
if (!Files.isDirectory(sourcePath)) {
119+
throw new IllegalArgumentException(getMessage("IMG-0007", sourcePath.toString()));
120+
}
121+
122+
logger.fine("copyLocalDirectory: copying folder {0}->{1}", sourcePath, destPath);
123+
124+
// retain folder structure of source in destination folder
125+
Files.createDirectory(destPath);
126+
127+
// get children of source directory and copy them to destination directory
128+
try (DirectoryStream<Path> stream = Files.newDirectoryStream(sourcePath)) {
129+
for (Path child : stream) {
130+
if (Files.isDirectory(child)) {
131+
copyLocalDirectory(child, destPath.resolve(child.getFileName()), markExec);
132+
} else if (Files.isRegularFile(child)) {
133+
copyLocalFile(child, destPath.resolve(child.getFileName()), markExec);
134+
} else {
135+
logger.info("IMG-0035", sourcePath.toString());
136+
}
137+
}
138+
}
139+
140+
}
106141

107142
/**
108143
* Create a file with the given path.

imagetool/src/main/resources/ImageTool.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ IMG-0003=Temporary directory used for docker build context: {0}
55
IMG-0004=Invalid patch id {0}. The patch id must be in the format of {1}. Where the first part is the 8 digit patch ID, and the second half, after the underscore, is the release version for the patch. The release version needs to be specified with 5 places such as 12.2.1.3.0 or 12.2.1.3.190416. Release version is required when adding a patch to the cache or when multiple versions of the same patch number exist for different versions.
66
IMG-0005=Installer response file: {0}
77
IMG-0006=No patch conflicts detected
8-
IMG-0007=WDT Download link = {0}
8+
IMG-0007={0} is not a directory
99
IMG-0008=OPatch patch number {0} cached file {1} version {2}
1010
IMG-0009=skipping patch conflict check, no support credentials provided
1111
IMG-0010=Oracle Home will be set to {0}
@@ -33,7 +33,7 @@ IMG-0031=No credentials provided. Cannot determine latestPSU
3333
IMG-0032=Failed to find latest PSU for {0}, version {1}
3434
IMG-0033=No credentials provided, skipping validation of patches
3535
IMG-0034=Patch ID {0} has multiple versions, please retry the command using one of the available patch versions: {1}
36-
IMG-0035=Multiple patches with the same patch number detected
36+
IMG-0035=additionalBuildFile could not be copied: {0}
3737
IMG-0036=Unable to find installer inventory file: {0}
3838
IMG-0037=Failed to find patch {0} for version {1}
3939
IMG-0038=In image {0}, the Oracle Home already exists at location:

site/create-image.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ LABEL owner="middleware team"
6262
#### `--additionalBuildFiles`
6363

6464
This option provides a way to supply additional files to the image build command.
65-
All provided files are copied directly under the `files` subfolder of the build context.
65+
All provided files and directories are copied directly under the `files` subfolder of the build context.
6666
To get those files into the image, additional build commands must be provided using the `additionalBuildCommands` options.
6767
Access to these files using a build command, such as `COPY` or `ADD`, should use the original filename
6868
with the folder prefix, `files/`. For example, if the

site/rebase-image.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ LABEL owner="middleware team"
5656
#### `--additionalBuildFiles`
5757

5858
This option provides a way to supply additional files to the image build command.
59-
All provided files are copied directly under the `files` subfolder of the build context.
59+
All provided files and directories are copied directly under the `files` subfolder of the build context.
6060
To get those files into the image, additional build commands must be provided using the `additionalBuildCommands` options.
6161
Access to these files using a build command, such as `COPY` or `ADD`, should use the original filename
6262
with the folder prefix, `files/`. For example, if the

site/update-image.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ LABEL owner="middleware team"
8181
#### `--additionalBuildFiles`
8282

8383
This option provides a way to supply additional files to the image build command.
84-
All provided files are copied directly under the `files` subfolder of the build context.
84+
All provided files and directories are copied directly under the `files` subfolder of the build context.
8585
To get those files into the image, additional build commands must be provided using the `additionalBuildCommands` options.
8686
Access to these files using a build command, such as `COPY` or `ADD`, should use the original filename
8787
with the folder prefix, `files/`. For example, if the

0 commit comments

Comments
 (0)