From e5a1bea348f079f87de460bdf1d3b231faea175e Mon Sep 17 00:00:00 2001 From: crountre Date: Mon, 8 Jun 2020 13:30:36 -0500 Subject: [PATCH 1/3] resolve parameters in template files with image knowledge --- .../imagetool/cli/menu/CommonOptions.java | 16 ++++++ .../imagetool/cli/menu/CreateImage.java | 2 + .../imagetool/cli/menu/UpdateImage.java | 3 ++ .../imagetool/util/ResolverOptions.java | 45 +++++++++++++++++ .../oracle/weblogic/imagetool/util/Utils.java | 32 ++++++++++++ .../src/main/resources/ImageTool.properties | 1 + .../imagetool/cli/menu/CommonOptionsTest.java | 50 +++++++++++++++++++ .../src/test/resources/templates/resolver.yml | 2 + .../test/resources/templates/verrazzano.yml | 42 ++++++++++++++++ 9 files changed, 193 insertions(+) create mode 100644 imagetool/src/main/java/com/oracle/weblogic/imagetool/util/ResolverOptions.java create mode 100644 imagetool/src/test/resources/templates/resolver.yml create mode 100644 imagetool/src/test/resources/templates/verrazzano.yml diff --git a/imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/menu/CommonOptions.java b/imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/menu/CommonOptions.java index b9057cc89..fc1e997a3 100644 --- a/imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/menu/CommonOptions.java +++ b/imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/menu/CommonOptions.java @@ -10,6 +10,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -24,6 +25,7 @@ import com.oracle.weblogic.imagetool.util.Constants; import com.oracle.weblogic.imagetool.util.DockerBuildCommand; import com.oracle.weblogic.imagetool.util.DockerfileOptions; +import com.oracle.weblogic.imagetool.util.ResolverOptions; import com.oracle.weblogic.imagetool.util.Utils; import picocli.CommandLine.Option; import picocli.CommandLine.Unmatched; @@ -33,6 +35,7 @@ public abstract class CommonOptions { private static final LoggingFacade logger = LoggingFactory.getLogger(CommonOptions.class); DockerfileOptions dockerfileOptions; + private List resolveOptions; private String tempDirectory = null; private String nonProxyHosts = null; @@ -167,6 +170,13 @@ void init(String buildId) throws Exception { logger.exiting(); } + List resolveOptions() { + if (resolveFiles != null) { + resolveOptions = Collections.singletonList(new ResolverOptions(imageTag, dockerfileOptions.domain_home())); + } + return resolveOptions; + } + /** * Returns true if any patches should be applied. * A PSU is considered a patch. @@ -432,6 +442,12 @@ String getPassword() { ) private boolean skipOpatchUpdate = false; + @Option( + names = {"--resolveFiles"}, + description = "Files with parameters that need to be resolved by values in the images tool." + ) + List resolveFiles; + @SuppressWarnings("unused") @Unmatched List unmatchedOptions; diff --git a/imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/menu/CreateImage.java b/imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/menu/CreateImage.java index 8f017e739..707d7d4d9 100644 --- a/imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/menu/CreateImage.java +++ b/imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/menu/CreateImage.java @@ -95,6 +95,8 @@ public CommandResponse call() throws Exception { String dockerfile = Utils.writeDockerfile(tmpDir + File.separator + "Dockerfile", "Create_Image.mustache", dockerfileOptions, dryRun); + Utils.writeResolvedFiles(resolveFiles, resolveOptions()); + runDockerCommand(dockerfile, cmdBuilder); } catch (Exception ex) { logger.fine("**ERROR**", ex); diff --git a/imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/menu/UpdateImage.java b/imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/menu/UpdateImage.java index 26711c902..6a2283f26 100644 --- a/imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/menu/UpdateImage.java +++ b/imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/menu/UpdateImage.java @@ -152,6 +152,9 @@ public CommandResponse call() throws Exception { String dockerfile = Utils.writeDockerfile(tmpDir + File.separator + "Dockerfile", "Update_Image.mustache", dockerfileOptions, dryRun); + // resolve parameters in the --resolveFiles file list (mustache templates) + Utils.writeResolvedFiles(resolveFiles, resolveOptions()); + runDockerCommand(dockerfile, cmdBuilder); } catch (Exception ex) { return new CommandResponse(-1, ex.getMessage()); diff --git a/imagetool/src/main/java/com/oracle/weblogic/imagetool/util/ResolverOptions.java b/imagetool/src/main/java/com/oracle/weblogic/imagetool/util/ResolverOptions.java new file mode 100644 index 000000000..0563fdb92 --- /dev/null +++ b/imagetool/src/main/java/com/oracle/weblogic/imagetool/util/ResolverOptions.java @@ -0,0 +1,45 @@ +// Copyright (c) 2020, Oracle Corporation and/or its affiliates. +// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + +package com.oracle.weblogic.imagetool.util; + +/** + * Mustache collection of options used to resolve values in a list of mustache templates + * as provided with the --resolverFiles command line argument. + */ +public class ResolverOptions { + + private String imageName; + private String domainHome; + + + /** + * Construct file with the options. + * + * @param imageName name from the image tag argument + * @param domainHome domain home argument or default if no argument + */ + public ResolverOptions(String imageName, String domainHome) { + this.imageName = imageName; + this.domainHome = domainHome; + } + + /** + * Return the image name value passed in the image tag argument. + * + * @return image tag name + */ + public String imageName() { + return imageName; + } + + /** + * Return the domain home passed in the domain home argument or the default if not passed as + * an argument. + * + * @return domain home value + */ + public String domainHome() { + return domainHome; + } +} \ No newline at end of file diff --git a/imagetool/src/main/java/com/oracle/weblogic/imagetool/util/Utils.java b/imagetool/src/main/java/com/oracle/weblogic/imagetool/util/Utils.java index f07cf8235..0fea49b96 100644 --- a/imagetool/src/main/java/com/oracle/weblogic/imagetool/util/Utils.java +++ b/imagetool/src/main/java/com/oracle/weblogic/imagetool/util/Utils.java @@ -210,6 +210,38 @@ public static String writeDockerfile(String destPath, String template, Dockerfil } } + /** + * Resolve the parameters in the list of Mustache templates with values passed in command line + * arguments or other values described by the image tool. + * @param fileNames list of file names with mustache parameters to be resolved + * @param options list of option files to resolve the mustache parameters + * @throws IOException if a file in the fileNames is invalid + */ + public static void writeResolvedFiles(List fileNames, List options) + throws IOException { + if (fileNames != null) { + for (String fileName : fileNames) { + logger.fine("writeResolvedFiles: resolve parameters in file {0}", fileName); + File template = new File(fileName); + File directory = template.getParentFile(); + if (directory == null + || !(template.isFile() && template.canRead() && template.canWrite())) { + throw new IllegalArgumentException(getMessage("IMG-0073", template.toString())); + } + + MustacheFactory mf = new DefaultMustacheFactory(directory); + Mustache mustache; + try (FileReader fr = new FileReader(template)) { + mustache = mf.compile(fr, fileName); + } + try (FileWriter fw = new FileWriter(template)) { + mustache.execute(fw, options).flush(); + } + } + } + + } + /** * Executes the given docker command and returns the stdout of the process as properties. * diff --git a/imagetool/src/main/resources/ImageTool.properties b/imagetool/src/main/resources/ImageTool.properties index 7f280a039..3c1e43f49 100644 --- a/imagetool/src/main/resources/ImageTool.properties +++ b/imagetool/src/main/resources/ImageTool.properties @@ -71,3 +71,4 @@ IMG-0069=No recommended patches for {0}, version {1} IMG-0070=Failed to find latest patches for {0}, version {1} IMG-0071=WDT Operation is set to UPDATE, but the DOMAIN_HOME environment variable was not defined in the base image, {0}. Did you mean to use "--wdtOperation CREATE" to create a new domain? IMG-0072=ORACLE_HOME environment variable is not defined in the base image: {0} +IMG-0073=Invalid file {0} listed in --resolveFiles diff --git a/imagetool/src/test/java/com/oracle/weblogic/imagetool/cli/menu/CommonOptionsTest.java b/imagetool/src/test/java/com/oracle/weblogic/imagetool/cli/menu/CommonOptionsTest.java index ce5ca492e..2a0bcb604 100644 --- a/imagetool/src/test/java/com/oracle/weblogic/imagetool/cli/menu/CommonOptionsTest.java +++ b/imagetool/src/test/java/com/oracle/weblogic/imagetool/cli/menu/CommonOptionsTest.java @@ -3,14 +3,18 @@ package com.oracle.weblogic.imagetool.cli.menu; +import java.io.BufferedReader; import java.io.File; +import java.io.FileInputStream; import java.io.IOException; +import java.io.InputStreamReader; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.logging.Level; import java.util.stream.Collectors; @@ -20,11 +24,13 @@ import com.oracle.weblogic.imagetool.logging.LoggingFacade; import com.oracle.weblogic.imagetool.logging.LoggingFactory; import com.oracle.weblogic.imagetool.util.DockerfileOptions; +import com.oracle.weblogic.imagetool.util.Utils; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; @Tag("unit") @@ -125,4 +131,48 @@ void handleAdditionalBuildCommands(@TempDir File buildDir) throws Exception { } } + /** + * Test resolving options in a list of input files. + * + * @throws Exception if in error or IOException + */ + @Test + void testResolveOptions() throws Exception { + CreateImage createImage = new CreateImage(); + + // accessing private fields normally set by the command line + Field optionsField = CommonOptions.class.getDeclaredField("dockerfileOptions"); + optionsField.setAccessible(true); + DockerfileOptions dockerfile = new DockerfileOptions("testbuildid"); + optionsField.set(createImage, dockerfile); + + Field imageTagField = CommonOptions.class.getDeclaredField("imageTag"); + imageTagField.setAccessible(true); + imageTagField.set(createImage, "phx.ocir.io/stevengreenberginc/todo:1.0.0"); + + createImage.resolveFiles = Arrays.asList("target/test-classes/templates/resolver.yml", + "target/test-classes/templates/verrazzano.yml"); + + Utils.writeResolvedFiles(createImage.resolveFiles, createImage.resolveOptions()); + + List linesRead = new ArrayList<>(); + try (BufferedReader br = new BufferedReader(new InputStreamReader( + new FileInputStream("target/test-classes/templates/resolver.yml")))) { + while (br.ready()) { + linesRead.add(br.readLine()); + } + } + assertEquals(2, linesRead.size(), "Number of lines read from the file was unexpected"); + for (String line : linesRead) { + if (line.contains("domainHome")) { + assertTrue(line.contains("/u01/domains/base_domain"), "Invalid domain home value " + line); + } else if (line.contains("image")) { + assertTrue(line.contains("phx.ocir.io/stevengreenberginc/todo:1.0.0"), + "Invalid tag name " + line); + } else { + fail("Unexpected line read " + line); + } + + } + } } diff --git a/imagetool/src/test/resources/templates/resolver.yml b/imagetool/src/test/resources/templates/resolver.yml new file mode 100644 index 000000000..e0487ce52 --- /dev/null +++ b/imagetool/src/test/resources/templates/resolver.yml @@ -0,0 +1,2 @@ +domainHome: {{{domainHome}}} +image: {{{imageName}}} \ No newline at end of file diff --git a/imagetool/src/test/resources/templates/verrazzano.yml b/imagetool/src/test/resources/templates/verrazzano.yml new file mode 100644 index 000000000..e30028108 --- /dev/null +++ b/imagetool/src/test/resources/templates/verrazzano.yml @@ -0,0 +1,42 @@ +apiVersion: verrazzano.io/v1beta1 +kind: VerrazzanoModel +metadata: + name: dereks-todo-model + namespace: default +spec: + description: "Derek's Todo System" + weblogicDomains: + - name: todo + adminPort: 32701 + t3Port: 32702 + domainCRValues: + domainUID: todo + domainHome: {{{domainHome}}} + image: {{{imageName}}} + includeServerOutInPodLog: true + replicas: 1 + webLogicCredentialsSecret: + name: todo-weblogic-credentials + imagePullSecrets: + - name: ocir + clusters: + - clusterName: cluster-1 + serverPod: + env: + - name: JAVA_OPTIONS + value: "-Dweblogic.StdoutDebugEnabled=false" + - name: USER_MEM_ARGS + value: "-Djava.security.egd=file:/dev/./urandom -Xms64m -Xmx256m " + - name: WL_HOME + value: /u01/oracle/wlserver + - name: MW_HOME + value: /u01/oracle + connections: + - ingress: + - name: todo-ingress + match: + - uri: + prefix: "/todo" + - database: + - target: todo-db + datasourceName: todoDb From 2a407991393f4b84d9b09f3df9a9fa9abf6acaa0 Mon Sep 17 00:00:00 2001 From: crountre Date: Tue, 9 Jun 2020 13:35:44 -0500 Subject: [PATCH 2/3] Made requested changes --- .../imagetool/cli/menu/CommonOptions.java | 26 +++++++++++---- .../imagetool/cli/menu/CreateImage.java | 3 +- .../imagetool/cli/menu/UpdateImage.java | 4 +-- .../oracle/weblogic/imagetool/util/Utils.java | 24 +++++++------- ...olverOptions.java => VerrazzanoModel.java} | 6 ++-- .../imagetool/cli/menu/CommonOptionsTest.java | 33 +++++++++---------- 6 files changed, 53 insertions(+), 43 deletions(-) rename imagetool/src/main/java/com/oracle/weblogic/imagetool/util/{ResolverOptions.java => VerrazzanoModel.java} (85%) diff --git a/imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/menu/CommonOptions.java b/imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/menu/CommonOptions.java index fc1e997a3..4f08eefb8 100644 --- a/imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/menu/CommonOptions.java +++ b/imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/menu/CommonOptions.java @@ -25,8 +25,8 @@ import com.oracle.weblogic.imagetool.util.Constants; import com.oracle.weblogic.imagetool.util.DockerBuildCommand; import com.oracle.weblogic.imagetool.util.DockerfileOptions; -import com.oracle.weblogic.imagetool.util.ResolverOptions; import com.oracle.weblogic.imagetool.util.Utils; +import com.oracle.weblogic.imagetool.util.VerrazzanoModel; import picocli.CommandLine.Option; import picocli.CommandLine.Unmatched; @@ -35,10 +35,12 @@ public abstract class CommonOptions { private static final LoggingFacade logger = LoggingFactory.getLogger(CommonOptions.class); DockerfileOptions dockerfileOptions; - private List resolveOptions; private String tempDirectory = null; private String nonProxyHosts = null; + private List resolveOptions = null; + private List resolveFiles = null; + abstract String getInstallerVersion(); private void handleChown() { @@ -170,9 +172,19 @@ void init(String buildId) throws Exception { logger.exiting(); } + List gatherFiles() { + if (resolveFiles == null) { + resolveFiles = new ArrayList<>(); + } + if (verrazzanoModel != null) { + resolveFiles.add(verrazzanoModel); + } + return resolveFiles; + } + List resolveOptions() { - if (resolveFiles != null) { - resolveOptions = Collections.singletonList(new ResolverOptions(imageTag, dockerfileOptions.domain_home())); + if (resolveFiles != null && !resolveFiles.isEmpty()) { + resolveOptions = Collections.singletonList(new VerrazzanoModel(imageTag, dockerfileOptions.domain_home())); } return resolveOptions; } @@ -443,10 +455,10 @@ String getPassword() { private boolean skipOpatchUpdate = false; @Option( - names = {"--resolveFiles"}, - description = "Files with parameters that need to be resolved by values in the images tool." + names = {"--vzModel"}, + description = "For verrazzano, resolve parameters in the verrazzano model with information from the image tool." ) - List resolveFiles; + Path verrazzanoModel; @SuppressWarnings("unused") @Unmatched diff --git a/imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/menu/CreateImage.java b/imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/menu/CreateImage.java index 707d7d4d9..108190ae4 100644 --- a/imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/menu/CreateImage.java +++ b/imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/menu/CreateImage.java @@ -95,7 +95,8 @@ public CommandResponse call() throws Exception { String dockerfile = Utils.writeDockerfile(tmpDir + File.separator + "Dockerfile", "Create_Image.mustache", dockerfileOptions, dryRun); - Utils.writeResolvedFiles(resolveFiles, resolveOptions()); + // resolve parameters in the list of mustache templates returned by gatherFiles() + Utils.writeResolvedFiles(gatherFiles(), resolveOptions()); runDockerCommand(dockerfile, cmdBuilder); } catch (Exception ex) { diff --git a/imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/menu/UpdateImage.java b/imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/menu/UpdateImage.java index 6a2283f26..66f437320 100644 --- a/imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/menu/UpdateImage.java +++ b/imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/menu/UpdateImage.java @@ -152,8 +152,8 @@ public CommandResponse call() throws Exception { String dockerfile = Utils.writeDockerfile(tmpDir + File.separator + "Dockerfile", "Update_Image.mustache", dockerfileOptions, dryRun); - // resolve parameters in the --resolveFiles file list (mustache templates) - Utils.writeResolvedFiles(resolveFiles, resolveOptions()); + // resolve parameters in the list of mustache templates returned by gatherFiles() + Utils.writeResolvedFiles(gatherFiles(), resolveOptions()); runDockerCommand(dockerfile, cmdBuilder); } catch (Exception ex) { diff --git a/imagetool/src/main/java/com/oracle/weblogic/imagetool/util/Utils.java b/imagetool/src/main/java/com/oracle/weblogic/imagetool/util/Utils.java index 0fea49b96..50a6462fb 100644 --- a/imagetool/src/main/java/com/oracle/weblogic/imagetool/util/Utils.java +++ b/imagetool/src/main/java/com/oracle/weblogic/imagetool/util/Utils.java @@ -213,28 +213,28 @@ public static String writeDockerfile(String destPath, String template, Dockerfil /** * Resolve the parameters in the list of Mustache templates with values passed in command line * arguments or other values described by the image tool. - * @param fileNames list of file names with mustache parameters to be resolved + * @param paths list of file paths that are mustache templates * @param options list of option files to resolve the mustache parameters * @throws IOException if a file in the fileNames is invalid */ - public static void writeResolvedFiles(List fileNames, List options) + public static void writeResolvedFiles(List paths, List options) throws IOException { - if (fileNames != null) { - for (String fileName : fileNames) { - logger.fine("writeResolvedFiles: resolve parameters in file {0}", fileName); - File template = new File(fileName); - File directory = template.getParentFile(); + if (paths != null) { + for (Path path : paths) { + logger.fine("writeResolvedFiles: resolve parameters in file {0}", path); + File directory = path.toFile().getParentFile(); if (directory == null - || !(template.isFile() && template.canRead() && template.canWrite())) { - throw new IllegalArgumentException(getMessage("IMG-0073", template.toString())); + || !(Files.exists(path) && Files.isReadable(path) && Files.isWritable(path))) { + throw new IllegalArgumentException(getMessage("IMG-0073", path)); } MustacheFactory mf = new DefaultMustacheFactory(directory); Mustache mustache; - try (FileReader fr = new FileReader(template)) { - mustache = mf.compile(fr, fileName); + try (FileReader fr = new FileReader(path.toFile())) { + mustache = mf.compile(fr, path.getFileName().toString()); } - try (FileWriter fw = new FileWriter(template)) { + + try (FileWriter fw = new FileWriter(path.toFile())) { mustache.execute(fw, options).flush(); } } diff --git a/imagetool/src/main/java/com/oracle/weblogic/imagetool/util/ResolverOptions.java b/imagetool/src/main/java/com/oracle/weblogic/imagetool/util/VerrazzanoModel.java similarity index 85% rename from imagetool/src/main/java/com/oracle/weblogic/imagetool/util/ResolverOptions.java rename to imagetool/src/main/java/com/oracle/weblogic/imagetool/util/VerrazzanoModel.java index 0563fdb92..12e3169cf 100644 --- a/imagetool/src/main/java/com/oracle/weblogic/imagetool/util/ResolverOptions.java +++ b/imagetool/src/main/java/com/oracle/weblogic/imagetool/util/VerrazzanoModel.java @@ -4,10 +4,10 @@ package com.oracle.weblogic.imagetool.util; /** - * Mustache collection of options used to resolve values in a list of mustache templates + * Mustache collection of options used to resolve values for the Verrazzano Model * as provided with the --resolverFiles command line argument. */ -public class ResolverOptions { +public class VerrazzanoModel { private String imageName; private String domainHome; @@ -19,7 +19,7 @@ public class ResolverOptions { * @param imageName name from the image tag argument * @param domainHome domain home argument or default if no argument */ - public ResolverOptions(String imageName, String domainHome) { + public VerrazzanoModel(String imageName, String domainHome) { this.imageName = imageName; this.domainHome = domainHome; } diff --git a/imagetool/src/test/java/com/oracle/weblogic/imagetool/cli/menu/CommonOptionsTest.java b/imagetool/src/test/java/com/oracle/weblogic/imagetool/cli/menu/CommonOptionsTest.java index 2a0bcb604..f631e4f1b 100644 --- a/imagetool/src/test/java/com/oracle/weblogic/imagetool/cli/menu/CommonOptionsTest.java +++ b/imagetool/src/test/java/com/oracle/weblogic/imagetool/cli/menu/CommonOptionsTest.java @@ -3,11 +3,8 @@ package com.oracle.weblogic.imagetool.cli.menu; -import java.io.BufferedReader; import java.io.File; -import java.io.FileInputStream; import java.io.IOException; -import java.io.InputStreamReader; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.nio.file.Files; @@ -148,26 +145,26 @@ void testResolveOptions() throws Exception { Field imageTagField = CommonOptions.class.getDeclaredField("imageTag"); imageTagField.setAccessible(true); - imageTagField.set(createImage, "phx.ocir.io/stevengreenberginc/todo:1.0.0"); + imageTagField.set(createImage, "mydomain:latest"); - createImage.resolveFiles = Arrays.asList("target/test-classes/templates/resolver.yml", - "target/test-classes/templates/verrazzano.yml"); + Field resolveFilesField = CommonOptions.class.getDeclaredField("resolveFiles"); + resolveFilesField.setAccessible(true); + List resolveFiles = + Arrays.asList(new File("target/test-classes/templates/resolver.yml").toPath(), + new File("target/test-classes/templates/verrazzano.yml").toPath()); + resolveFilesField.set(createImage, resolveFiles); - Utils.writeResolvedFiles(createImage.resolveFiles, createImage.resolveOptions()); + Utils.writeResolvedFiles(resolveFiles, createImage.resolveOptions()); - List linesRead = new ArrayList<>(); - try (BufferedReader br = new BufferedReader(new InputStreamReader( - new FileInputStream("target/test-classes/templates/resolver.yml")))) { - while (br.ready()) { - linesRead.add(br.readLine()); - } - } + List linesRead = + Files.readAllLines(new File("target/test-classes/templates/resolver.yml").toPath()); assertEquals(2, linesRead.size(), "Number of lines read from the file was unexpected"); for (String line : linesRead) { - if (line.contains("domainHome")) { - assertTrue(line.contains("/u01/domains/base_domain"), "Invalid domain home value " + line); - } else if (line.contains("image")) { - assertTrue(line.contains("phx.ocir.io/stevengreenberginc/todo:1.0.0"), + line = line.trim(); + if (line.startsWith("domainHome")) { + assertTrue(line.endsWith("/u01/domains/base_domain"), "Invalid domain home value " + line); + } else if (line.startsWith("image")) { + assertTrue(line.endsWith("mydomain:latest"), "Invalid tag name " + line); } else { fail("Unexpected line read " + line); From 8ea5c7dd9c69750d0e6a985863fabe7b59a6da6e Mon Sep 17 00:00:00 2001 From: crountre Date: Tue, 9 Jun 2020 17:12:41 -0500 Subject: [PATCH 3/3] Made requested changes --- imagetool/src/main/resources/ImageTool.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imagetool/src/main/resources/ImageTool.properties b/imagetool/src/main/resources/ImageTool.properties index 3c1e43f49..202cfd8b2 100644 --- a/imagetool/src/main/resources/ImageTool.properties +++ b/imagetool/src/main/resources/ImageTool.properties @@ -71,4 +71,4 @@ IMG-0069=No recommended patches for {0}, version {1} IMG-0070=Failed to find latest patches for {0}, version {1} IMG-0071=WDT Operation is set to UPDATE, but the DOMAIN_HOME environment variable was not defined in the base image, {0}. Did you mean to use "--wdtOperation CREATE" to create a new domain? IMG-0072=ORACLE_HOME environment variable is not defined in the base image: {0} -IMG-0073=Invalid file {0} listed in --resolveFiles +IMG-0073=Invalid file {0} listed for Verrazzano model