Skip to content

Commit 616fdf7

Browse files
committed
Change default for --chown in UPDATE to the owner:group of the Oracle Home in the fromImage
1 parent 6e636ca commit 616fdf7

File tree

5 files changed

+67
-6
lines changed

5 files changed

+67
-6
lines changed

documentation/1.11/content/userguide/tools/update-image.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ Update WebLogic Docker image with selected patches
2525
```
2626
| Parameter | Definition | Default |
2727
| --- | --- | --- |
28-
| `--fromImage` | (Required) Container image to be updated. The `fromImage` option serves as a starting point for the new image to be created. | |
28+
| `--fromImage` | (Required) Container image to be extended. The provided image MUST contain an Oracle Home with middleware installed. The `fromImage` option serves as a starting point for the new image to be created. | |
2929
| `--tag` | (Required) Tag for the final build image. Example: `store/oracle/weblogic:12.2.1.3.0` | |
3030
| `--additionalBuildCommands` | Path to a file with additional build commands. For more details, see [Additional information](#--additionalbuildcommands). |
3131
| `--additionalBuildFiles` | Additional files that are required by your `additionalBuildCommands`. A comma separated list of files that should be copied to the build context. See [Additional information](#--additionalbuildfiles). |
3232
| `--builder`, `-b` | Executable to process the Dockerfile. Use the full path of the executable if not on your path. | `docker` |
3333
| `--buildNetwork` | Networking mode for the RUN instructions during the image build. See `--network` for Docker `build`. | |
34-
| `--chown` | `userid:groupid` for JDK/Middleware installs and patches. | `oracle:oracle` |
34+
| `--chown` | `userid:groupid` for middleware patches and other operations. | Owner:Group of the Oracle Home |
3535
| `--dryRun` | Skip Docker build execution and print the Dockerfile to stdout. | |
3636
| `--httpProxyUrl` | Proxy for the HTTP protocol. Example: `http://myproxy:80` or `http:user:passwd@myproxy:8080` | |
3737
| `--httpsProxyUrl` | Proxy for the HTTPS protocol. Example: `https://myproxy:80` or `https:user:passwd@myproxy:8080` | |

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public abstract class CommonOptions {
4646
private String buildId;
4747

4848
private void handleChown() {
49-
if (!isOptionSet("--chown")) {
49+
if (!isChownSet()) {
50+
// nothing to do, user did not specify --chown on the command line
5051
return;
5152
}
5253

@@ -170,7 +171,7 @@ void initializeOptions() throws InvalidCredentialException, IOException, Invalid
170171
if (kubernetesTarget == KubernetesTarget.OPENSHIFT) {
171172
dockerfileOptions.setDomainGroupAsUser(true);
172173
// if the user did not set the OS user:group, make the default oracle:root, instead of oracle:oracle
173-
if (!isOptionSet(osUserAndGroup)) {
174+
if (!isChownSet()) {
174175
dockerfileOptions.setGroupId("root");
175176
}
176177
}
@@ -240,6 +241,15 @@ public void cleanup() throws IOException, InterruptedException {
240241
Utils.removeIntermediateDockerImages(buildEngine, buildId());
241242
}
242243

244+
/**
245+
* If the user provided a value to alter the default user:group, return true.
246+
*
247+
* @return true if the user provided a value to change user:group.
248+
*/
249+
public boolean isChownSet() {
250+
return isOptionSet("--chown");
251+
}
252+
243253
private boolean isOptionSet(String optionName) {
244254
CommandLine.ParseResult pr = spec.commandLine().getParseResult();
245255
return pr.hasMatchedOption(optionName);

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,20 @@ public CommandResponse call() throws Exception {
7777

7878
String baseImageUsr = baseImageProperties.getProperty("oracleHomeUser");
7979
String baseImageGrp = baseImageProperties.getProperty("oracleHomeGroup");
80-
if (!dockerfileOptions.userid().equals(baseImageUsr) || !dockerfileOptions.groupid().equals(baseImageGrp)) {
81-
return CommandResponse.error("IMG-0087", fromImage(), baseImageUsr, baseImageGrp);
80+
81+
if (isChownSet()) {
82+
// --chown for UPDATE no longer makes sense if the value must always be what the fromImage is.
83+
if (!dockerfileOptions.userid().equals(baseImageUsr)
84+
|| !dockerfileOptions.groupid().equals(baseImageGrp)) {
85+
// if the user specified a --chown that did not match the fromImage(), error
86+
return CommandResponse.error("IMG-0087", fromImage(), baseImageUsr, baseImageGrp);
87+
}
88+
} else {
89+
// if the user did not specify --chown, use the user:group for the Oracle Home found in the --fromImage
90+
dockerfileOptions.setUserId(baseImageUsr);
91+
dockerfileOptions.setGroupId(baseImageGrp);
92+
logger.fine("--chown not set by user. Using values found in --fromImage {0} for --chown {1}:{2}",
93+
fromImage(), baseImageUsr, baseImageGrp);
8294
}
8395

8496
List<InstalledPatch> installedPatches = Collections.emptyList();

imagetool/src/test/java/com/oracle/weblogic/imagetool/cli/menu/CommonOptionsTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import picocli.CommandLine;
2828

2929
import static org.junit.jupiter.api.Assertions.assertEquals;
30+
import static org.junit.jupiter.api.Assertions.assertFalse;
31+
import static org.junit.jupiter.api.Assertions.assertTrue;
3032
import static org.junit.jupiter.api.Assertions.fail;
3133

3234
@Tag("unit")
@@ -202,4 +204,24 @@ void testResolveOptions() throws Exception {
202204
}
203205
}
204206
}
207+
208+
/**
209+
* isChownSet() true if the user provided a user:group on the CLI.
210+
*/
211+
@Test
212+
void isChownSet() {
213+
CreateImage createImage = new CreateImage();
214+
new CommandLine(createImage).parseArgs("--tag", "x:1", "--chown", "oracle:root");
215+
assertTrue(createImage.isChownSet());
216+
}
217+
218+
/**
219+
* isChownSet() returns false if the user did not provide a user:group on the CLI.
220+
*/
221+
@Test
222+
void isChownNotSet() {
223+
CreateImage createImage = new CreateImage();
224+
new CommandLine(createImage).parseArgs("--tag", "x:1");
225+
assertFalse(createImage.isChownSet());
226+
}
205227
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (c) 2022, Oracle and/or its affiliates.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3+
4+
package com.oracle.weblogic.imagetool.logging;
5+
6+
import org.junit.jupiter.api.Test;
7+
8+
import static org.junit.jupiter.api.Assertions.assertEquals;
9+
10+
11+
class FileFormatterTest {
12+
13+
@Test
14+
void format() {
15+
assertEquals(true, true);
16+
}
17+
}

0 commit comments

Comments
 (0)