Skip to content

Commit 2dee1cc

Browse files
authored
Use specific subfolder for additionalBuildFiles (#119)
* additionalBuildFiles should use a specific subfolder of the build context to prevent overrunning other files copied by the tool * additional text to describe sections for COPY
1 parent bbfd3c6 commit 2dee1cc

File tree

4 files changed

+57
-1
lines changed

4 files changed

+57
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,13 @@ private void handleAdditionalBuildCommands() throws IOException {
7373
}
7474

7575
if (additionalBuildFiles != null) {
76+
final String FILES_DIR = "files";
77+
Files.createDirectory(Paths.get(getTempDirectory(), FILES_DIR));
7678
for (Path additionalFile : additionalBuildFiles) {
7779
if (!Files.isRegularFile(additionalFile)) {
7880
throw new FileNotFoundException(Utils.getMessage("IMG-0030", additionalFile));
7981
}
80-
Path targetFile = Paths.get(getTempDirectory(), additionalFile.getFileName().toString());
82+
Path targetFile = Paths.get(getTempDirectory(), FILES_DIR, additionalFile.getFileName().toString());
8183
logger.info("IMG-0043", additionalFile);
8284
Utils.copyLocalFile(additionalFile.toString(), targetFile.toString(), false);
8385
}

site/create-image.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,29 @@ Each section can contain one or more valid Dockerfile commands and would look li
5353
```dockerfile
5454
[after-fmw-install]
5555
RUN rm /some/dir/unnecessary-file
56+
COPY --chown=oracle:oracle files/my_additional_file.txt /u01
5657

5758
[final-build-commands]
5859
LABEL owner="middleware team"
5960
```
6061

62+
#### `--additionalBuildFiles`
63+
64+
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.
66+
To get those files into the image, additional build commands must be provided using the `additionalBuildCommands` options.
67+
Access to these files using a build command, such as `COPY` or `ADD`, should use the original filename
68+
with the folder prefix, `files/`. For example, if the
69+
original file was provided as `--additionalBuildFiles /scratch/test1/convenience.sh`, the Docker build command `COPY`
70+
provided in `--additionalBuildCommands` should look like
71+
`COPY --chown=oracle:oracle files/convenience.sh /my/internal/image/location`.
72+
Because Image Tool uses multi-stage
73+
builds, it is important to place the build command (like `COPY`) in the appropriate section of the `Dockerfile` based
74+
on when the build needs access to the file. For example, if the file is needed in the final image and not for
75+
installation or domain creation steps, use the `final-build-commands` section so that the `COPY` command occurs in the
76+
final stage of the image build. Or, if the file needs to change the Oracle Home prior to domain creation, use
77+
the `after-fmw-install` or `before-wdt-command` sections.
78+
6179
#### Use an argument file
6280

6381
You can save all arguments passed for the Image Tool in a file, then use the file as a parameter.

site/rebase-image.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,29 @@ Each section can contain one or more valid Dockerfile commands and would look li
4747
```dockerfile
4848
[after-fmw-install]
4949
RUN rm /some/dir/unnecessary-file
50+
COPY --chown=oracle:oracle files/my_additional_file.txt /u01
5051

5152
[final-build-commands]
5253
LABEL owner="middleware team"
5354
```
5455

56+
#### `--additionalBuildFiles`
57+
58+
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.
60+
To get those files into the image, additional build commands must be provided using the `additionalBuildCommands` options.
61+
Access to these files using a build command, such as `COPY` or `ADD`, should use the original filename
62+
with the folder prefix, `files/`. For example, if the
63+
original file was provided as `--additionalBuildFiles /scratch/test1/convenience.sh`, the Docker build command `COPY`
64+
provided in `--additionalBuildCommands` should look like
65+
`COPY --chown=oracle:oracle files/convenience.sh /my/internal/image/location`.
66+
Because Image Tool uses multi-stage
67+
builds, it is important to place the build command (like `COPY`) in the appropriate section of the `Dockerfile` based
68+
on when the build needs access to the file. For example, if the file is needed in the final image and not for
69+
installation or domain creation steps, use the `final-build-commands` section so that the `COPY` command occurs in the
70+
final stage of the image build. Or, if the file needs to change the Oracle Home prior to domain creation, use
71+
the `after-fmw-install` or `before-wdt-command` sections.
72+
5573
#### Use an argument file
5674

5775
You can save all arguments passed for the Image Tool in a file, then use the file as a parameter.

site/update-image.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,29 @@ increase the size of the image significantly, and is not recommended.
7272
```dockerfile
7373
[after-fmw-install]
7474
RUN rm /some/dir/unnecessary-file
75+
COPY --chown=oracle:oracle files/my_additional_file.txt /u01
7576

7677
[final-build-commands]
7778
LABEL owner="middleware team"
7879
```
7980

81+
#### `--additionalBuildFiles`
82+
83+
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.
85+
To get those files into the image, additional build commands must be provided using the `additionalBuildCommands` options.
86+
Access to these files using a build command, such as `COPY` or `ADD`, should use the original filename
87+
with the folder prefix, `files/`. For example, if the
88+
original file was provided as `--additionalBuildFiles /scratch/test1/convenience.sh`, the Docker build command `COPY`
89+
provided in `--additionalBuildCommands` should look like
90+
`COPY --chown=oracle:oracle files/convenience.sh /my/internal/image/location`.
91+
Because Image Tool uses multi-stage
92+
builds, it is important to place the build command (like `COPY`) in the appropriate section of the `Dockerfile` based
93+
on when the build needs access to the file. For example, if the file is needed in the final image and not for
94+
installation or domain creation steps, use the `final-build-commands` section so that the `COPY` command occurs in the
95+
final stage of the image build. Or, if the file needs to change the Oracle Home prior to domain creation, use
96+
the `after-fmw-install` or `before-wdt-command` sections.
97+
8098
#### Use an argument file
8199

82100
You can save all arguments passed for the Image Tool in a file, then use the file as a parameter.

0 commit comments

Comments
 (0)