Skip to content

Commit 14491dd

Browse files
committed
fix JAVA_HOME issue in UpdateImage where JAVA_HOME is not default value
1 parent 015e9a3 commit 14491dd

File tree

3 files changed

+292
-0
lines changed

3 files changed

+292
-0
lines changed

Jenkinsfile

Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ pipeline {
5656
}
5757
}
5858
steps {
59+
step {
60+
sh '''
61+
oci os object get -ns weblogick8s -bn wko-system-test-files --config-file=/dev/null --auth=instance_principal --file ./imagetool.zip --name imagetool-master.zip
62+
'''
63+
}
5964
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'otn-cred', passwordVariable: 'ORACLE_SUPPORT_PASSWORD', usernameVariable: 'ORACLE_SUPPORT_USERNAME']]) {
6065
sh '''
6166
cd tests
@@ -113,4 +118,233 @@ pipeline {
113118
}
114119
}
115120
}
121+
}
122+
123+
124+
def filesDownloaded = 0
125+
def downloadThem() {
126+
if (filesDownloaded == 0) {
127+
echo 'Should download now'
128+
filesDownloaded = 1
129+
} else {
130+
echo 'Files already downloaded, nothing to do'
131+
}
132+
echo 'function complete'
133+
}
134+
135+
pipeline {
136+
options {
137+
disableConcurrentBuilds()
138+
}
139+
agent any
140+
tools {
141+
maven 'maven-3.6.0'
142+
jdk 'jdk8'
143+
}
144+
145+
triggers {
146+
// timer trigger for "nightly build" on master branch
147+
cron( env.BRANCH_NAME.equals('master') ? 'H H(0-3) * * 1-5' : '')
148+
}
149+
150+
environment {
151+
// variables for SystemTest stages (integration tests)
152+
STAGING_DIR = "/scratch/artifacts/imagetool"
153+
DB_IMAGE = "phx.ocir.io/weblogick8s/database/enterprise:12.2.0.1-slim"
154+
}
155+
156+
stages {
157+
stage ('Environment') {
158+
steps {
159+
sh '''
160+
echo "PATH = ${PATH}"
161+
echo "M2_HOME = ${M2_HOME}"
162+
mvn --version
163+
'''
164+
}
165+
}
166+
stage ('Build') {
167+
steps {
168+
sh 'mvn -B -DskipTests -DskipITs clean install'
169+
}
170+
}
171+
stage ('Test') {
172+
when {
173+
not { changelog '\\[skip-ci\\].*' }
174+
}
175+
steps {
176+
sh 'mvn test'
177+
}
178+
post {
179+
always {
180+
junit 'imagetool/target/surefire-reports/*.xml'
181+
}
182+
}
183+
}
184+
stage ('SystemTest Gate') {
185+
steps {
186+
script {
187+
downloadThem()
188+
}
189+
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'otn-cred', passwordVariable: 'ORACLE_SUPPORT_PASSWORD', usernameVariable: 'ORACLE_SUPPORT_USERNAME']]) {
190+
sh '''
191+
cd tests
192+
mvn clean -Dtest.staging.dir=${STAGING_DIR} -Dtest.groups=gate
193+
'''
194+
}
195+
}
196+
post {
197+
always {
198+
junit 'tests/target/failsafe-reports/*.xml'
199+
}
200+
}
201+
}
202+
stage ('SystemTest Full') {
203+
steps {
204+
script {
205+
downloadThem()
206+
docker.image("${env.DB_IMAGE}").pull()
207+
}
208+
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'otn-cred', passwordVariable: 'ORACLE_SUPPORT_PASSWORD', usernameVariable: 'ORACLE_SUPPORT_USERNAME']]) {
209+
sh '''
210+
cd tests
211+
mvn clean -Dtest.staging.dir=${STAGING_DIR} -Dtest.groups=gate,nightly
212+
'''
213+
}
214+
}
215+
post {
216+
always {
217+
junit 'tests/target/failsafe-reports/*.xml'
218+
}
219+
failure {
220+
mail to: "${env.WIT_BUILD_NOTIFICATION_EMAIL_TO}", from: '[email protected]',
221+
subject: "WebLogic Image Tool: ${env.JOB_NAME} - Failed",
222+
body: "Job Failed - \"${env.JOB_NAME}\" build: ${env.BUILD_NUMBER}\n\nView the log at:\n ${env.BUILD_URL}\n"
223+
}
224+
}
225+
}
226+
stage ('Save Nightly Installer'){
227+
when {
228+
allOf {
229+
triggeredBy 'TimerTrigger'
230+
branch "master"
231+
}
232+
}
233+
steps {
234+
sh '''
235+
oci os object put --namespace=weblogick8s --bucket-name=wko-system-test-files --config-file=/dev/null --auth=instance_principal --force --file=installer/target/imagetool.zip --name=imagetool-master.zip
236+
'''
237+
}
238+
}
239+
}
240+
}
241+
242+
def downloadThem() {
243+
if (filesDownloaded == 0) {
244+
echo 'Should download now'
245+
filesDownloaded = 1
246+
} else {
247+
echo 'Files already downloaded, nothing to do'
248+
}
249+
echo 'function complete'
250+
}
251+
252+
pipeline {
253+
options {
254+
disableConcurrentBuilds()
255+
}
256+
agent any
257+
tools {
258+
maven 'maven-3.6.0'
259+
jdk 'jdk8'
260+
}
261+
262+
triggers {
263+
// timer trigger for "nightly build" on master branch
264+
cron( env.BRANCH_NAME.equals('master') ? 'H H(0-3) * * 1-5' : '')
265+
}
266+
267+
environment {
268+
// variables for SystemTest stages (integration tests)
269+
STAGING_DIR = "/scratch/artifacts/imagetool"
270+
DB_IMAGE = "phx.ocir.io/weblogick8s/database/enterprise:12.2.0.1-slim"
271+
filesDownloaded = 0
272+
}
273+
274+
stages {
275+
stage ('Environment') {
276+
steps {
277+
sh '''
278+
echo "PATH = ${PATH}"
279+
echo "M2_HOME = ${M2_HOME}"
280+
mvn --version
281+
'''
282+
}
283+
}
284+
stage ('Build') {
285+
steps {
286+
sh 'mvn -B -DskipTests -DskipITs clean install'
287+
}
288+
}
289+
stage ('Test') {
290+
when {
291+
not { changelog '\\[skip-ci\\].*' }
292+
}
293+
steps {
294+
sh 'mvn test'
295+
}
296+
post {
297+
always {
298+
junit 'imagetool/target/surefire-reports/*.xml'
299+
}
300+
}
301+
}
302+
stage ('SystemTest Gate') {
303+
steps {
304+
script {
305+
downloadThem()
306+
}
307+
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'otn-cred', passwordVariable: 'ORACLE_SUPPORT_PASSWORD', usernameVariable: 'ORACLE_SUPPORT_USERNAME']]) {
308+
sh '''
309+
cd tests
310+
mvn clean -Dtest.staging.dir=${STAGING_DIR} -Dtest.groups=gate
311+
'''
312+
}
313+
}
314+
}
315+
stage ('SystemTest Full') {
316+
steps {
317+
script {
318+
downloadThem()
319+
docker.image("${env.DB_IMAGE}").pull()
320+
}
321+
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'otn-cred', passwordVariable: 'ORACLE_SUPPORT_PASSWORD', usernameVariable: 'ORACLE_SUPPORT_USERNAME']]) {
322+
sh '''
323+
cd tests
324+
mvn clean -Dtest.staging.dir=${STAGING_DIR} -Dtest.groups=gate,nightly
325+
'''
326+
}
327+
}
328+
post {
329+
failure {
330+
mail to: "${env.WIT_BUILD_NOTIFICATION_EMAIL_TO}", from: '[email protected]',
331+
subject: "WebLogic Image Tool: ${env.JOB_NAME} - Failed",
332+
body: "Job Failed - \"${env.JOB_NAME}\" build: ${env.BUILD_NUMBER}\n\nView the log at:\n ${env.BUILD_URL}\n"
333+
}
334+
}
335+
}
336+
stage ('Save Nightly Installer'){
337+
when {
338+
allOf {
339+
triggeredBy 'TimerTrigger'
340+
branch "master"
341+
}
342+
}
343+
steps {
344+
sh '''
345+
oci os object put --namespace=weblogick8s --bucket-name=wko-system-test-files --config-file=/dev/null --auth=instance_principal --force --file=installer/target/imagetool.zip --name=imagetool-master.zip
346+
'''
347+
}
348+
}
349+
}
116350
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ public CommandResponse call() throws Exception {
6262

6363
Properties baseImageProperties = Utils.getBaseImageProperties(fromImage, tmpDir);
6464

65+
dockerfileOptions.setJavaHome(baseImageProperties.getProperty("JAVA_HOME", null));
66+
6567
String oracleHome = baseImageProperties.getProperty("ORACLE_HOME", null);
6668
if (oracleHome == null) {
6769
return new CommandResponse(-1, "IMG-0072", fromImage);

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

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ static void staticUnprepare() throws Exception {
243243

244244
/**
245245
* Create the log directory in ./target (build folder), and open a new file using the test method's name.
246+
*
246247
* @param testInfo metadata from the test to be logged
247248
* @return an output file wrapped in a PrintWriter
248249
* @throws IOException if the PrintWriter fails to open the file
@@ -881,4 +882,59 @@ void createWlsImgWithAdditionalBuildCommands(TestInfo testInfo) throws Exception
881882
assertTrue(inspect.stdout().contains("final-build-commands:finalBuildCommands"),
882883
tagName + " does not contain the expected label");
883884
}
885+
886+
/**
887+
* Create a WLS image using Java Server JRE image as a base.
888+
* This tests that the JAVA_HOME is correctly identified and applied in the CREATE.
889+
*
890+
* @throws Exception - if any error occurs
891+
*/
892+
@Test
893+
@Order(26)
894+
@Tag("nightly")
895+
@DisplayName("Create image with WLS using Java ServerJRE")
896+
void createImageWithServerJRE(TestInfo testInfo) throws Exception {
897+
String tagName = build_tag + ":" + getMethodName(testInfo);
898+
String command = new CreateCommand()
899+
.tag(tagName)
900+
.fromImage("store/oracle/serverjre:8")
901+
.build();
902+
903+
try (PrintWriter out = getTestMethodWriter(testInfo)) {
904+
CommandResult result = Runner.run(command, out, logger);
905+
assertEquals(0, result.exitValue(), "for command: " + command);
906+
907+
// verify the docker image is created
908+
String imageId = Runner.run("docker images -q " + tagName, out, logger).stdout().trim();
909+
assertFalse(imageId.isEmpty(), "Image was not created: " + tagName);
910+
}
911+
}
912+
913+
/**
914+
* Update the WLS image created in the previous test.
915+
* This tests that the JAVA_HOME is correctly identified and applied in the UPDATE.
916+
*
917+
* @throws Exception - if any error occurs
918+
*/
919+
@Test
920+
@Order(27)
921+
@Tag("nightly")
922+
@DisplayName("Update image with WLS using Java ServerJRE")
923+
void updateImageWithServerJRE(TestInfo testInfo) throws Exception {
924+
String tagName = build_tag + ":" + getMethodName(testInfo);
925+
String command = new UpdateCommand()
926+
.fromImage(build_tag + ":createImageWithServerJRE")
927+
.tag(tagName)
928+
.patches(P27342434_ID)
929+
.build();
930+
931+
try (PrintWriter out = getTestMethodWriter(testInfo)) {
932+
CommandResult result = Runner.run(command, out, logger);
933+
assertEquals(0, result.exitValue(), "for command: " + command);
934+
935+
// verify the docker image is created
936+
String imageId = Runner.run("docker images -q " + tagName, out, logger).stdout().trim();
937+
assertFalse(imageId.isEmpty(), "Image was not created: " + tagName);
938+
}
939+
}
884940
}

0 commit comments

Comments
 (0)