Skip to content

Commit 74d4eb2

Browse files
added metadata resolver and parameterized dockerfile
Former-commit-id: 4a24e9200268af8d8d437e08fcdd9956c2790b57
1 parent d334937 commit 74d4eb2

File tree

15 files changed

+578
-86
lines changed

15 files changed

+578
-86
lines changed

pom.xml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,25 @@
2525
<artifactId>fluent-hc</artifactId>
2626
<version>4.5.6</version>
2727
</dependency>
28-
<dependency>
29-
<groupId>commons-cli</groupId>
30-
<artifactId>commons-cli</artifactId>
31-
<version>1.3.1</version>
32-
</dependency>
28+
<!--<dependency>-->
29+
<!--<groupId>commons-cli</groupId>-->
30+
<!--<artifactId>commons-cli</artifactId>-->
31+
<!--<version>1.3.1</version>-->
32+
<!--</dependency>-->
3333
<dependency>
3434
<groupId>org.apache.httpcomponents</groupId>
3535
<artifactId>httpmime</artifactId>
3636
<version>4.5.6</version>
3737
</dependency>
38-
38+
<dependency>
39+
<groupId>info.picocli</groupId>
40+
<artifactId>picocli</artifactId>
41+
<version>3.8.0</version>
42+
</dependency>
43+
<dependency>
44+
<groupId>net.sourceforge.argparse4j</groupId>
45+
<artifactId>argparse4j</artifactId>
46+
<version>0.8.1</version>
47+
</dependency>
3948
</dependencies>
4049
</project>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.oracle.weblogicx.imagebuilder.builder.cli;
2+
3+
import net.sourceforge.argparse4j.ArgumentParsers;
4+
import net.sourceforge.argparse4j.inf.ArgumentParser;
5+
import net.sourceforge.argparse4j.inf.ArgumentParserException;
6+
import net.sourceforge.argparse4j.inf.Namespace;
7+
8+
public class Arg4jDriver {
9+
10+
public static void main(String[] args) {
11+
ArgumentParser argParser = ArgumentParsers.newFor("builder").build()
12+
.description("Build WebLogic docker image");
13+
14+
// argParser.addArgument("-it", "--installType")
15+
// .choices("wls", "fmw").setDefault("wls").required(false)
16+
// .help("Installer type. wls or fmw (Infrastructure)");
17+
18+
argParser.addMutuallyExclusiveGroup("Choose one Installer type").required(true)
19+
.addArgument("-fmw, -wls").dest("type")
20+
.setDefault("-wls").help("Either -fmw or -wls");
21+
22+
Namespace ns = null;
23+
try {
24+
ns = argParser.parseArgs(args);
25+
System.out.println(ns.getAttrs());
26+
if (ns.getAttrs().size() < 3) {
27+
System.out.println("Empty");
28+
//argParser.printHelp();
29+
} else {
30+
System.out.println(ns.getAttrs());
31+
}
32+
} catch (ArgumentParserException e) {
33+
argParser.handleError(e);
34+
System.exit(1);
35+
}
36+
}
37+
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
package com.oracle.weblogicx.imagebuilder.builder.cli;
2+
3+
import picocli.CommandLine;
4+
import picocli.CommandLine.Command;
5+
import picocli.CommandLine.Option;
6+
7+
import java.util.ArrayList;
8+
import java.util.Arrays;
9+
import java.util.List;
10+
11+
@Command(
12+
name = "builder",
13+
mixinStandardHelpOptions = true,
14+
description = "Build WebLogic docker image",
15+
version = "1.0",
16+
sortOptions = false,
17+
subcommands = { CacheCLI.class },
18+
requiredOptionMarker = '*',
19+
abbreviateSynopsis = true
20+
)
21+
public class BuilderCLIDriver implements Runnable {
22+
23+
enum InstallerType { wls, fmw }
24+
25+
@Option(
26+
names = { "--installerType" },
27+
description = "Installer type. Supported values: ${COMPLETION-CANDIDATES}",
28+
required = true,
29+
defaultValue = "wls"
30+
)
31+
private InstallerType installerType;
32+
33+
@Option(
34+
names = { "--installerVersion" },
35+
description = "Supported values: ${COMPLETION-CANDIDATES}",
36+
required = true,
37+
defaultValue = "12.2.1.3.0",
38+
completionCandidates = VersionValues.class
39+
)
40+
private String installerVersion;
41+
42+
@Option(
43+
names = { "--latestPSU" },
44+
description = "Whether to apply patches from latest PSU. Mutually Exclusive to parameter -patches."
45+
)
46+
private boolean latestPSU = false;
47+
48+
@Option(
49+
names = { "--patches" },
50+
paramLabel = "patchId",
51+
split = ",",
52+
description = "Comma separated patch Ids. Ex: p12345678,p87654321"
53+
)
54+
private List<String> patches;
55+
56+
@Option(
57+
names = { "--fromImage" },
58+
description = "Your WebLogic docker image to use as base image."
59+
)
60+
private String fromImage;
61+
62+
@Option(
63+
names = { "--tag" },
64+
paramLabel = "TAG",
65+
required = true,
66+
description = "Tag for the final build image. Ex: store/oracle/weblogic:12.2.1.3.0"
67+
)
68+
private String imageTag;
69+
70+
@Option(
71+
names = { "--user" },
72+
paramLabel = "<support email>",
73+
required = true,
74+
description = "Your Oracle Support email id"
75+
)
76+
private String userId;
77+
78+
@Option(
79+
names = { "--password" },
80+
paramLabel = "<Wait for Prompt>",
81+
interactive = true,
82+
required = true,
83+
description = "Password for support userId"
84+
)
85+
private String password;
86+
87+
@Option(
88+
hidden = true,
89+
names = { "--publish" },
90+
description = "Publish this docker image"
91+
)
92+
private boolean isPublish = false;
93+
94+
static class VersionValues extends ArrayList<String> {
95+
VersionValues() {
96+
super(Arrays.asList("12.2.1.3.0", "12.2.1.2.0"));
97+
}
98+
}
99+
100+
public static void main(String[] args) {
101+
if (args.length == 0) {
102+
CommandLine.usage(new BuilderCLIDriver(), System.out);
103+
} else {
104+
CommandLine.run(new BuilderCLIDriver(), args);
105+
}
106+
}
107+
108+
@Override
109+
public void run() {
110+
System.out.println("hello");
111+
System.out.println("InstallerType = \"" + installerType + "\"");
112+
System.out.println("InstallerVersion = \"" + installerVersion + "\"");
113+
System.out.println("latestPSU = \"" + latestPSU + "\"");
114+
System.out.println("patches = \"" + patches + "\"");
115+
System.out.println("fromImage = \"" + fromImage + "\"");
116+
System.out.println("userId = \"" + userId + "\"");
117+
System.out.println("password = \"" + password + "\"");
118+
System.out.println("publish = \"" + isPublish + "\"");
119+
}
120+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.oracle.weblogicx.imagebuilder.builder.cli;
2+
3+
4+
public class CLIDriver {
5+
6+
public void setOptions() {
7+
8+
}
9+
public static void main(String[] args) {
10+
11+
// Options cliOptions = new Options();
12+
// cliOptions.addOption("help", "print usage details");
13+
//
14+
// cliOptions.addOption(Option.builder("bv").longOpt("baseVersion").hasArg().argName("12.2.1.3.0")
15+
// .desc("WebLogic Installer version").build());
16+
//
17+
// OptionGroup imageType = new OptionGroup();
18+
// imageType.setRequired(true);
19+
// Option wlsOption = Option.builder("wls").desc("WebLogic generic installer").build();
20+
// imageType.addOption(wlsOption);
21+
// Option fmwOption = Option.builder("fmw").desc("FMW infrastructure installer").build();
22+
// imageType.addOption(fmwOption);
23+
// cliOptions.addOptionGroup(imageType);
24+
//
25+
// Option.builder().val
26+
//
27+
// HelpFormatter helpFormatter = new HelpFormatter();
28+
// helpFormatter.printHelp("builder", cliOptions);
29+
// CommandLineParser cliParser = new DefaultParser();
30+
//
31+
// try {
32+
//// cliParser.parse(cliOptions, args);
33+
// } catch (ParseException pe) {
34+
// System.out.println("Error occurred: " + pe.getMessage());
35+
// }
36+
}
37+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.oracle.weblogicx.imagebuilder.builder.cli;
2+
3+
import com.oracle.weblogicx.imagebuilder.builder.meta.FileMetaDataResolver;
4+
import picocli.CommandLine.Command;
5+
import picocli.CommandLine.Option;
6+
7+
import java.nio.file.Files;
8+
import java.nio.file.Path;
9+
10+
@Command(
11+
name = "cache",
12+
description = "List and set cache options",
13+
helpCommand = true,
14+
mixinStandardHelpOptions = true
15+
)
16+
public class CacheCLI implements Runnable {
17+
18+
@Option(
19+
names = { "--listPath" },
20+
description = "List the cache dir path"
21+
)
22+
private boolean listCachePath = false;
23+
24+
@Option(
25+
names = { "--listItems" },
26+
description = "List items in the cache"
27+
)
28+
private boolean listCacheItems = false;
29+
30+
@Option(
31+
names = { "--setCacheDir" },
32+
description = "Set cache directory where the tool downloads the artifacts to. Default: $user.home/cache"
33+
)
34+
private Path cacheDirPath = null;
35+
36+
@Override
37+
public void run() {
38+
if (listCachePath) {
39+
System.out.println("cache dir: " + FileMetaDataResolver.META_RESOLVER.getCacheDir());
40+
}
41+
if (listCacheItems) {
42+
FileMetaDataResolver.META_RESOLVER.getCacheItems().forEach(
43+
(key, value) -> System.out.println(key + "=" + value)
44+
);
45+
}
46+
if (cacheDirPath != null) {
47+
if (!Files.exists(cacheDirPath) || !cacheDirPath.toFile().isDirectory()) {
48+
cacheDirPath.toFile().mkdirs();
49+
System.out.println("mkdirs: " + cacheDirPath);
50+
}
51+
FileMetaDataResolver.META_RESOLVER.setCacheDir(cacheDirPath.toAbsolutePath().toString());
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)