Skip to content

Commit 5097101

Browse files
authored
added --pull option for docker build (#155)
1 parent 5905a3e commit 5097101

File tree

7 files changed

+55
-34
lines changed

7 files changed

+55
-34
lines changed

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

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -106,30 +106,18 @@ void runDockerCommand(String dockerfile, DockerBuildCommand command) throws IOEx
106106
* @return list of options
107107
*/
108108
DockerBuildCommand getInitialBuildCmd(String contextFolder) {
109-
110109
logger.entering();
111110
DockerBuildCommand cmdBuilder = new DockerBuildCommand(contextFolder);
112111

113-
cmdBuilder.setTag(imageTag);
114-
115-
if (!Utils.isEmptyString(buildNetwork)) {
116-
cmdBuilder.addNetworkArg(buildNetwork);
117-
}
118-
119-
if (!Utils.isEmptyString(httpProxyUrl)) {
120-
cmdBuilder.addBuildArg("http_proxy", httpProxyUrl);
121-
}
122-
123-
if (!Utils.isEmptyString(httpsProxyUrl)) {
124-
cmdBuilder.addBuildArg("https_proxy", httpsProxyUrl);
125-
}
126-
127-
if (!Utils.isEmptyString(nonProxyHosts)) {
128-
cmdBuilder.addBuildArg("no_proxy", nonProxyHosts);
129-
}
112+
cmdBuilder.tag(imageTag)
113+
.network(buildNetwork)
114+
.pull(buildPull)
115+
.buildArg("http_proxy", httpProxyUrl)
116+
.buildArg("https_proxy", httpsProxyUrl)
117+
.buildArg("no_proxy", nonProxyHosts);
130118

131119
if (dockerPath != null && Files.isExecutable(dockerPath)) {
132-
cmdBuilder.setDockerPath(dockerPath.toAbsolutePath().toString());
120+
cmdBuilder.dockerPath(dockerPath.toAbsolutePath().toString());
133121
}
134122
logger.exiting();
135123
return cmdBuilder;
@@ -392,6 +380,12 @@ String getPassword() {
392380
)
393381
String buildNetwork;
394382

383+
@Option(
384+
names = {"--pull"},
385+
description = "Always attempt to pull a newer version of base images during the build"
386+
)
387+
boolean buildPull = false;
388+
395389
@SuppressWarnings("unused")
396390
@Unmatched
397391
List<String> unmatchedOptions;

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,8 @@ public CommandResponse call() throws Exception {
114114

115115
DockerBuildCommand cmdBuilder = getInitialBuildCmd(tmpDir);
116116

117-
if (adminPort != null) {
118-
cmdBuilder.addBuildArg("ADMIN_PORT", adminPort);
119-
}
120-
121-
if (managedServerPort != null) {
122-
cmdBuilder.addBuildArg("MANAGED_SERVER_PORT", managedServerPort);
123-
}
117+
cmdBuilder.buildArg("ADMIN_PORT", adminPort)
118+
.buildArg("MANAGED_SERVER_PORT", managedServerPort);
124119

125120
if (dockerfileOptions.isRebaseToNew()) {
126121

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void handleWdtArgs(DockerfileOptions dockerfileOptions, DockerBuildCommand cmdBu
4545
String encryptionKey = Utils.getPasswordFromInputs(encryptionKeyStr, encryptionKeyFile, encryptionKeyEnv);
4646
if (encryptionKey != null) {
4747
dockerfileOptions.setWdtUseEncryption(true);
48-
cmdBuilder.addBuildArg("WDT_ENCRYPTION_KEY", encryptionKey, true);
48+
cmdBuilder.buildArg("WDT_ENCRYPTION_KEY", encryptionKey, true);
4949
}
5050

5151
dockerfileOptions.setWdtEnabled();

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

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,22 @@ public DockerBuildCommand(String contextFolder) {
4141
context = contextFolder;
4242
}
4343

44-
public void setDockerPath(String value) {
44+
public void dockerPath(String value) {
4545
command.set(0, value);
4646
}
4747

48-
public void setTag(String value) {
48+
/**
49+
* Add Docker image tag name for this build command.
50+
* @param value name to be used as the image tag.
51+
* @return this
52+
*/
53+
public DockerBuildCommand tag(String value) {
54+
if (Utils.isEmptyString(value)) {
55+
return this;
56+
}
4957
command.add("--tag");
5058
command.add(value);
59+
return this;
5160
}
5261

5362
/**
@@ -56,8 +65,8 @@ public void setTag(String value) {
5665
* @param key the ARG
5766
* @param value the value to be used in the Dockerfile for this ARG
5867
*/
59-
public void addBuildArg(String key, String value) {
60-
addBuildArg(key, value, false);
68+
public DockerBuildCommand buildArg(String key, String value) {
69+
return buildArg(key, value, false);
6170
}
6271

6372
/**
@@ -66,21 +75,40 @@ public void addBuildArg(String key, String value) {
6675
* @param value the value to be used in the Dockerfile for this ARG
6776
* @param conceal true for passwords so the value is not logged
6877
*/
69-
public void addBuildArg(String key, String value, boolean conceal) {
78+
public DockerBuildCommand buildArg(String key, String value, boolean conceal) {
79+
if (Utils.isEmptyString(value)) {
80+
return this;
81+
}
7082
BuildArg arg = new BuildArg();
7183
arg.key = key;
7284
arg.value = value;
7385
arg.conceal = conceal;
7486
buildArgs.add(arg);
87+
return this;
7588
}
7689

7790
/**
7891
* Add a --network to the Docker build command.
7992
* @param value the Docker network to use
8093
*/
81-
public void addNetworkArg(String value) {
94+
public DockerBuildCommand network(String value) {
95+
if (Utils.isEmptyString(value)) {
96+
return this;
97+
}
8298
command.add("--network");
8399
command.add(value);
100+
return this;
101+
}
102+
103+
/**
104+
* Add a --pull to the Docker build command. If value is false, return without adding the --pull.
105+
* @param value true to add the pull
106+
*/
107+
public DockerBuildCommand pull(boolean value) {
108+
if (value) {
109+
command.add("--pull");
110+
}
111+
return this;
84112
}
85113

86114
/**
@@ -90,7 +118,7 @@ public void addNetworkArg(String value) {
90118
* @throws IOException if an error occurs reading from the process inputstream.
91119
* @throws InterruptedException when the process wait is interrupted.
92120
*/
93-
public void run(Path dockerLog)
121+
public DockerBuildCommand run(Path dockerLog)
94122
throws IOException, InterruptedException {
95123
// process builder
96124
logger.entering(getCommand(false), dockerLog);
@@ -114,6 +142,7 @@ public void run(Path dockerLog)
114142
if (process.waitFor() != 0) {
115143
Utils.processError(process);
116144
}
145+
return this;
117146
}
118147

119148
/**

site/create-image.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Usage: imagetool create [OPTIONS]
2727
| `--passwordEnv` | Environment variable containing the Oracle Support password, see `--user`. | |
2828
| `--passwordFile` | Path to a file containing just the Oracle Support password, see `--user`. | |
2929
| `--patches` | Comma separated list of patch IDs. Example: `12345678,87654321` | |
30+
| `--pull` | Always attempt to pull a newer version of base images during the build. | |
3031
| `--tag` | (Required) Tag for the final build image. Example: `store/oracle/weblogic:12.2.1.3.0` | |
3132
| `--type` | Installer type. Supported values: `WLS`, `FMW`, `IDM`, `OSB`, `OUD_WLS`, `SOA_OSB`, `WCP`, `OAM`, `OIG`, `OUD`, `SOA`, `WCC`, `WCS`, `WCP` | `WLS` |
3233
| `--user` | Oracle support email ID. | |

site/rebase-image.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Usage: imagetool rebase [OPTIONS]
2929
| `--passwordEnv` | Environment variable containing the Oracle Support password, see `--user`. | |
3030
| `--passwordFile` | Path to a file containing just the Oracle Support password, see `--user`. | |
3131
| `--patches` | Comma separated list of patch IDs. Example: `12345678,87654321` | |
32+
| `--pull` | Always attempt to pull a newer version of base images during the build. | |
3233
| `--sourceImage` | (Required) Source Image containing the WebLogic domain. | |
3334
| `--tag` | (Required) Tag for the final build image. Example: `store/oracle/weblogic:12.2.1.3.0` | |
3435
| `--targetImage` | Docker image to extend for the domain's new image. | |

site/update-image.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Update WebLogic Docker image with selected patches
3838
| `--passwordEnv` | Environment variable containing the Oracle Support password, see `--user`. | |
3939
| `--passwordFile` | Path to a file containing just the Oracle Support password, see `--user`. | |
4040
| `--patches` | Comma separated list of patch IDs. Example: `12345678,87654321` | |
41+
| `--pull` | Always attempt to pull a newer version of base images during the build. | |
4142
| `--tag` | (Required) Tag for the final build image. Example: `store/oracle/weblogic:12.2.1.3.0` | |
4243
| `--user` | Oracle support email ID. | |
4344
| `--wdtArchive` | Path to the WDT archive file used by the WDT model. | |

0 commit comments

Comments
 (0)