Skip to content

Commit 27f94de

Browse files
committed
Merge branch 'master' of https://github.com/oracle/weblogic-image-tool into imagetooltest1
2 parents 8229fc0 + e5ac102 commit 27f94de

File tree

6 files changed

+98
-45
lines changed

6 files changed

+98
-45
lines changed

imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/cache/AddInstallerEntry.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ public AddInstallerEntry(boolean isCLIMode) {
3131
public CommandResponse call() {
3232
if (location != null && Files.isRegularFile(location) && !Utils.isEmptyString(version)) {
3333
String key = String.format("%s%s%s", type, CacheStore.CACHE_KEY_SEPARATOR, version);
34+
if (cacheStore.getValueFromCache(key) != null) {
35+
return new CommandResponse(-1, String.format("Installer already exists %s=%s. Try removing it "
36+
+ "using the deleteEntry command before adding it again.",
37+
key,
38+
cacheStore.getValueFromCache(key)));
39+
}
3440
cacheStore.addToCache(key, location.toAbsolutePath().toString());
3541
return new CommandResponse(0, String.format("Successfully added to cache. %s=%s", key,
3642
cacheStore.getValueFromCache(key)));

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.util.logging.Logger;
2222
import java.util.stream.Collectors;
2323

24-
import com.oracle.weblogic.imagetool.api.model.CachePolicy;
2524
import com.oracle.weblogic.imagetool.api.model.CommandResponse;
2625
import com.oracle.weblogic.imagetool.api.model.DomainType;
2726
import com.oracle.weblogic.imagetool.api.model.InstallerType;

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import java.util.List;
1414
import java.util.concurrent.Callable;
1515
import java.util.logging.Logger;
16+
import java.util.regex.Matcher;
17+
import java.util.regex.Pattern;
1618
import java.util.stream.Collectors;
1719
import java.util.stream.Stream;
1820

@@ -61,6 +63,9 @@ public CommandResponse call() throws Exception {
6163
return new CommandResponse(-1, "user Oracle support credentials do not match");
6264
}
6365
}
66+
67+
handleChown();
68+
6469
logger.finer("Exiting ImageOperation call ");
6570
return new CommandResponse(0, null);
6671
}
@@ -188,6 +193,28 @@ void addOPatch1394ToImage(Path tmpDir, String opatchBugNumber) throws Exception
188193
dockerfileOptions.setOPatchPatchingEnabled();
189194
}
190195

196+
private void handleChown() {
197+
if (osUserAndGroup.length != 2) {
198+
throw new IllegalArgumentException("--chown value must be a colon separated user and group. user:group");
199+
}
200+
201+
Pattern p = Pattern.compile("^[a-z_]([a-z0-9_-]{0,31}|[a-z0-9_-]{0,30}\\$)$");
202+
Matcher usr = p.matcher(osUserAndGroup[0]);
203+
if (!usr.matches()) {
204+
throw new IllegalArgumentException("--chown must contain a valid Unix username. No more than 32 characters"
205+
+ " and starts with a lowercase character. Invalid value = " + osUserAndGroup[0]);
206+
}
207+
Matcher grp = p.matcher(osUserAndGroup[1]);
208+
if (!grp.matches()) {
209+
throw new IllegalArgumentException("--chown must contain a valid Unix groupid. No more than 32 characters"
210+
+ " and starts with a lowercase character. Invalid value = " + osUserAndGroup[1]);
211+
}
212+
213+
dockerfileOptions.setUserId(osUserAndGroup[0]);
214+
dockerfileOptions.setGroupId(osUserAndGroup[1]);
215+
}
216+
217+
191218
WLSInstallerType installerType = WLSInstallerType.WLS;
192219

193220
String installerVersion = Constants.DEFAULT_WLS_VERSION;
@@ -277,6 +304,14 @@ void addOPatch1394ToImage(Path tmpDir, String opatchBugNumber) throws Exception
277304
)
278305
Path dockerLog;
279306

307+
@Option(
308+
names = {"--chown"},
309+
split = ":",
310+
description = "userid:groupid for JDK/Middleware installs and patches. Default: ${DEFAULT-VALUE}.",
311+
defaultValue = "oracle:oracle"
312+
)
313+
private String[] osUserAndGroup;
314+
280315
@Unmatched
281316
List<String> unmatchedOptions;
282317
}

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
@@ -17,6 +17,7 @@ public class DockerfileOptions {
1717
private String groupname = "oracle";
1818
private String javaHome = "/u01/jdk";
1919
private String baseImageName = "oraclelinux:7-slim";
20+
private String tempDirectory = "/tmp/delme";
2021

2122
/**
2223
* Options to be used with the Mustache template.
@@ -170,4 +171,23 @@ public DockerfileOptions setWdtEnabled() {
170171
useWdt = true;
171172
return this;
172173
}
174+
175+
/**
176+
* Referenced by Dockerfile template, provides location where installers should write their temporary files.
177+
*
178+
* @return the full path to the temporary directory that should be used.
179+
*/
180+
public String tempDir() {
181+
return tempDirectory;
182+
}
183+
184+
/**
185+
* The location where installers should write their temporary files.
186+
*
187+
* @param value the full path to the temporary directory that should be used.
188+
*/
189+
public void setTempDirectory(String value) {
190+
191+
tempDirectory = value;
192+
}
173193
}

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

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ FROM {{baseImage}} as OS_UPDATE
88
USER root
99

1010
{{#useYum}}
11-
RUN yum -y --downloaddir=$OTMPDIR install gzip tar unzip \
12-
&& yum -y --downloaddir=$OTMPDIR clean all \
13-
&& rm -rf $OTMPDIR
11+
RUN yum -y --downloaddir={{tempDir}} install gzip tar unzip \
12+
&& yum -y --downloaddir={{tempDir}} clean all \
13+
&& rm -rf {{tempDir}}
1414
{{/useYum}}
1515
{{#useAptGet}}
1616
RUN apt-get -y update \
@@ -30,34 +30,31 @@ RUN zypper -nq update \
3030
{{/useZypper}}
3131

3232
## Create user and group
33-
RUN if [ -z "$(getent group {{groupid}})" ]; then hash groupadd &> /dev/null && groupadd -g 1000 {{groupid}} || exit -1 ; fi \
34-
&& if [ -z "$(getent passwd {{userid}})" ]; then hash useradd &> /dev/null && useradd -u 1100 -g {{groupid}} {{userid}} || exit -1; fi \
33+
RUN if [ -z "$(getent group {{groupid}})" ]; then hash groupadd &> /dev/null && groupadd {{groupid}} || exit -1 ; fi \
34+
&& if [ -z "$(getent passwd {{userid}})" ]; then hash useradd &> /dev/null && useradd -g {{groupid}} {{userid}} || exit -1; fi \
3535
&& mkdir /u01 \
3636
&& chown {{userid}}:{{groupid}} /u01
3737

3838
FROM OS_UPDATE as JDK_BUILD
3939
ARG JAVA_PKG
40-
ARG OTMPDIR
4140

4241
ENV JAVA_PKG=${JAVA_PKG:-server-jre-*-linux-x64.tar.gz} \
43-
JAVA_HOME={{java_home}} \
44-
OTMPDIR=${OTMPDIR:-/tmp/delme}
42+
JAVA_HOME={{java_home}}
4543

46-
COPY --chown={{userid}}:{{groupid}} $JAVA_PKG $OTMPDIR/
44+
COPY --chown={{userid}}:{{groupid}} $JAVA_PKG {{tempDir}}/
4745

4846
USER {{userid}}
4947

50-
RUN tar xzf $OTMPDIR/$JAVA_PKG -C /u01 \
48+
RUN tar xzf {{tempDir}}/$JAVA_PKG -C /u01 \
5149
&& mv /u01/jdk* {{java_home}} \
52-
&& rm -rf $OTMPDIR
50+
&& rm -rf {{tempDir}}
5351

5452
FROM OS_UPDATE as WLS_BUILD
5553
ARG WLS_PKG
5654
ARG INV_LOC
5755
ARG WLS_RESP
5856
ARG ORACLE_HOME=/u01/oracle
5957
ARG ORAINST
60-
ARG OTMPDIR
6158
ARG PATCHDIR
6259

6360
ENV WLS_PKG=${WLS_PKG:-fmw_12.2.1.3.0_wls_Disk1_1of1.zip} \
@@ -66,36 +63,35 @@ ENV WLS_PKG=${WLS_PKG:-fmw_12.2.1.3.0_wls_Disk1_1of1.zip} \
6663
INV_LOC=${INV_LOC:-/u01/oracle/oraInventory} \
6764
WLS_RESP=${WLS_RESP:-wls.rsp} \
6865
ORAINST=${ORAINST:-oraInst.loc} \
69-
OTMPDIR=${OTMPDIR:-/tmp/delme} \
7066
OPATCH_NO_FUSER=true \
7167
PATCHDIR=${PATCHDIR:-patches}
7268

7369
# Install base WLS
7470
COPY --from=JDK_BUILD --chown={{userid}}:{{groupid}} {{java_home}} {{java_home}}/
75-
COPY --chown={{userid}}:{{groupid}} $WLS_PKG $WLS_RESP $OTMPDIR/
71+
COPY --chown={{userid}}:{{groupid}} $WLS_PKG $WLS_RESP {{tempDir}}/
7672
COPY --chown={{userid}}:{{groupid}} $ORAINST $INV_LOC/
7773
{{#isOpatchPatchingEnabled}}
78-
COPY --chown=oracle:oracle p28186730_139400_Generic.zip $OTMPDIR/opatch/
74+
COPY --chown=oracle:oracle p28186730_139400_Generic.zip {{tempDir}}/opatch/
7975
{{/isOpatchPatchingEnabled}}
8076
{{#isPatchingEnabled}}
81-
COPY --chown=oracle:oracle $PATCHDIR/* $OTMPDIR/patches/
77+
COPY --chown=oracle:oracle $PATCHDIR/* {{tempDir}}/patches/
8278
{{/isPatchingEnabled}}
8379

8480
USER {{userid}}
8581

86-
RUN unzip $OTMPDIR/$WLS_PKG -d $OTMPDIR \
87-
&& {{java_home}}/bin/java -Xmx1024m -jar $OTMPDIR/fmw_*.jar -silent ORACLE_HOME=$ORACLE_HOME \
88-
-responseFile $OTMPDIR/$WLS_RESP -invPtrLoc $INV_LOC/$ORAINST -ignoreSysPrereqs -force -novalidation \
82+
RUN unzip {{tempDir}}/$WLS_PKG -d {{tempDir}} \
83+
&& {{java_home}}/bin/java -Xmx1024m -jar {{tempDir}}/fmw_*.jar -silent ORACLE_HOME=$ORACLE_HOME \
84+
-responseFile {{tempDir}}/$WLS_RESP -invPtrLoc $INV_LOC/$ORAINST -ignoreSysPrereqs -force -novalidation \
8985
{{#isOpatchPatchingEnabled}}
90-
&& cd $OTMPDIR/opatch \
91-
&& {{java_home}}/bin/jar -xf $OTMPDIR/opatch/p28186730_139400_Generic.zip \
92-
&& {{java_home}}/bin/java -jar $OTMPDIR/opatch/6880880/opatch_generic.jar -silent -ignoreSysPrereqs -force -novalidation oracle_home=$ORACLE_HOME \
86+
&& cd {{tempDir}}/opatch \
87+
&& {{java_home}}/bin/jar -xf {{tempDir}}/opatch/p28186730_139400_Generic.zip \
88+
&& {{java_home}}/bin/java -jar {{tempDir}}/opatch/6880880/opatch_generic.jar -silent -ignoreSysPrereqs -force -novalidation oracle_home=$ORACLE_HOME \
9389
{{/isOpatchPatchingEnabled}}
9490
{{#isPatchingEnabled}}
95-
&& $ORACLE_HOME/OPatch/opatch napply -silent -oh $ORACLE_HOME -phBaseDir $OTMPDIR/patches \
91+
&& $ORACLE_HOME/OPatch/opatch napply -silent -oh $ORACLE_HOME -phBaseDir {{tempDir}}/patches \
9692
&& $ORACLE_HOME/OPatch/opatch util cleanup -silent -oh $ORACLE_HOME \
9793
{{/isPatchingEnabled}}
98-
&& rm -rf {{java_home}} $OTMPDIR
94+
&& rm -rf {{java_home}} {{tempDir}}
9995

10096
{{#isWdtEnabled}}
10197
FROM OS_UPDATE as WDT_BUILD
@@ -133,7 +129,6 @@ ENV WDT_PKG=${WDT_PKG:-weblogic-deploy.zip} \
133129
PROPERTIES_FILE_DIR=$ORACLE_HOME/properties \
134130
WDT_HOME=${WDT_HOME:-/u01/app/weblogic-deploy} \
135131
SCRIPTS_DIR=${SCRIPTS_DIR:-scripts} \
136-
OTMPDIR=${OTMPDIR:-/tmp/delme} \
137132
RCU_RUN_FLAG=${RCU_RUN_FLAG:-}
138133

139134
# DO NOT COMBINE THESE BLOCKS. It won't work when formatting variables like DOMAIN_HOME
@@ -142,16 +137,16 @@ ENV DOMAIN_HOME=${DOMAIN_HOME:-/u01/domains/base_domain} \
142137

143138
COPY --from=JDK_BUILD --chown={{userid}}:{{groupid}} {{java_home}} {{java_home}}/
144139
COPY --from=WLS_BUILD --chown={{userid}}:{{groupid}} $ORACLE_HOME $ORACLE_HOME/
145-
COPY --chown={{userid}}:{{groupid}} ${WDT_PKG} ${WDT_MODEL} ${WDT_ARCHIVE} ${WDT_VARIABLE} ${OTMPDIR}/
140+
COPY --chown={{userid}}:{{groupid}} ${WDT_PKG} ${WDT_MODEL} ${WDT_ARCHIVE} ${WDT_VARIABLE} {{tempDir}}/
146141

147142
USER {{userid}}
148143

149-
RUN unzip $OTMPDIR/$WDT_PKG -d $(dirname $WDT_HOME) \
144+
RUN unzip {{tempDir}}/$WDT_PKG -d $(dirname $WDT_HOME) \
150145
&& mkdir -p $(dirname ${DOMAIN_HOME}) \
151146
&& mkdir -p ${PROPERTIES_FILE_DIR} \
152-
&& if [ -n "$WDT_MODEL" ]; then MODEL_OPT="-model_file ${OTMPDIR}/${WDT_MODEL##*/}"; fi \
153-
&& if [ -n "$WDT_ARCHIVE" ]; then ARCHIVE_OPT="-archive_file ${OTMPDIR}/${WDT_ARCHIVE##*/}"; fi \
154-
&& if [ -n "$WDT_VARIABLE" ]; then VARIABLE_OPT="-variable_file ${OTMPDIR}/${WDT_VARIABLE##*/}"; fi \
147+
&& if [ -n "$WDT_MODEL" ]; then MODEL_OPT="-model_file {{tempDir}}/${WDT_MODEL##*/}"; fi \
148+
&& if [ -n "$WDT_ARCHIVE" ]; then ARCHIVE_OPT="-archive_file {{tempDir}}/${WDT_ARCHIVE##*/}"; fi \
149+
&& if [ -n "$WDT_VARIABLE" ]; then VARIABLE_OPT="-variable_file {{tempDir}}/${WDT_VARIABLE##*/}"; fi \
155150
&& if [ -n "${RCU_RUN_FLAG}" ]; then RCU_RUN_OPT="-run_rcu"; fi \
156151
&& cd ${WDT_HOME}/bin \
157152
&& ${WDT_HOME}/bin/createDomain.sh \
@@ -163,7 +158,7 @@ RUN unzip $OTMPDIR/$WDT_PKG -d $(dirname $WDT_HOME) \
163158
$VARIABLE_OPT \
164159
$MODEL_OPT \
165160
$ARCHIVE_OPT \
166-
&& rm -rf {{java_home}} ${ORACLE_HOME} ${WDT_HOME} $OTMPDIR
161+
&& rm -rf {{java_home}} ${ORACLE_HOME} ${WDT_HOME} {{tempDir}}
167162
{{/isWdtEnabled}}
168163

169164
FROM {{baseImage}} as FINAL_BUILD
@@ -198,8 +193,8 @@ ENV DOMAIN_HOME=${DOMAIN_HOME:-/u01/domains/base_domain} \
198193
PATH=$PATH:{{java_home}}/bin:${ORACLE_HOME}/oracle_common/common/bin:${ORACLE_HOME}/wlserver/common/bin:${DOMAIN_HOME}/bin:${ORACLE_HOME}
199194

200195
## Create user and group
201-
RUN if [ -z "$(getent group {{groupid}})" ]; then hash groupadd &> /dev/null && groupadd -g 1000 {{groupid}} || exit -1 ; fi \
202-
&& if [ -z "$(getent passwd {{userid}})" ]; then hash useradd &> /dev/null && useradd -u 1100 -g {{groupid}} {{userid}} || exit -1; fi \
196+
RUN if [ -z "$(getent group {{groupid}})" ]; then hash groupadd &> /dev/null && groupadd {{groupid}} || exit -1 ; fi \
197+
&& if [ -z "$(getent passwd {{userid}})" ]; then hash useradd &> /dev/null && useradd -g {{groupid}} {{userid}} || exit -1; fi \
203198
&& mkdir -p $(dirname {{java_home}}) $(dirname $ORACLE_HOME) $(dirname $DOMAIN_HOME) \
204199
&& chown {{userid}}:{{groupid}} $(dirname {{java_home}}) $(dirname $ORACLE_HOME) $(dirname $DOMAIN_HOME)
205200

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,24 @@ FROM {{baseImage}} as OS_UPDATE
99
USER root
1010

1111
ARG PATCHDIR
12-
ARG OTMPDIR
1312

1413
ENV PATCHDIR=${PATCHDIR:-patches} \
15-
OTMPDIR=${OTMPDIR:-/tmp/delme} \
1614
OPATCH_NO_FUSER=true
1715

18-
USER oracle
16+
USER {{userid}}
1917

2018
{{#isOpatchPatchingEnabled}}
21-
COPY --chown=oracle:oracle p28186730_139400_Generic.zip $OTMPDIR/opatch/
22-
RUN cd $OTMPDIR/opatch \
23-
&& $JAVA_HOME/bin/jar -xf $OTMPDIR/opatch/p28186730_139400_Generic.zip \
24-
&& $JAVA_HOME/bin/java -jar $OTMPDIR/opatch/6880880/opatch_generic.jar -silent -ignoreSysPrereqs -force -novalidation oracle_home=$ORACLE_HOME \
25-
&& rm -rf $OTMPDIR
19+
COPY --chown={{userid}}:{{groupid}} p28186730_139400_Generic.zip {{tempDir}}/opatch/
20+
RUN cd {{tempDir}}/opatch \
21+
&& $JAVA_HOME/bin/jar -xf {{tempDir}}/opatch/p28186730_139400_Generic.zip \
22+
&& $JAVA_HOME/bin/java -jar {{tempDir}}/opatch/6880880/opatch_generic.jar -silent -ignoreSysPrereqs -force -novalidation oracle_home=$ORACLE_HOME \
23+
&& rm -rf {{tempDir}}
2624
{{/isOpatchPatchingEnabled}}
2725

2826
{{#isPatchingEnabled}}
29-
COPY --chown=oracle:oracle $PATCHDIR/* $OTMPDIR/patches/
27+
COPY --chown={{userid}}:{{groupid}} $PATCHDIR/* {{tempDir}}/patches/
3028

31-
RUN $ORACLE_HOME/OPatch/opatch napply -silent -oh $ORACLE_HOME -phBaseDir $OTMPDIR/patches \
29+
RUN $ORACLE_HOME/OPatch/opatch napply -silent -oh $ORACLE_HOME -phBaseDir {{tempDir}}/patches \
3230
&& $ORACLE_HOME/OPatch/opatch util cleanup -silent -oh $ORACLE_HOME \
33-
&& rm -rf $OTMPDIR
31+
&& rm -rf {{tempDir}}
3432
{{/isPatchingEnabled}}

0 commit comments

Comments
 (0)