Skip to content

Fix regression with UPDATE where WDT install could not be overwritten #294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ ENV ORACLE_HOME={{{oracle_home}}} \
{{/installJava}}
{{#isWdtEnabled}}
DOMAIN_HOME={{{domain_home}}} \
WDT_HOME={{{wdt_home}}} \
{{#modelOnly}}
WDT_MODEL_HOME={{{wdt_model_home}}} \
{{/modelOnly}}
{{/isWdtEnabled}}
PATH=${PATH}:{{{java_home}}}/bin:{{{oracle_home}}}/oracle_common/common/bin:{{{oracle_home}}}/wlserver/common/bin:{{{oracle_home}}}{{#isWdtEnabled}}:{{{domain_home}}}/bin{{/isWdtEnabled}}
PATH=${PATH}:{{{java_home}}}/bin:{{{oracle_home}}}/oracle_common/common/bin:{{{oracle_home}}}/wlserver/common/bin:{{{oracle_home}}}{{#isWdtEnabled}}:{{{domain_home}}}/bin
{{/isWdtEnabled}}

LABEL com.oracle.weblogic.imagetool.buildid="{{buildId}}"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ USER root
ENV OPATCH_NO_FUSER=true

{{#isWdtEnabled}}
ENV DOMAIN_HOME={{{domain_home}}} \
ENV DOMAIN_HOME={{{domain_home}}} \
WDT_HOME={{{wdt_home}}} \
{{#modelOnly}}
WDT_MODEL_HOME={{{wdt_model_home}}} \
{{/modelOnly}}
Expand Down
5 changes: 3 additions & 2 deletions imagetool/src/main/resources/docker-files/run-wdt.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ RUN cd {{{wdt_home}}} \
{{{.}}}
{{/beforeWdtCommand}}

RUN test -d {{{wdt_home}}}/weblogic-deploy && rm -rf {{{wdt_home}}}/weblogic-deploy || echo Initial WDT install \
{{#usingWdtTarGzInstaller}}
RUN tar zxf {{{tempDir}}}/{{{wdtInstaller}}} -C {{{wdt_home}}}
&& tar zxf {{{tempDir}}}/{{{wdtInstaller}}} -C {{{wdt_home}}}
{{/usingWdtTarGzInstaller}}
{{^usingWdtTarGzInstaller}}
RUN unzip -q {{{tempDir}}}/{{{wdtInstaller}}} -d {{{wdt_home}}}
&& unzip -q {{{tempDir}}}/{{{wdtInstaller}}} -d {{{wdt_home}}}
{{/usingWdtTarGzInstaller}}

{{^modelOnly}}
Expand Down
7 changes: 7 additions & 0 deletions imagetool/src/main/resources/probe-env/inspect-image-long.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ if [ -n "$WDT_MODEL_HOME" ]; then
echo wdtModelHome="$WDT_MODEL_HOME"
fi

if [ -n "$WDT_HOME" ]; then
echo wdtHome="$WDT_HOME"
echo wdtVersion="$(cat $WDT_HOME/weblogic-deploy/VERSION.txt | sed 's/.* //')"
elif [ -f "/u01/wdt/weblogic-deploy/VERSION.txt" ]; then
echo wdtHome="/u01/wdt"
echo wdtVersion="$(cat /u01/wdt/weblogic-deploy/VERSION.txt | sed 's/.* //')"
fi

if [ -n "$ORACLE_HOME" ]; then
echo oracleHome="$ORACLE_HOME"
Expand Down
7 changes: 7 additions & 0 deletions imagetool/src/main/resources/probe-env/inspect-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ if [ -n "$WDT_MODEL_HOME" ]; then
echo wdtModelHome="$WDT_MODEL_HOME"
fi

if [ -n "$WDT_HOME" ]; then
echo wdtHome="$WDT_HOME"
echo wdtVersion="$(cat $WDT_HOME/weblogic-deploy/VERSION.txt | sed 's/.* //')"
elif [ -f "/u01/wdt/weblogic-deploy/VERSION.txt" ]; then
echo wdtHome="/u01/wdt"
echo wdtVersion="$(cat /u01/wdt/weblogic-deploy/VERSION.txt | sed 's/.* //')"
fi

if [ -n "$ORACLE_HOME" ]; then
echo oracleHome="$ORACLE_HOME"
Expand Down
133 changes: 101 additions & 32 deletions tests/src/test/java/com/oracle/weblogic/imagetool/tests/ITImagetool.java
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,28 @@ private static String getMethodName(TestInfo testInfo) {

}

private static CommandResult executeAndVerify(String command) throws Exception {
logger.info("Executing command: " + command);
CommandResult result = Runner.run(command);
assertEquals(0, result.exitValue(), "for command: " + command);
logger.info(result.stdout());
return result;
}

/**
* Determine if a Docker image exists on the local system.
*/
private static boolean imageExists(String imageTag) throws IOException, InterruptedException {
return !getImageId(imageTag).isEmpty();
}

/**
* Get the docker identifier for this image tag.
*/
private static String getImageId(String imageTag) throws IOException, InterruptedException {
return Runner.run("docker images -q " + imageTag).stdout().trim();
}

private void verifyFileInImage(String imagename, String filename, String expectedContent) throws Exception {
logger.info("verifying the file content in image");
String command = "docker run --rm " + imagename + " bash -c 'cat " + filename + "'";
Expand All @@ -289,14 +311,6 @@ private void createDBContainer() throws Exception {
checkCmdInLoop(command);
}

private static CommandResult executeAndVerify(String command) throws Exception {
logger.info("Executing command: " + command);
CommandResult result = Runner.run(command);
assertEquals(0, result.exitValue(), "for command: " + command);
logger.info(result.stdout());
return result;
}

/**
* Test caching of an installer of type JDK.
*
Expand Down Expand Up @@ -538,8 +552,8 @@ void createWlsImg(TestInfo testInfo) throws Exception {
assertEquals(0, result.exitValue(), "for command: " + command);

// verify the docker image is created
String imageId = Runner.run("docker images -q " + tagName, out, logger).stdout().trim();
assertFalse(imageId.isEmpty(), "Image was not created: " + tagName);
assertTrue(imageExists(tagName), "Image was not created: " + tagName);

wlsImgBuilt = true;
}
}
Expand Down Expand Up @@ -568,8 +582,8 @@ void updateWlsImg(TestInfo testInfo) throws Exception {
assertEquals(0, result.exitValue(), "for command: " + command);

// verify the docker image is created
String imageId = Runner.run("docker images -q " + tagName, out, logger).stdout().trim();
assertFalse(imageId.isEmpty(), "Image was not created: " + tagName);
assertTrue(imageExists(tagName), "Image was not created: " + tagName);

// TODO should check that patch and OPatch were applied
}
}
Expand Down Expand Up @@ -603,8 +617,8 @@ void createWlsImgUsingWdt(TestInfo testInfo) throws Exception {
assertEquals(0, result.exitValue(), "for command: " + command);

// verify the docker image is created
String imageId = Runner.run("docker images -q " + tagName, out, logger).stdout().trim();
assertFalse(imageId.isEmpty(), "Image was not created: " + tagName);
assertTrue(imageExists(tagName), "Image was not created: " + tagName);

domainImgBuilt = true;
}
}
Expand Down Expand Up @@ -633,8 +647,7 @@ void rebaseWlsImg(TestInfo testInfo) throws Exception {
assertEquals(0, result.exitValue(), "for command: " + command);

// verify the docker image is created
String imageId = Runner.run("docker images -q " + tagName, out, logger).stdout().trim();
assertFalse(imageId.isEmpty(), "Image was not created: " + tagName);
assertTrue(imageExists(tagName), "Image was not created: " + tagName);
}
}

Expand Down Expand Up @@ -688,8 +701,7 @@ void createFmwImgFullInternetAccess(TestInfo testInfo) throws Exception {
assertEquals(0, result.exitValue(), "for command: " + command);

// verify the docker image is created
String imageId = Runner.run("docker images -q " + tagName, out, logger).stdout().trim();
assertFalse(imageId.isEmpty(), "Image was not created: " + tagName);
assertTrue(imageExists(tagName), "Image was not created: " + tagName);
}
}

Expand Down Expand Up @@ -744,8 +756,7 @@ void createJrfDomainImgUsingWdt(TestInfo testInfo) throws Exception {
assertEquals(0, result.exitValue(), "for command: " + command);

// verify the docker image is created
String imageId = Runner.run("docker images -q " + tagName, out, logger).stdout().trim();
assertFalse(imageId.isEmpty(), "Image was not created: " + tagName);
assertTrue(imageExists(tagName), "Image was not created: " + tagName);
}
}

Expand Down Expand Up @@ -784,8 +795,7 @@ void createRestrictedJrfDomainImgUsingWdt(TestInfo testInfo) throws Exception {
assertEquals(0, result.exitValue(), "for command: " + command);

// verify the docker image is created
String imageId = Runner.run("docker images -q " + tagName, out, logger).stdout().trim();
assertFalse(imageId.isEmpty(), "Image was not created: " + tagName);
assertTrue(imageExists(tagName), "Image was not created: " + tagName);
}
}

Expand Down Expand Up @@ -821,8 +831,7 @@ void createWlsImgUsingMultiModels(TestInfo testInfo) throws Exception {
assertEquals(0, result.exitValue(), "for command: " + command);

// verify the docker image is created
String imageId = Runner.run("docker images -q " + tagName, out, logger).stdout().trim();
assertFalse(imageId.isEmpty(), "Image was not created: " + tagName);
assertTrue(imageExists(tagName), "Image was not created: " + tagName);
}
}

Expand Down Expand Up @@ -851,8 +860,7 @@ void createWlsImgWithAdditionalBuildCommands(TestInfo testInfo) throws Exception
assertEquals(0, result.exitValue(), "for command: " + command);

// verify the docker image is created
String imageId = Runner.run("docker images -q " + tagName, out, logger).stdout().trim();
assertFalse(imageId.isEmpty(), "Image was not created: " + tagName);
assertTrue(imageExists(tagName), "Image was not created: " + tagName);
}

// verify the file created in [before-jdk-install] section
Expand Down Expand Up @@ -891,8 +899,7 @@ void createImageWithServerJRE(TestInfo testInfo) throws Exception {
assertEquals(0, result.exitValue(), "for command: " + command);

// verify the docker image is created
String imageId = Runner.run("docker images -q " + tagName, out, logger).stdout().trim();
assertFalse(imageId.isEmpty(), "Image was not created: " + tagName);
assertTrue(imageExists(tagName), "Image was not created: " + tagName);
}
}

Expand All @@ -919,8 +926,7 @@ void updateImageWithServerJRE(TestInfo testInfo) throws Exception {
assertEquals(0, result.exitValue(), "for command: " + command);

// verify the docker image is created
String imageId = Runner.run("docker images -q " + tagName, out, logger).stdout().trim();
assertFalse(imageId.isEmpty(), "Image was not created: " + tagName);
assertTrue(imageExists(tagName), "Image was not created: " + tagName);
}
}

Expand Down Expand Up @@ -962,8 +968,7 @@ void createMiiOl8slim(TestInfo testInfo) throws Exception {
assertEquals(0, result.exitValue(), "for command: " + command);

// verify the docker image is created
String imageId = Runner.run("docker images -q " + tagName, out, logger).stdout().trim();
assertFalse(imageId.isEmpty(), "Image was not created: " + tagName);
assertTrue(imageExists(tagName), "Image was not created: " + tagName);

validateDirectoryPermissions("/u01/domains", "drwxrwxr-x", tagName, out);
validateDirectoryPermissions("/u01/wdt", "drwxrwxr-x", tagName, out);
Expand Down Expand Up @@ -991,4 +996,68 @@ private void validateDirectoryPermissions(String directory, String expected, Str
// When running on an SELinux host, the permissions shown by ls will end with a "."
assertTrue(tokens[0].startsWith(expected), "Incorrect directory permissions for " + directory);
}

/**
* update a WLS image with a model.
*
* @throws Exception - if any error occurs
*/
@Test
@Order(28)
@Tag("nightly")
@DisplayName("Use Update to add a WDT model to createWlsImg")
void updateAddModel(TestInfo testInfo) throws Exception {
assumeTrue(wlsImgBuilt);

String tagName = build_tag + ":" + getMethodName(testInfo);
String command = new UpdateCommand()
.fromImage(build_tag + ":createWlsImg") //from step 10, createWlsImg()
.tag(tagName)
.wdtVersion(WDT_VERSION)
.wdtModel(WDT_MODEL)
.wdtVariables(WDT_VARIABLES)
.wdtArchive(WDT_ARCHIVE)
.wdtModelOnly(true)
.build();

try (PrintWriter out = getTestMethodWriter(testInfo)) {
CommandResult result = Runner.run(command, out, logger);
assertEquals(0, result.exitValue(), "for command: " + command);

// verify the docker image is created
assertTrue(imageExists(tagName), "Image was not created: " + tagName);
}
}

/**
* update a WLS image with another model.
*
* @throws Exception - if any error occurs
*/
@Test
@Order(29)
@Tag("nightly")
@DisplayName("Use Update to add a second WDT model to createWlsImg")
void updateAddSecondModel(TestInfo testInfo) throws Exception {
String testFromImage = build_tag + ":updateAddModel";
// skip this test if updateAddModel() failed to create an image
assumeTrue(imageExists(testFromImage));

String tagName = build_tag + ":" + getMethodName(testInfo);
String command = new UpdateCommand()
.fromImage(testFromImage)
.tag(tagName)
.wdtVersion(WDT_VERSION)
.wdtModel(WDT_MODEL2)
.wdtModelOnly(true)
.build();

try (PrintWriter out = getTestMethodWriter(testInfo)) {
CommandResult result = Runner.run(command, out, logger);
assertEquals(0, result.exitValue(), "for command: " + command);

// verify the docker image is created
assertTrue(imageExists(tagName), "Image was not created: " + tagName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,23 @@

package com.oracle.weblogic.imagetool.tests.utils;

import java.nio.file.Path;
import java.util.Arrays;
import java.util.stream.Collectors;

public class UpdateCommand extends ImageToolCommand {

private String fromImage;
private String tag;
private String patches;

// WDT flags
private String wdtVersion;
private String wdtModel;
private String wdtArchive;
private String wdtVariables;
private boolean wdtModelOnly;

public UpdateCommand() {
super("update");
}
Expand All @@ -23,15 +34,36 @@ public UpdateCommand tag(String value) {
return this;
}

public UpdateCommand tag(String name, String version) {
return tag(name + ":" + version);
}

public UpdateCommand patches(String... values) {
patches = String.join(",", values);
return this;
}

public UpdateCommand wdtVersion(String value) {
wdtVersion = value;
return this;
}

public UpdateCommand wdtModel(Path... values) {
wdtModel = Arrays.stream(values).map(Path::toString).collect(Collectors.joining(","));
return this;
}

public UpdateCommand wdtArchive(Path value) {
wdtArchive = value.toString();
return this;
}

public UpdateCommand wdtVariables(Path value) {
wdtVariables = value.toString();
return this;
}

public UpdateCommand wdtModelOnly(boolean value) {
wdtModelOnly = value;
return this;
}

/**
* Generate the command using the provided command line options.
* @return the imagetool command as a string suitable for running in ProcessBuilder
Expand All @@ -40,6 +72,11 @@ public String build() {
return super.build()
+ field("--fromImage", fromImage)
+ field("--tag", tag)
+ field("--patches", patches);
+ field("--patches", patches)
+ field("--wdtVersion", wdtVersion)
+ field("--wdtModel", wdtModel)
+ field("--wdtArchive", wdtArchive)
+ field("--wdtVariables", wdtVariables)
+ field("--wdtModelOnly", wdtModelOnly);
}
}