Skip to content

Commit fd6de66

Browse files
authored
Merge branch 'master' into imagetooltest1
2 parents 4214365 + 75ca0bc commit fd6de66

File tree

6 files changed

+77
-4
lines changed

6 files changed

+77
-4
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import java.util.List;
1818
import java.util.Properties;
1919
import java.util.Set;
20+
import java.util.logging.Level;
2021
import java.util.logging.Logger;
2122
import java.util.stream.Collectors;
2223

@@ -84,11 +85,19 @@ public CommandResponse call() throws Exception {
8485

8586
List<String> imageEnvCmd = Utils.getDockerRunCmd(tmpDir, fromImage, "test-env.sh");
8687
Properties baseImageProperties = Utils.runDockerCommand(imageEnvCmd);
87-
baseImageProperties.keySet().forEach(x -> logger.info(
88-
x + "=" + baseImageProperties.getProperty(x.toString())));
88+
if (logger.isLoggable(Level.FINE)) {
89+
baseImageProperties.keySet().forEach(x -> logger.fine("ENV(" + fromImage + "): "
90+
+ x + "=" + baseImageProperties.getProperty(x.toString())));
91+
}
8992

9093
boolean ohAlreadyExists = baseImageProperties.getProperty("WLS_VERSION", null) != null;
9194

95+
String existingJavaHome = baseImageProperties.getProperty("JAVA_HOME", null);
96+
if (existingJavaHome != null) {
97+
dockerfileOptions.disableJavaInstall(existingJavaHome);
98+
logger.info("JAVA_HOME detected in base image, skipping JDK install: " + existingJavaHome);
99+
}
100+
92101
if (ohAlreadyExists) {
93102
return new CommandResponse(-1,
94103
"Oracle Home exists at location:" + baseImageProperties.getProperty("ORACLE_HOME"));

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class DockerfileOptions {
1313
private boolean useWdt = false;
1414
private boolean applyPatches = false;
1515
private boolean updateOpatch = false;
16+
private boolean skipJavaInstall = false;
1617
private String username = "oracle";
1718
private String groupname = "oracle";
1819
private String javaHome = "/u01/jdk";
@@ -115,6 +116,25 @@ public void setJavaHome(String value) {
115116
javaHome = value;
116117
}
117118

119+
/**
120+
* Disable the Java installation because Java is already installed.
121+
*
122+
* @param javaHome the JAVA_HOME from the base image.
123+
*/
124+
public void disableJavaInstall(String javaHome) {
125+
this.javaHome = javaHome;
126+
skipJavaInstall = true;
127+
}
128+
129+
/**
130+
* Referenced by Dockerfile template, for enabling JDK install function.
131+
*
132+
* @return true if Java should be installed.
133+
*/
134+
public boolean installJava() {
135+
return !skipJavaInstall;
136+
}
137+
118138
/**
119139
* Referenced by Dockerfile template, for enabling patching function.
120140
*

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,32 @@ private static void processError(Process process) throws IOException {
237237
"docker command failed with error: " + stringBuilder.toString());
238238
}
239239
}
240+
//
241+
// public static boolean isJavaInstalled(String dockerImage) throws IOException, InterruptedException {
242+
// boolean result = false;
243+
// List<String> dockerInspectCommand = new ArrayList<>();
244+
// dockerInspectCommand.add("docker");
245+
// dockerInspectCommand.add("inspect");
246+
// dockerInspectCommand.add("--format='{{range .Config.Env}}{{println .}}{{end}}'");
247+
// dockerInspectCommand.add(dockerImage);
248+
// ProcessBuilder processBuilder = new ProcessBuilder(dockerInspectCommand);
249+
// Process process = processBuilder.start();
250+
// BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
251+
// String line;
252+
// while ((line = reader.readLine()) != null) {
253+
// System.out.println(line);
254+
// if (line.trim().startsWith("JAVA_HOME")) {
255+
// result = true;
256+
// }
257+
// }
258+
//
259+
// int exitVal = process.waitFor();
260+
// if (exitVal != 0) {
261+
// throw new IOException("ERROR: Unable to inspect image " + dockerImage + ",
262+
// docker returned " + exitVal);
263+
// }
264+
// return result;
265+
// }
240266

241267
private static void writeFromInputToOutputStreams(InputStream inputStream, OutputStream... outputStreams) {
242268
Thread readerThread = new Thread(() -> {

imagetool/src/main/resources/docker-files/Create_Image.mustache

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ RUN if [ -z "$(getent group {{groupid}})" ]; then hash groupadd &> /dev/null &&
3535
&& mkdir /u01 \
3636
&& chown {{userid}}:{{groupid}} /u01
3737

38+
{{#installJava}}
3839
FROM OS_UPDATE as JDK_BUILD
3940
ARG JAVA_PKG
4041

@@ -48,6 +49,7 @@ USER {{userid}}
4849
RUN tar xzf {{tempDir}}/$JAVA_PKG -C /u01 \
4950
&& mv /u01/jdk* {{java_home}} \
5051
&& rm -rf {{tempDir}}
52+
{{/installJava}}
5153

5254
FROM OS_UPDATE as WLS_BUILD
5355
ARG WLS_PKG
@@ -67,7 +69,9 @@ ENV WLS_PKG=${WLS_PKG:-fmw_12.2.1.3.0_wls_Disk1_1of1.zip} \
6769
PATCHDIR=${PATCHDIR:-patches}
6870

6971
# Install base WLS
72+
{{#installJava}}
7073
COPY --from=JDK_BUILD --chown={{userid}}:{{groupid}} {{java_home}} {{java_home}}/
74+
{{/installJava}}
7175
COPY --chown={{userid}}:{{groupid}} $WLS_PKG $WLS_RESP {{tempDir}}/
7276
COPY --chown={{userid}}:{{groupid}} $ORAINST $INV_LOC/
7377
{{#isOpatchPatchingEnabled}}
@@ -91,7 +95,7 @@ RUN unzip {{tempDir}}/$WLS_PKG -d {{tempDir}} \
9195
&& $ORACLE_HOME/OPatch/opatch napply -silent -oh $ORACLE_HOME -phBaseDir {{tempDir}}/patches \
9296
&& $ORACLE_HOME/OPatch/opatch util cleanup -silent -oh $ORACLE_HOME \
9397
{{/isPatchingEnabled}}
94-
&& rm -rf {{java_home}} {{tempDir}}
98+
&& rm -rf {{tempDir}}
9599

96100
{{#isWdtEnabled}}
97101
FROM OS_UPDATE as WDT_BUILD
@@ -135,7 +139,9 @@ ENV WDT_PKG=${WDT_PKG:-weblogic-deploy.zip} \
135139
ENV DOMAIN_HOME=${DOMAIN_HOME:-/u01/domains/base_domain} \
136140
PATH=$PATH:{{java_home}}/bin:${ORACLE_HOME}/oracle_common/common/bin:${ORACLE_HOME}/wlserver/common/bin:${DOMAIN_HOME}/bin:${ORACLE_HOME}
137141

142+
{{#installJava}}
138143
COPY --from=JDK_BUILD --chown={{userid}}:{{groupid}} {{java_home}} {{java_home}}/
144+
{{/installJava}}
139145
COPY --from=WLS_BUILD --chown={{userid}}:{{groupid}} $ORACLE_HOME $ORACLE_HOME/
140146
COPY --chown={{userid}}:{{groupid}} ${WDT_PKG} ${WDT_MODEL} ${WDT_ARCHIVE} ${WDT_VARIABLE} {{tempDir}}/
141147

@@ -158,7 +164,7 @@ RUN unzip {{tempDir}}/$WDT_PKG -d $(dirname $WDT_HOME) \
158164
$VARIABLE_OPT \
159165
$MODEL_OPT \
160166
$ARCHIVE_OPT \
161-
&& rm -rf {{java_home}} ${ORACLE_HOME} ${WDT_HOME} {{tempDir}}
167+
&& rm -rf ${ORACLE_HOME} ${WDT_HOME} {{tempDir}}
162168
{{/isWdtEnabled}}
163169

164170
FROM {{baseImage}} as FINAL_BUILD
@@ -174,7 +180,9 @@ ARG ADMIN_PORT
174180
ARG MANAGED_SERVER_PORT
175181

176182
ENV ORACLE_HOME=${ORACLE_HOME} \
183+
{{#installJava}}
177184
JAVA_HOME={{java_home}} \
185+
{{/installJava}}
178186
{{#isWdtEnabled}}
179187
ADMIN_NAME=${ADMIN_NAME:-admin-server} \
180188
ADMIN_HOST=${ADMIN_HOST:-wlsadmin} \
@@ -198,7 +206,9 @@ RUN if [ -z "$(getent group {{groupid}})" ]; then hash groupadd &> /dev/null &&
198206
&& mkdir -p $(dirname {{java_home}}) $(dirname $ORACLE_HOME) $(dirname $DOMAIN_HOME) \
199207
&& chown {{userid}}:{{groupid}} $(dirname {{java_home}}) $(dirname $ORACLE_HOME) $(dirname $DOMAIN_HOME)
200208

209+
{{#installJava}}
201210
COPY --from=JDK_BUILD --chown={{userid}}:{{groupid}} $JAVA_HOME {{java_home}}/
211+
{{/installJava}}
202212
COPY --from=WLS_BUILD --chown={{userid}}:{{groupid}} $ORACLE_HOME $ORACLE_HOME/
203213
{{#isWdtEnabled}}
204214
COPY --from=WDT_BUILD --chown={{userid}}:{{groupid}} $DOMAIN_HOME $DOMAIN_HOME/

imagetool/src/main/resources/probe-env/test-create-env.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ if [[ -f /etc/os-release ]]; then
1010
cat /etc/os-release | grep -oE '^VERSION_ID=[\"]?[[:digit:]\.]+[\"]?'
1111
fi
1212

13+
if [[ ! -z "$JAVA_HOME" ]]; then
14+
echo JAVA_HOME="$JAVA_HOME"
15+
fi
16+
1317
if [[ ! -z "$ORACLE_HOME" ]]; then
1418
echo ORACLE_HOME="$ORACLE_HOME"
1519
WLS_TYPE=$(cat $ORACLE_HOME/inventory/registry.xml 2> /dev/null | grep -q 'WebLogic Server for FMW' && printf "fmw")

imagetool/src/main/resources/probe-env/test-update-env.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ if [[ -f /etc/os-release ]]; then
1010
cat /etc/os-release | grep -oE '^VERSION_ID=[\"]?[[:digit:]\.]+[\"]?'
1111
fi
1212

13+
if [[ ! -z "$JAVA_HOME" ]]; then
14+
echo JAVA_HOME="$JAVA_HOME"
15+
fi
16+
1317
if [[ ! -z "$ORACLE_HOME" ]]; then
1418
echo ORACLE_HOME="$ORACLE_HOME"
1519
WLS_TYPE=$(cat $ORACLE_HOME/inventory/registry.xml 2> /dev/null | grep -q 'WebLogic Server for FMW' && printf "fmw")

0 commit comments

Comments
 (0)