Skip to content

Commit e7d3f57

Browse files
xiancaoddsharpe
authored andcommitted
Use new wlsimgcachedir (#86)
* delete entry from cache first * add cleanup * disable concurrent builds * set env in Jenkinsfile * create wlsimgblddir * use build-tag * update db container name * docker image cleanup * not expose db port
1 parent bf142e0 commit e7d3f57

File tree

3 files changed

+55
-21
lines changed

3 files changed

+55
-21
lines changed

Jenkinsfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
pipeline {
2+
options {
3+
disableConcurrentBuilds()
4+
}
25
agent any
36
tools {
47
maven 'maven-3.6.0'
58
jdk 'jdk11'
69
}
710

11+
environment {
12+
WLSIMG_BLDDIR = "${env.WORKSPACE}/imagetool/target/build"
13+
WLSIMG_CACHEDIR = "${env.WORKSPACE}/imagetool/target/cache"
14+
}
15+
816
stages {
917
stage ('Environment') {
1018
steps {

imagetool/src/test/java/com/oracle/weblogic/imagetool/integration/BaseTest.java

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class BaseTest {
2121
protected static final String BASE_OS_IMG_TAG = "7-4imagetooltest";
2222
protected static final String ORACLE_DB_IMG = "phx.ocir.io/weblogick8s/database/enterprise";
2323
protected static final String ORACLE_DB_IMG_TAG = "12.2.0.1-slim";
24-
protected static final String DB_CONTAINER_NAME = "InfraDB";
24+
protected static String dbContainerName = "";
2525
private static String projectRoot = "";
2626
protected static String wlsImgBldDir = "";
2727
protected static String wlsImgCacheDir = "";
@@ -31,6 +31,7 @@ public class BaseTest {
3131
private static final String IMAGETOOLZIPFILE = "imagetool.zip";
3232
private static final String IMAGETOOLDIR = "imagetool";
3333
private static final String INSTALLERCACHEDIR = "/scratch/artifacts/imagetool";
34+
protected static String build_tag = "";
3435

3536
protected static void initialize() throws Exception {
3637
logger.info("Initializing the tests ...");
@@ -51,6 +52,14 @@ protected static void initialize() throws Exception {
5152
imagetool = "java -cp \"" + getImagetoolHome() + FS + "lib" + FS + "*\" -Djava.util.logging.config.file=" +
5253
getImagetoolHome() + FS + "bin" + FS + "logging.properties com.oracle.weblogic.imagetool.cli.CLIDriver";
5354

55+
build_tag = System.getenv("BUILD_TAG");
56+
if(build_tag != null ) {
57+
build_tag = build_tag.toLowerCase();
58+
} else {
59+
build_tag = "imagetool";
60+
}
61+
dbContainerName = "InfraDB4" + build_tag;
62+
logger.info("DEBUG: build_tag=" + build_tag);
5463
logger.info("DEBUG: WLSIMG_BLDDIR=" + wlsImgBldDir);
5564
logger.info("DEBUG: WLSIMG_CACHEDIR=" + wlsImgCacheDir);
5665
logger.info("DEBUG: imagetool=" + imagetool);
@@ -63,11 +72,16 @@ protected static void setup() throws Exception {
6372
executeNoVerify(command);
6473

6574
// unzip the weblogic-image-tool/imagetool/target/imagetool.zip
66-
command = "unzip " + getTargetDir() + FS + IMAGETOOLZIPFILE;
75+
command = "unzip " + getTargetDir() + FS + IMAGETOOLZIPFILE + " -d " + getTargetDir();
6776
executeNoVerify(command);
6877

6978
command = "source " + getImagetoolHome() + FS + "bin" + FS + "setup.sh";
7079
executeNoVerify(command);
80+
81+
if(!(new File(wlsImgBldDir)).exists()) {
82+
logger.info(wlsImgBldDir + " does not exist, creating it");
83+
(new File(wlsImgBldDir)).mkdir();
84+
}
7185
}
7286

7387
protected static void cleanup() throws Exception {
@@ -79,12 +93,15 @@ protected static void cleanup() throws Exception {
7993
executeNoVerify(command);
8094

8195
// clean up the docker images
82-
command = "docker stop " + DB_CONTAINER_NAME;
96+
command = "docker stop " + dbContainerName;
8397
executeNoVerify(command);
8498
command = "docker rmi -f " + BASE_OS_IMG + ":" + BASE_OS_IMG_TAG + " " + ORACLE_DB_IMG + ":" +
8599
ORACLE_DB_IMG_TAG;
86100
executeNoVerify(command);
87101

102+
command = "docker rmi -f $(docker images | grep " + build_tag + " | tr -s ' ' | cut -d ' ' -f 3)";
103+
executeNoVerify(command);
104+
88105
// clean up the possible left over wlsimgbuilder_temp*
89106
command = "rm -rf " + wlsImgBldDir + FS + "wlsimgbuilder_temp*";
90107
executeNoVerify(command);
@@ -134,7 +151,7 @@ protected static String getTargetDir() {
134151

135152
protected static String getImagetoolHome() throws Exception {
136153

137-
return getProjectRoot() + FS + IMAGETOOLDIR;
154+
return getTargetDir() + FS + IMAGETOOLDIR;
138155
}
139156

140157
protected static String getInstallerCacheDir() {
@@ -165,7 +182,7 @@ protected void verifyExitValue(ExecResult result, String command) throws Excepti
165182

166183
protected void verifyDockerImages(String imageTag) throws Exception {
167184
// verify the docker image is created
168-
ExecResult result = ExecCommand.exec("docker images | grep imagetool | grep " + imageTag +
185+
ExecResult result = ExecCommand.exec("docker images | grep " + build_tag + " | grep " + imageTag +
169186
"| wc -l");
170187
if(Integer.parseInt(result.stdout().trim()) != 1) {
171188
throw new Exception("wls docker image is not created as expected");
@@ -217,15 +234,15 @@ protected ExecResult buildWDTArchive() throws Exception {
217234

218235
protected void createDBContainer() throws Exception {
219236
logger.info("Creating an Oracle db docker container ...");
220-
String command = "docker rm -f " + DB_CONTAINER_NAME;
237+
String command = "docker rm -f " + dbContainerName;
221238
ExecCommand.exec(command);
222-
command = "docker run -d --name " + DB_CONTAINER_NAME + " -p 1521:1521 -p 5500:5500 --env=\"DB_PDB=InfraPDB1\"" +
239+
command = "docker run -d --name " + dbContainerName + " --env=\"DB_PDB=InfraPDB1\"" +
223240
" --env=\"DB_DOMAIN=us.oracle.com\" --env=\"DB_BUNDLE=basic\" " + ORACLE_DB_IMG + ":" +
224241
ORACLE_DB_IMG_TAG;
225242
ExecCommand.exec(command);
226243

227244
// wait for the db is ready
228-
command = "docker ps | grep " + DB_CONTAINER_NAME;
245+
command = "docker ps | grep " + dbContainerName;
229246
checkCmdInLoop(command, "healthy");
230247
}
231248

imagetool/src/test/java/com/oracle/weblogic/imagetool/integration/ITImagetool.java

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class ITImagetool extends BaseTest {
4949
@BeforeClass
5050
public static void staticPrepare() throws Exception {
5151
logger.info("prepare for image tool test ...");
52-
52+
// initialize
5353
initialize();
5454
// clean up the env first
5555
cleanup();
@@ -107,6 +107,7 @@ public void test2CacheAddInstallerJDK() throws Exception {
107107
logTestBegin(testMethodName);
108108

109109
String jdkPath = getInstallerCacheDir() + FS + JDK_INSTALLER;
110+
deleteEntryFromCache("jdk_" + JDK_VERSION);
110111
addInstallerToCache("jdk", JDK_VERSION, jdkPath);
111112

112113
ExecResult result = listItemsInCache();
@@ -126,6 +127,7 @@ public void test3CacheAddInstallerWLS() throws Exception {
126127
logTestBegin(testMethodName);
127128

128129
String wlsPath = getInstallerCacheDir() + FS + WLS_INSTALLER;
130+
deleteEntryFromCache("wls_" + WLS_VERSION);
129131
addInstallerToCache("wls", WLS_VERSION, wlsPath);
130132

131133
ExecResult result = listItemsInCache();
@@ -144,9 +146,12 @@ public void test4CreateWLSImg() throws Exception {
144146
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
145147
logTestBegin(testMethodName);
146148

147-
String command = imagetool + " create --jdkVersion=" + JDK_VERSION + " --tag imagetool:" + testMethodName;
149+
String command = imagetool + " create --jdkVersion=" + JDK_VERSION + " --tag " +
150+
build_tag + ":" + testMethodName;
148151
logger.info("Executing command: " + command);
149-
ExecCommand.exec(command, true);
152+
ExecResult result = ExecCommand.exec(command);
153+
logger.info("DEBUG: result.stdout=" + result.stdout());
154+
logger.info("DEBUG: result.stderr=" + result.stderr());
150155

151156
// verify the docker image is created
152157
verifyDockerImages(testMethodName);
@@ -227,10 +232,11 @@ public void test8CreateWLSImgUseCache() throws Exception {
227232

228233
// need to add the required patches 28186730 for Opatch before create wls images
229234
String patchPath = getInstallerCacheDir() + FS + P28186730_INSTALLER;
235+
deleteEntryFromCache(P28186730_ID + "_opatch");
230236
addPatchToCache("wls", P28186730_ID, OPATCH_VERSION, patchPath);
231237

232238
String command = imagetool + " create --jdkVersion " + JDK_VERSION + " --fromImage " +
233-
BASE_OS_IMG + ":" + BASE_OS_IMG_TAG + " --tag imagetool:" + testMethodName +
239+
BASE_OS_IMG + ":" + BASE_OS_IMG_TAG + " --tag " + build_tag + ":" + testMethodName +
234240
" --version " + WLS_VERSION;
235241
logger.info("Executing command: " + command);
236242
ExecCommand.exec(command, true);
@@ -250,8 +256,8 @@ public void test9UpdateWLSImg() throws Exception {
250256
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
251257
logTestBegin(testMethodName);
252258

253-
String command = imagetool + " update --fromImage imagetool:test8CreateWLSImgUseCache --tag imagetool:" +
254-
testMethodName + " --patches " + P27342434_ID;
259+
String command = imagetool + " update --fromImage imagetool:test8CreateWLSImgUseCache --tag " +
260+
build_tag + ":" + testMethodName + " --patches " + P27342434_ID;
255261
logger.info("Executing command: " + command);
256262
ExecCommand.exec(command, true);
257263

@@ -307,7 +313,7 @@ public void testACreateWLSImgUsingWDT() throws Exception {
307313
String wdtModel = getWDTResourcePath() + FS + WDT_MODEL;
308314
String wdtVariables = getWDTResourcePath() + FS + WDT_VARIABLES;
309315
String command = imagetool + " create --fromImage " +
310-
BASE_OS_IMG + ":" + BASE_OS_IMG_TAG + " --tag imagetool:" + testMethodName +
316+
BASE_OS_IMG + ":" + BASE_OS_IMG_TAG + " --tag " + build_tag + ":" + testMethodName +
311317
" --version " + WLS_VERSION + " --patches " + P27342434_ID + " --wdtVersion " + WDT_VERSION +
312318
" --wdtArchive " + wdtArchive + " --wdtDomainHome /u01/domains/simple_domain --wdtModel " +
313319
wdtModel + " --wdtVariables " + wdtVariables;
@@ -343,7 +349,7 @@ public void testBCreateFMWImgFullInternetAccess() throws Exception {
343349
String jdkPath = getInstallerCacheDir() + FS + JDK_INSTALLER;
344350
addInstallerToCache("jdk", JDK_VERSION, jdkPath);
345351

346-
String command = imagetool + " create --version=" + WLS_VERSION + " --tag imagetool:" + testMethodName +
352+
String command = imagetool + " create --version=" + WLS_VERSION + " --tag " + build_tag + ":" + testMethodName +
347353
" --latestPSU --user " + oracleSupportUsername + " --passwordEnv ORACLE_SUPPORT_PASSWORD --type fmw";
348354
logger.info("Executing command: " + command);
349355
ExecCommand.exec(command, true);
@@ -365,18 +371,21 @@ public void testCCreateFMWImgNonDefault() throws Exception {
365371

366372
// add fmw installer to the cache
367373
String fmwPath = getInstallerCacheDir() + FS + FMW_INSTALLER_1221;
374+
deleteEntryFromCache("fmw_" + WLS_VERSION_1221);
368375
addInstallerToCache("fmw", WLS_VERSION_1221, fmwPath);
369376

370377
// add jdk installer to the cache
371378
String jdkPath = getInstallerCacheDir() + FS + JDK_INSTALLER_8u212;
379+
deleteEntryFromCache("jdk_" + JDK_VERSION_8u212);
372380
addInstallerToCache("jdk", JDK_VERSION_8u212, jdkPath);
373381

374382
// add the patch to the cache
375383
String patchPath = getInstallerCacheDir() + FS + P22987840_INSTALLER;
384+
deleteEntryFromCache(P22987840_ID + "_" + WLS_VERSION_1221);
376385
addPatchToCache("fmw", P22987840_ID, WLS_VERSION_1221, patchPath);
377386

378387
String command = imagetool + " create --jdkVersion " + JDK_VERSION_8u212 + " --version=" + WLS_VERSION_1221 +
379-
" --tag imagetool:" + testMethodName + " --patches " + P22987840_ID + " --type fmw";
388+
" --tag " + build_tag + ":" + testMethodName + " --patches " + P22987840_ID + " --type fmw";
380389
logger.info("Executing command: " + command);
381390
ExecCommand.exec(command, true);
382391

@@ -429,13 +438,13 @@ public void testDCreateJRFDomainImgUsingWDT() throws Exception {
429438
Path dest = Paths.get(tmpWdtModel);
430439
Files.copy(source, dest, StandardCopyOption.REPLACE_EXISTING);
431440
String getDBContainerIP = "docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' " +
432-
DB_CONTAINER_NAME;
441+
dbContainerName;
433442
String host = ExecCommand.exec(getDBContainerIP).stdout().trim();
434443
logger.info("DEBUG: DB_HOST=" + host);
435444
replaceStringInFile(tmpWdtModel, "%DB_HOST%", host);
436445

437446
String command = imagetool + " create --fromImage " +
438-
BASE_OS_IMG + ":" + BASE_OS_IMG_TAG + " --tag imagetool:" + testMethodName +
447+
BASE_OS_IMG + ":" + BASE_OS_IMG_TAG + " --tag " + build_tag + ":" + testMethodName +
439448
" --version " + WLS_VERSION + " --wdtVersion " + WDT_VERSION +
440449
" --wdtArchive " + wdtArchive + " --wdtDomainHome /u01/domains/simple_domain --wdtModel " +
441450
tmpWdtModel + " --wdtDomainType JRF --wdtRunRCU --type fmw";
@@ -483,7 +492,7 @@ public void testECreateRestricedJRFDomainImgUsingWDT() throws Exception {
483492
String wdtModel = getWDTResourcePath() + FS + WDT_MODEL;
484493
String wdtVariables = getWDTResourcePath() + FS + WDT_VARIABLES;
485494
String command = imagetool + " create --fromImage " +
486-
BASE_OS_IMG + ":" + BASE_OS_IMG_TAG + " --tag imagetool:" + testMethodName +
495+
BASE_OS_IMG + ":" + BASE_OS_IMG_TAG + " --tag " + build_tag + ":" + testMethodName +
487496
" --version " + WLS_VERSION + " --latestPSU --user " + oracleSupportUsername +
488497
" --password " + oracleSupportPassword + " --wdtVersion " + WDT_VERSION +
489498
" --wdtArchive " + wdtArchive + " --wdtDomainHome /u01/domains/simple_domain --wdtModel " +
@@ -535,7 +544,7 @@ public void testFCreateWLSImgUsingMultiModels() throws Exception {
535544
String wdtModel2 = getWDTResourcePath() + FS + WDT_MODEL2;
536545
String wdtVariables = getWDTResourcePath() + FS + WDT_VARIABLES;
537546
String command = imagetool + " create --fromImage " +
538-
BASE_OS_IMG + ":" + BASE_OS_IMG_TAG + " --tag imagetool:" + testMethodName +
547+
BASE_OS_IMG + ":" + BASE_OS_IMG_TAG + " --tag " + build_tag + ":" + testMethodName +
539548
" --version " + WLS_VERSION + " --wdtVersion " + WDT_VERSION +
540549
" --wdtArchive " + wdtArchive + " --wdtDomainHome /u01/domains/simple_domain --wdtModel " +
541550
wdtModel + "," + wdtModel2 + " --wdtVariables " + wdtVariables;

0 commit comments

Comments
 (0)