Skip to content

Commit 6c23dbc

Browse files
gosurya-oraclejshum2479
authored andcommitted
Java poc
Former-commit-id: 53787cec1f997eb342484ec37c736be6f5f2d1bb
1 parent 7505852 commit 6c23dbc

File tree

15 files changed

+152
-150
lines changed

15 files changed

+152
-150
lines changed

README.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,22 @@ applying selected patches.
3333
- Docker client and daemon on the build machine
3434
- Experimental features should be turned on to support docker build --squash option.
3535

36-
## Initialization
37-
38-
Build the project to
36+
## Setup
37+
38+
- Build the project to generate artifacts imagebuilder-0.1-SNAPSHOT.jar and imagebuilder_completion.sh
39+
- The jar is an uber-jar containing all the required packages to run the tool.
40+
- If running an os with bash, Use the below commands to setup the tool with tab complete feature.
41+
```bash
42+
#!/usr/bin/env bash
43+
unalias imagebuilder 2> /dev/null
44+
alias imagebuilder='java -cp "./imagebuilder-0.1-SNAPSHOT.jar" com.oracle.weblogicx.imagebuilder.cli.CLIDriver'
45+
source ./imagebuilder_completion.sh
46+
```
47+
- On Windows, setup imagebuilder.cmd or imagebuilder.bat script
48+
```cmd
49+
@ECHO OFF
50+
java -cp "./imagebuilder-0.1-SNAPSHOT.jar" com.oracle.weblogicx.imagebuilder.cli.CLIDriver %*
51+
```
52+
- Then, execute "imagebuilder help" to get the help screen
53+
- The jar can be executed directly using command java -cp "./imagebuilder-0.1-SNAPSHOT.jar" com.oracle.weblogicx.imagebuilder.cli.CLIDriver help
54+
- Once familiar with the commands, you should be able to create and update WebLogic docker images

pom.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55

66
<modelVersion>4.0.0</modelVersion>
7-
<groupId>oracle.weblogicx</groupId>
7+
<groupId>com.oracle.weblogicx</groupId>
88
<artifactId>imagebuilder</artifactId>
9-
<version>1.0-SNAPSHOT</version>
9+
<version>0.1-SNAPSHOT</version>
1010

1111
<properties>
12+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1213
<maven.compiler.source>1.8</maven.compiler.source>
1314
<maven.compiler.target>1.8</maven.compiler.target>
1415
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
@@ -61,7 +62,7 @@
6162
<classpath/>
6263
<argument>picocli.AutoComplete</argument>
6364
<argument>--force</argument><!-- overwrite if exists -->
64-
<argument>--writeCommandScript</argument>
65+
<!--<argument>&#45;&#45;writeCommandScript</argument>-->
6566
<argument>--completionScript</argument>
6667
<argument>${project.build.directory}/imagebuilder_completion.sh</argument>
6768
<argument>com.oracle.weblogicx.imagebuilder.cli.CLIDriver</argument>

site/cache.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Cache
2+
3+
The cache command is used to add / edit the required metadata for the tool. Cache helps the tool to identify where the
4+
required installers (wls, fmw, jdk) are located and where to download the patches to. There are several subcommands to
5+
aid the user.
6+
7+
```
8+
Usage: imagebuilder cache [COMMAND]
9+
List and set cache options
10+
11+
Commands:
12+
13+
listItems List cache contents
14+
addInstaller Add cache entry for wls, fmw, jdk or wdt installer
15+
addPatch Add cache entry for wls|fmw patch or psu
16+
getCacheDir Prints the cache directory path
17+
setCacheDir Sets the cache directory where to download required artifacts
18+
addEntry Command to add a cache entry. Use caution
19+
deleteEntry Command to delete a cache entry
20+
help Displays help information about the specified command
21+
```
22+
23+
## Usage scenarios
24+
25+
- listItems: Display the contents of cache. Displays key value pairs of the installers, patches.
26+
```
27+
imagebuilder cache listItems
28+
29+
Cache contents
30+
jdk_8u202=/Users/xyz/Downloads/cache/server-jre-8u202-linux-x64.tar.gz
31+
12345678_600000000012345=/Users/xyz/Downloads/cache/p12345678_122130_Generic.zip
32+
87654321_600000000654321=/Users/xyz/Downloads/cache/p87654321_139400_Generic.zip
33+
wls_12.2.1.3.0=/Users/xyz/Downloads/cache/fmw_12.2.1.3.0_wls_Disk1_1of1.zip
34+
cache.dir=/Users/xyz/Downloads/cache
35+
```
36+
37+
- addInstaller: Add installer to cache, ex: jdk
38+
```
39+
imagebuilder cache addInstaller --type jdk --version 8u202 --path /path/to/local/jdk.tar.gz
40+
```
41+
42+
- addPatch: Add patch to cache. This command verifies if the path points to a valid patch by querying Oracle support portal
43+
```
44+
imagebuilder cache addPatch --type wls --version 12.2.1.3.0 --user [email protected] --passwordEnv MYVAR --patchId 12345678 --path /path/to/patch.zip
45+
```
46+
47+
- getCacheDir and setCacheDir: Get/Set cache directory. Used to display or set the directory where patches will be downloaded to by the tool.
48+
```
49+
imagebuilder cache getCacheDir
50+
imagebuilder cache setCacheDir /path/to/dir
51+
```
52+
53+
- addEntry: Consider this as an expert mode where you can add key value pairs to cache without any validation.
54+
```
55+
imagebuilder cache addEntry --key xyz_123 --value /path/to/file
56+
```
57+
58+
- deleteEntry: Delete a entry from cache for a given key. _Note: This command does not delete files from disk._
59+
```
60+
imagebuilder cache deleteEntry --key xyz_123
61+
```

site/create-image.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ are marked with asterisk (*). Password can be provided in one of the three ways.
77
3) File containing the password
88

99
```
10-
Missing required options [--tag=TAG, --user=<support email>]
1110
Usage: imagebuilder create [OPTIONS]
1211
Build WebLogic docker image
1312
--docker=<dockerPath> path to docker executable. Default: docker
@@ -59,7 +58,7 @@ The commands below assume that all the required jdk, wls or fmw (WebLogic infras
5958
```
6059
imagebuilder create --tag sample:wls --latestPSU --user [email protected] --password hello
6160
```
62-
61+
6362
- Create an image named sample:wdt with same options as above and create a domain with [WebLogic Deploy Tooling](https://github.com/oracle/weblogic-deploy-tooling)
6463
```
6564
imagebuilder create --tag sample:wdt --latestPSU --user [email protected] --password hello --wdtModel /path/to/model.json --wdtVariables /path/to/variables.json --wdtVersion 0.16

site/update-image.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Update Image
2+
3+
The update command is used to apply patches to an existing WebLogic docker image. The required options for the command
4+
are marked with asterisk (*). Password can be provided in one of the three ways.
5+
6+
1) Plain Text
7+
2) Environment Variable
8+
3) File containing the password
9+
10+
```
11+
Usage: imagebuilder update [OPTIONS]
12+
Update WebLogic docker image with selected patches
13+
--docker=<dockerPath> path to docker executable. Default: docker
14+
* --fromImage=<fromImage>
15+
Docker image to use as base image.
16+
--httpProxyUrl=<httpProxyUrl>
17+
proxy for http protocol. Ex: http://myproxy:80 or http:
18+
//user:passwd@myproxy:8080
19+
--httpsProxyUrl=<httpsProxyUrl>
20+
proxy for https protocol. Ex: http://myproxy:80 or http:
21+
//user:passwd@myproxy:8080
22+
--latestPSU Whether to apply patches from latest PSU.
23+
--password=<password for support user id>
24+
Password for support userId
25+
--passwordEnv=<environment variable>
26+
environment variable containing the support password
27+
--passwordFile=<password file>
28+
path to file containing just the password
29+
--patches=patchId[,patchId...]
30+
Comma separated patch Ids. Ex: p12345678,p87654321
31+
* --tag=TAG Tag for the final build image. Ex: store/oracle/weblogic:
32+
12.2.1.3.0
33+
* --user=<support email>
34+
Oracle Support email id
35+
```
36+
37+
## Usage scenarios
38+
39+
**_Note: Use --passwordEnv or --passwordFile instead of --password_**
40+
41+
- Update an image named sample:1.0 by applying the latest psu and tag it as sample:1.1.
42+
```
43+
imagebuilder update --fromImage sample:1.0 --tag sample:1.1 --latestPSU --user [email protected] --passwordEnv MYVAR
44+
```
45+
46+
- Update an image named sample:1.0 with selected patches applied.
47+
```
48+
imagebuilder update --fromImage sample:1.0 --tag sample:1.1 --user [email protected] --password hello --patches 12345678,p87654321
49+
```
50+
The patch numbers may or may not start with 'p'.

src/main/java/com/oracle/weblogicx/imagebuilder/cli/cache/AddEntry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public CommandResponse call() {
5050
private String key;
5151

5252
@Option(
53-
names = {"--path"},
53+
names = {"--value"},
5454
description = "Value for the cache entry",
5555
required = true
5656
)

src/main/java/com/oracle/weblogicx/imagebuilder/cli/cache/AddInstallerEntry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
@Command(
1717
name = "addInstaller",
18-
description = "Add cache entry for wls|fmw or jdk installer",
18+
description = "Add cache entry for wls, fmw, jdk or wdt installer",
1919
sortOptions = false
2020
)
2121
public class AddInstallerEntry extends CacheOperation {

src/main/java/com/oracle/weblogicx/imagebuilder/cli/cache/AddPatchEntry.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@
1414
import picocli.CommandLine.Command;
1515
import picocli.CommandLine.Option;
1616

17-
import java.io.BufferedReader;
1817
import java.io.FileInputStream;
19-
import java.io.FileReader;
2018
import java.io.IOException;
2119
import java.nio.file.Files;
2220
import java.nio.file.Path;
2321

2422
import static com.oracle.weblogicx.imagebuilder.api.meta.CacheStore.CACHE_KEY_SEPARATOR;
23+
import static com.oracle.weblogicx.imagebuilder.util.Constants.PATCH_ID_REGEX;
2524

2625
@Command(
2726
name = "addPatch",
@@ -46,9 +45,11 @@ public CommandResponse call() throws Exception {
4645
&& userId != null && !userId.isEmpty()
4746
&& password != null && !password.isEmpty()
4847
&& location != null && Files.exists(location) && Files.isRegularFile(location)) {
49-
String patchNumber = this.patchId.toLowerCase();
50-
if (patchNumber.startsWith("p") && patchNumber.length() > 1) {
51-
patchNumber = patchNumber.substring(1);
48+
String patchNumber;
49+
if (patchId.matches(PATCH_ID_REGEX)) {
50+
patchNumber = patchId.substring(1);
51+
} else {
52+
return new CommandResponse(-1, "Invalid patch id format: " + patchId);
5253
}
5354
SearchResult result = ARUUtil.getPatchDetail(type.toString(), version, patchNumber, userId, password);
5455
if (result.isSuccess()) {

src/main/java/com/oracle/weblogicx/imagebuilder/cli/menu/CreateImage.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import com.oracle.weblogicx.imagebuilder.api.model.InstallerType;
88
import com.oracle.weblogicx.imagebuilder.api.model.WLSInstallerType;
99
import com.oracle.weblogicx.imagebuilder.impl.InstallerFile;
10-
import com.oracle.weblogicx.imagebuilder.util.ARUUtil;
1110
import com.oracle.weblogicx.imagebuilder.util.Constants;
1211
import com.oracle.weblogicx.imagebuilder.util.HttpUtil;
1312
import com.oracle.weblogicx.imagebuilder.util.Utils;
@@ -56,14 +55,6 @@ public CommandResponse call() throws Exception {
5655

5756
Instant startTime = Instant.now();
5857

59-
// System.out.println("hello");
60-
// System.out.println("WLSInstallerType = \"" + installerType + "\"");
61-
// System.out.println("InstallerVersion = \"" + installerVersion + "\"");
62-
// System.out.println("latestPSU = \"" + latestPSU + "\"");
63-
// System.out.println("patches = \"" + patches + "\"");
64-
// System.out.println("fromImage = \"" + fromImage + "\"");
65-
// System.out.println("userId = \"" + userId + "\"");
66-
6758
FileHandler fileHandler = setupLogger(isCLIMode);
6859
Path tmpDir = null;
6960
Path tmpDir2 = null;
@@ -75,16 +66,6 @@ public CommandResponse call() throws Exception {
7566
return result;
7667
}
7768

78-
/*
79-
password = handlePasswordOptions();
80-
handleProxyUrls();
81-
82-
// check user support credentials
83-
if (!ARUUtil.checkCredentials(userId, password)) {
84-
return new CommandResponse(-1, "user Oracle support credentials do not match");
85-
}
86-
*/
87-
8869
List<String> cmdBuilder = getInitialBuildCmd();
8970

9071
// create a tmp directory for user.
@@ -146,7 +127,6 @@ public CommandResponse call() throws Exception {
146127
Utils.runDockerCommand(cmdBuilder, dockerLog);
147128

148129
} catch (Exception ex) {
149-
//ex.printStackTrace();
150130
return new CommandResponse(-1, ex.getMessage());
151131
} finally {
152132
Utils.deleteFilesRecursively(tmpDir);

src/main/java/com/oracle/weblogicx/imagebuilder/cli/menu/ImageOperation.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import static com.oracle.weblogicx.imagebuilder.util.Constants.BUILD_ARG;
3232
import static com.oracle.weblogicx.imagebuilder.util.Constants.HTTP;
3333
import static com.oracle.weblogicx.imagebuilder.util.Constants.HTTPS;
34+
import static com.oracle.weblogicx.imagebuilder.util.Constants.PATCH_ID_REGEX;
3435

3536
public abstract class ImageOperation implements Callable<CommandResponse> {
3637

@@ -90,8 +91,13 @@ List<String> handlePatchFiles(Path tmpDir, Path tmpPatchesDir) throws Exception
9091
}
9192
if (patches != null && !patches.isEmpty()) {
9293
for (String patchId : patches) {
93-
patchLocations.add(new PatchFile(installerType.toString(), installerVersion, patchId, userId, password)
94-
.resolve(cacheStore));
94+
if (patchId.matches(PATCH_ID_REGEX)) {
95+
patchId = patchId.substring(1);
96+
patchLocations.add(new PatchFile(installerType.toString(), installerVersion, patchId, userId,
97+
password).resolve(cacheStore));
98+
} else {
99+
logger.severe("Ignoring invalid patch id format: " + patchId);
100+
}
95101
}
96102
}
97103
for (String patchLocation : patchLocations) {

0 commit comments

Comments
 (0)