Skip to content

Commit 6a30387

Browse files
authored
Enable experimental Podman support (#255)
* allow user to override default image builder with podman * use the same engine for image creation and running containers * removed old environment variables and removed default expose command from final image * removed ARG for WDT encryption key and moved to bean property in Dockerfile generation * removed unnecessary ARG statements from Dockerfile * removed remaining references to ADMIN_PORT and MANAGED_SERVER_PORT
1 parent 4647b70 commit 6a30387

File tree

15 files changed

+150
-145
lines changed

15 files changed

+150
-145
lines changed

imagetool/src/main/java/com/oracle/weblogic/imagetool/util/DockerBuildCommand.java renamed to imagetool/src/main/java/com/oracle/weblogic/imagetool/builder/BuildCommand.java

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2020, 2021, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

4-
package com.oracle.weblogic.imagetool.util;
4+
package com.oracle.weblogic.imagetool.builder;
55

66
import java.io.BufferedReader;
77
import java.io.FileOutputStream;
@@ -22,24 +22,33 @@
2222

2323
import com.oracle.weblogic.imagetool.logging.LoggingFacade;
2424
import com.oracle.weblogic.imagetool.logging.LoggingFactory;
25+
import com.oracle.weblogic.imagetool.util.CloseableList;
26+
import com.oracle.weblogic.imagetool.util.Utils;
2527

26-
public class DockerBuildCommand {
27-
private static final LoggingFacade logger = LoggingFactory.getLogger(DockerBuildCommand.class);
28+
public class BuildCommand {
29+
private static final LoggingFacade logger = LoggingFactory.getLogger(BuildCommand.class);
2830

29-
private List<String> command;
30-
private List<BuildArg> buildArgs;
31-
private String context;
31+
private final List<String> command;
32+
private final List<BuildArg> buildArgs;
33+
private final String context;
3234

3335
/**
34-
* Create a Docker build command for creating an image.
36+
* Create a build command for creating an image. At some point, it might
37+
* be beneficial to subclass this with separate classes for each builder (docker or podman).
38+
* For now, the differences do not justify the extra complexity.
3539
*/
36-
public DockerBuildCommand(String contextFolder) {
40+
public BuildCommand(String buildEngine, String contextFolder) {
3741
Objects.requireNonNull(contextFolder);
3842
buildArgs = new ArrayList<>();
39-
command = Stream.of("docker", "build", "--no-cache").collect(Collectors.toList());
43+
command = Stream.of(buildEngine, "build", "--no-cache").collect(Collectors.toList());
4044
context = contextFolder;
4145
}
4246

47+
/**
48+
* If Docker is not on the user's path, set the full path to the executable.
49+
* @param value full path to Docker
50+
* @deprecated use --builder instead
51+
*/
4352
public void dockerPath(String value) {
4453
command.set(0, value);
4554
}
@@ -49,7 +58,7 @@ public void dockerPath(String value) {
4958
* @param value name to be used as the image tag.
5059
* @return this
5160
*/
52-
public DockerBuildCommand tag(String value) {
61+
public BuildCommand tag(String value) {
5362
if (Utils.isEmptyString(value)) {
5463
return this;
5564
}
@@ -64,7 +73,7 @@ public DockerBuildCommand tag(String value) {
6473
* @param value true to enable --force-rm on docker build.
6574
* @return this
6675
*/
67-
public DockerBuildCommand forceRm(boolean value) {
76+
public BuildCommand forceRm(boolean value) {
6877
if (value) {
6978
command.add("--force-rm");
7079
}
@@ -77,7 +86,7 @@ public DockerBuildCommand forceRm(boolean value) {
7786
* @param key the ARG
7887
* @param value the value to be used in the Dockerfile for this ARG
7988
*/
80-
public DockerBuildCommand buildArg(String key, String value) {
89+
public BuildCommand buildArg(String key, String value) {
8190
return buildArg(key, value, false);
8291
}
8392

@@ -87,7 +96,7 @@ public DockerBuildCommand buildArg(String key, String value) {
8796
* @param value the value to be used in the Dockerfile for this ARG
8897
* @param conceal true for passwords so the value is not logged
8998
*/
90-
public DockerBuildCommand buildArg(String key, String value, boolean conceal) {
99+
public BuildCommand buildArg(String key, String value, boolean conceal) {
91100
if (Utils.isEmptyString(value)) {
92101
return this;
93102
}
@@ -103,7 +112,7 @@ public DockerBuildCommand buildArg(String key, String value, boolean conceal) {
103112
* Add a --network to the Docker build command.
104113
* @param value the Docker network to use
105114
*/
106-
public DockerBuildCommand network(String value) {
115+
public BuildCommand network(String value) {
107116
if (Utils.isEmptyString(value)) {
108117
return this;
109118
}
@@ -116,7 +125,7 @@ public DockerBuildCommand network(String value) {
116125
* Add a --pull to the Docker build command. If value is false, return without adding the --pull.
117126
* @param value true to add the pull
118127
*/
119-
public DockerBuildCommand pull(boolean value) {
128+
public BuildCommand pull(boolean value) {
120129
if (value) {
121130
command.add("--pull");
122131
}
@@ -130,7 +139,7 @@ public DockerBuildCommand pull(boolean value) {
130139
* @throws IOException if an error occurs reading from the process inputstream.
131140
* @throws InterruptedException when the process wait is interrupted.
132141
*/
133-
public DockerBuildCommand run(Path dockerLog)
142+
public BuildCommand run(Path dockerLog)
134143
throws IOException, InterruptedException {
135144
// process builder
136145
logger.entering(getCommand(false), dockerLog);
@@ -180,7 +189,7 @@ private Path createFile(Path filePath) {
180189
}
181190
}
182191
} catch (IOException e) {
183-
logger.fine("Failed to create Docker log file", e);
192+
logger.fine("Failed to create log file for the build command", e);
184193
logFilePath = null;
185194
}
186195
}

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

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.oracle.weblogic.imagetool.aru.AruPatch;
2323
import com.oracle.weblogic.imagetool.aru.AruProduct;
2424
import com.oracle.weblogic.imagetool.aru.AruUtil;
25+
import com.oracle.weblogic.imagetool.builder.BuildCommand;
2526
import com.oracle.weblogic.imagetool.cachestore.MultiplePatchVersionsException;
2627
import com.oracle.weblogic.imagetool.cachestore.OPatchFile;
2728
import com.oracle.weblogic.imagetool.cachestore.PatchFile;
@@ -30,7 +31,6 @@
3031
import com.oracle.weblogic.imagetool.logging.LoggingFactory;
3132
import com.oracle.weblogic.imagetool.util.AdditionalBuildCommands;
3233
import com.oracle.weblogic.imagetool.util.Constants;
33-
import com.oracle.weblogic.imagetool.util.DockerBuildCommand;
3434
import com.oracle.weblogic.imagetool.util.DockerfileOptions;
3535
import com.oracle.weblogic.imagetool.util.Utils;
3636
import picocli.CommandLine.Option;
@@ -94,8 +94,8 @@ private void handleAdditionalBuildCommands() throws IOException {
9494
}
9595
}
9696

97-
void runDockerCommand(String dockerfile, DockerBuildCommand command) throws IOException, InterruptedException {
98-
logger.info("docker cmd = " + command.toString());
97+
void runDockerCommand(String dockerfile, BuildCommand command) throws IOException, InterruptedException {
98+
logger.info("IMG-0078", command.toString());
9999

100100
if (dryRun) {
101101
System.out.println("########## BEGIN DOCKERFILE ##########");
@@ -112,9 +112,9 @@ void runDockerCommand(String dockerfile, DockerBuildCommand command) throws IOEx
112112
*
113113
* @return list of options
114114
*/
115-
DockerBuildCommand getInitialBuildCmd(String contextFolder) {
115+
BuildCommand getInitialBuildCmd(String contextFolder) {
116116
logger.entering();
117-
DockerBuildCommand cmdBuilder = new DockerBuildCommand(contextFolder);
117+
BuildCommand cmdBuilder = new BuildCommand(buildEngine, contextFolder);
118118

119119
cmdBuilder.forceRm(!skipcleanup)
120120
.tag(imageTag)
@@ -125,6 +125,8 @@ DockerBuildCommand getInitialBuildCmd(String contextFolder) {
125125
.buildArg("no_proxy", nonProxyHosts);
126126

127127
if (dockerPath != null && Files.isExecutable(dockerPath)) {
128+
// remove this IF block after the deprecation period
129+
logger.warning("--dockerPath is deprecated, use --builder");
128130
cmdBuilder.dockerPath(dockerPath.toAbsolutePath().toString());
129131
}
130132
logger.exiting();
@@ -357,7 +359,7 @@ public void copyOptionsFromImage(String fromImage, String tmpDir) throws IOExcep
357359
Utils.copyResourceAsFile("/probe-env/test-create-env.sh",
358360
tmpDir + File.separator + "test-env.sh", true);
359361

360-
Properties baseImageProperties = Utils.getBaseImageProperties(fromImage, tmpDir);
362+
Properties baseImageProperties = Utils.getBaseImageProperties(buildEngine, fromImage, tmpDir);
361363

362364
if (baseImageProperties.getProperty("WLS_VERSION", null) != null) {
363365
throw new IllegalArgumentException(Utils.getMessage("IMG-0038", fromImage,
@@ -447,11 +449,16 @@ String getPassword() {
447449
)
448450
private String httpsProxyUrl;
449451

452+
/**
453+
* Set the Docker build executable when "docker" is not on the path.
454+
* @deprecated use --builder instead
455+
*/
450456
@Option(
451457
names = {"--docker"},
452458
description = "path to docker executable. Default: ${DEFAULT-VALUE}",
453459
defaultValue = "docker"
454460
)
461+
@Deprecated
455462
private Path dockerPath;
456463

457464
@Option(
@@ -463,7 +470,7 @@ String getPassword() {
463470

464471
@Option(
465472
names = {"--skipcleanup"},
466-
description = "Do no delete Docker context folder, intermediate images, and failed build container."
473+
description = "Do no delete build context folder, intermediate images, and failed build container."
467474
)
468475
boolean skipcleanup = false;
469476

@@ -490,7 +497,7 @@ String getPassword() {
490497

491498
@Option(
492499
names = {"--dryRun"},
493-
description = "Skip Docker build execution and print Dockerfile to stdout"
500+
description = "Skip image build execution and print Dockerfile to stdout"
494501
)
495502
boolean dryRun = false;
496503

@@ -550,7 +557,14 @@ String getPassword() {
550557
)
551558
PackageManagerType packageManager = PackageManagerType.OS_DEFAULT;
552559

560+
@Option(
561+
names = {"--builder", "-b"},
562+
description = "Executable to process the Dockerfile. Default: ${DEFAULT-VALUE}"
563+
)
564+
String buildEngine = "docker";
565+
553566
@SuppressWarnings("unused")
554567
@Unmatched
568+
555569
List<String> unmatchedOptions;
556570
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414

1515
import com.oracle.weblogic.imagetool.api.model.CachedFile;
1616
import com.oracle.weblogic.imagetool.api.model.CommandResponse;
17+
import com.oracle.weblogic.imagetool.builder.BuildCommand;
1718
import com.oracle.weblogic.imagetool.installer.FmwInstallerType;
1819
import com.oracle.weblogic.imagetool.installer.InstallerType;
1920
import com.oracle.weblogic.imagetool.installer.MiddlewareInstall;
2021
import com.oracle.weblogic.imagetool.logging.LoggingFacade;
2122
import com.oracle.weblogic.imagetool.logging.LoggingFactory;
2223
import com.oracle.weblogic.imagetool.util.Constants;
23-
import com.oracle.weblogic.imagetool.util.DockerBuildCommand;
2424
import com.oracle.weblogic.imagetool.util.Utils;
2525
import picocli.CommandLine.ArgGroup;
2626
import picocli.CommandLine.Command;
@@ -66,7 +66,7 @@ public CommandResponse call() throws Exception {
6666
install.copyFiles(cache(), tmpDir);
6767
dockerfileOptions.setMiddlewareInstall(install);
6868

69-
DockerBuildCommand cmdBuilder = getInitialBuildCmd(tmpDir);
69+
BuildCommand cmdBuilder = getInitialBuildCmd(tmpDir);
7070
// build wdt args if user passes --wdtModelPath
7171
wdtOptions.handleWdtArgs(dockerfileOptions, cmdBuilder, tmpDir);
7272

@@ -105,7 +105,7 @@ public CommandResponse call() throws Exception {
105105
} finally {
106106
if (!skipcleanup) {
107107
Utils.deleteFilesRecursively(tmpDir);
108-
Utils.removeIntermediateDockerImages(buildId);
108+
Utils.removeIntermediateDockerImages(buildEngine, buildId);
109109
}
110110
}
111111
Instant endTime = Instant.now();

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

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515

1616
import com.oracle.weblogic.imagetool.api.model.CachedFile;
1717
import com.oracle.weblogic.imagetool.api.model.CommandResponse;
18+
import com.oracle.weblogic.imagetool.builder.BuildCommand;
1819
import com.oracle.weblogic.imagetool.installer.FmwInstallerType;
1920
import com.oracle.weblogic.imagetool.installer.InstallerType;
2021
import com.oracle.weblogic.imagetool.installer.MiddlewareInstall;
2122
import com.oracle.weblogic.imagetool.logging.LoggingFacade;
2223
import com.oracle.weblogic.imagetool.logging.LoggingFactory;
2324
import com.oracle.weblogic.imagetool.util.Constants;
24-
import com.oracle.weblogic.imagetool.util.DockerBuildCommand;
2525
import com.oracle.weblogic.imagetool.util.DockerfileOptions;
2626
import com.oracle.weblogic.imagetool.util.Utils;
2727
import picocli.CommandLine.Command;
@@ -52,8 +52,6 @@ public CommandResponse call() throws Exception {
5252
String newOracleHome = null;
5353
String newJavaHome = null;
5454
String domainHome;
55-
String adminPort;
56-
String managedServerPort;
5755

5856
try {
5957

@@ -69,14 +67,11 @@ public CommandResponse call() throws Exception {
6967
Utils.copyResourceAsFile("/probe-env/test-update-env.sh",
7068
tmpDir + File.separator + "test-env.sh", true);
7169

72-
Properties baseImageProperties = Utils.getBaseImageProperties(sourceImage, tmpDir);
70+
Properties baseImageProperties = Utils.getBaseImageProperties(buildEngine, sourceImage, tmpDir);
7371

7472
oldOracleHome = baseImageProperties.getProperty("ORACLE_HOME", null);
7573
oldJavaHome = baseImageProperties.getProperty("JAVA_PATH", null);
7674
domainHome = baseImageProperties.getProperty("DOMAIN_HOME", null);
77-
adminPort = baseImageProperties.getProperty("ADMIN_PORT", null);
78-
managedServerPort = baseImageProperties.getProperty("MANAGED_SERVER_PORT", null);
79-
8075

8176
} else {
8277
return new CommandResponse(-1, "Source Image not set");
@@ -91,7 +86,7 @@ public CommandResponse call() throws Exception {
9186
Utils.copyResourceAsFile("/probe-env/test-update-env.sh",
9287
tmpDir + File.separator + "test-env.sh", true);
9388

94-
Properties baseImageProperties = Utils.getBaseImageProperties(targetImage, tmpDir);
89+
Properties baseImageProperties = Utils.getBaseImageProperties(buildEngine, targetImage, tmpDir);
9590

9691
newOracleHome = baseImageProperties.getProperty("ORACLE_HOME", null);
9792
newJavaHome = baseImageProperties.getProperty("JAVA_PATH", null);
@@ -114,10 +109,7 @@ public CommandResponse call() throws Exception {
114109
return new CommandResponse(-1, Utils.getMessage("IMG-0025"));
115110
}
116111

117-
DockerBuildCommand cmdBuilder = getInitialBuildCmd(tmpDir);
118-
119-
cmdBuilder.buildArg("ADMIN_PORT", adminPort)
120-
.buildArg("MANAGED_SERVER_PORT", managedServerPort);
112+
BuildCommand cmdBuilder = getInitialBuildCmd(tmpDir);
121113

122114
if (dockerfileOptions.isRebaseToNew()) {
123115

@@ -165,7 +157,7 @@ public CommandResponse call() throws Exception {
165157
} finally {
166158
if (!skipcleanup) {
167159
Utils.deleteFilesRecursively(tmpDir);
168-
Utils.removeIntermediateDockerImages(buildId);
160+
Utils.removeIntermediateDockerImages(buildEngine, buildId);
169161
}
170162
}
171163
Instant endTime = Instant.now();

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
import java.util.concurrent.Callable;
1515

1616
import com.oracle.weblogic.imagetool.api.model.CommandResponse;
17+
import com.oracle.weblogic.imagetool.builder.BuildCommand;
1718
import com.oracle.weblogic.imagetool.cachestore.OPatchFile;
1819
import com.oracle.weblogic.imagetool.installer.FmwInstallerType;
1920
import com.oracle.weblogic.imagetool.logging.LoggingFacade;
2021
import com.oracle.weblogic.imagetool.logging.LoggingFactory;
2122
import com.oracle.weblogic.imagetool.util.Constants;
22-
import com.oracle.weblogic.imagetool.util.DockerBuildCommand;
2323
import com.oracle.weblogic.imagetool.util.Utils;
2424
import com.oracle.weblogic.imagetool.wdt.WdtOperation;
2525
import picocli.CommandLine.ArgGroup;
@@ -60,7 +60,7 @@ public CommandResponse call() throws Exception {
6060
Utils.copyResourceAsFile("/probe-env/test-update-env.sh",
6161
tmpDir + File.separator + "test-env.sh", true);
6262

63-
Properties baseImageProperties = Utils.getBaseImageProperties(fromImage, tmpDir);
63+
Properties baseImageProperties = Utils.getBaseImageProperties(buildEngine, fromImage, tmpDir);
6464

6565
dockerfileOptions.setJavaHome(baseImageProperties.getProperty("JAVA_HOME", null));
6666

@@ -144,7 +144,7 @@ public CommandResponse call() throws Exception {
144144
}
145145
}
146146

147-
DockerBuildCommand cmdBuilder = getInitialBuildCmd(tmpDir);
147+
BuildCommand cmdBuilder = getInitialBuildCmd(tmpDir);
148148

149149
// build wdt args if user passes --wdtModelPath
150150
wdtOptions.handleWdtArgs(dockerfileOptions, cmdBuilder, tmpDir);
@@ -172,7 +172,7 @@ public CommandResponse call() throws Exception {
172172
} finally {
173173
if (!skipcleanup) {
174174
Utils.deleteFilesRecursively(tmpDir);
175-
Utils.removeIntermediateDockerImages(buildId);
175+
Utils.removeIntermediateDockerImages(buildEngine, buildId);
176176
}
177177
}
178178
Instant endTime = Instant.now();

0 commit comments

Comments
 (0)