From c5af585aed32cd0c4601fd6baa18509740e9928a Mon Sep 17 00:00:00 2001 From: "derek.sharpe" Date: Tue, 7 Jan 2025 19:28:20 +0000 Subject: [PATCH] Remove force-rm default from buildx and add command line option for buildx --- bug_release.sh | 26 ++++++++++--------- .../content/userguide/tools/create-image.md | 1 + .../content/userguide/tools/rebase-image.md | 1 + .../content/userguide/tools/update-image.md | 1 + .../imagetool/builder/BuildCommand.java | 17 ++++++++++-- .../imagetool/cli/menu/CommonOptions.java | 11 ++++++-- .../imagetool/builder/BuilderTest.java | 21 +++++++++++++++ pom.xml | 10 +++---- .../imagetool/tests/utils/Runner.java | 11 ++++---- 9 files changed, 73 insertions(+), 26 deletions(-) diff --git a/bug_release.sh b/bug_release.sh index de4440aa8..64588b027 100755 --- a/bug_release.sh +++ b/bug_release.sh @@ -1,4 +1,6 @@ #!/bin/bash +# Only use this script when releasing bug fixes (removes SNAPSHOT for version) +git checkout main project_version=$(mvn help:evaluate -q -DforceStdout -D"expression=project.version") echo Current POM version: ${project_version} @@ -10,18 +12,18 @@ new_version=$(echo $project_version | sed -e "s/[0-9][0-9]*\([^0-9]*\)$/$next_di echo New Version: ${new_version} -echo mvn versions:set -DremoveSnapshot -DgenerateBackupPoms=false -echo mvn clean install -echo git add . -echo git commit -m \"release ${project_version_number_only}\" -echo git push +mvn versions:set -DremoveSnapshot -DgenerateBackupPoms=false +mvn clean install +git add . +git commit -m \"release ${project_version_number_only}\" +git push -echo git tag release-${project_version_number_only} -echo git push origin release-${project_version_number_only} +git tag release-${project_version_number_only} +git push origin release-${project_version_number_only} -echo mvn versions:set -DgenerateBackupPoms=false -DnewVersion=${new_version} -echo mvn clean install -echo git add . -echo git commit -m \"preparing for next development iteration\" -echo git push +mvn versions:set -DgenerateBackupPoms=false -DnewVersion=${new_version} +mvn clean install +git add . +git commit -m \"preparing for next development iteration\" +git push diff --git a/documentation/site/content/userguide/tools/create-image.md b/documentation/site/content/userguide/tools/create-image.md index 68a1f5ae2..e14ebe588 100644 --- a/documentation/site/content/userguide/tools/create-image.md +++ b/documentation/site/content/userguide/tools/create-image.md @@ -48,6 +48,7 @@ Usage: imagetool create [OPTIONS] | `--strictPatchOrdering` | Instruct OPatch to apply patches one at a time (uses `apply` instead of `napply`). | | | `--target` | Select the target environment in which the created image will be used. Supported values: `Default` (Docker/Kubernetes), `OpenShift`. See [Additional information](#--target). | `Default` | | `--type` | Installer type. Supported values: `WLS`, `WLSDEV`, `WLSSLIM`, `FMW`, `IDM`, `MFT`, `OAM`, `ODI`, `OHS`, `OIG`, `OUD`, `OUD_WLS`, `OID`, `OSB`, `SOA`, `SOA_OSB`, `SOA_OSB_B2B`, `WCC`, `WCP`, `WCS` | `WLS` | +| `--useBuildx` | Use BuildKit for building the container image. | | | `--user` | Oracle support email ID. When supplying `user`, you must supply the password either as an environment variable using `--passwordEnv`, or as a file using `--passwordFile`, or interactively, on the command line with `--password`. | | | `--version` | Installer version. | `12.2.1.3.0` | | `--wdtArchive` | A WDT archive ZIP file or comma-separated list of files. | | diff --git a/documentation/site/content/userguide/tools/rebase-image.md b/documentation/site/content/userguide/tools/rebase-image.md index 25f7fd549..a4cf080d8 100644 --- a/documentation/site/content/userguide/tools/rebase-image.md +++ b/documentation/site/content/userguide/tools/rebase-image.md @@ -47,6 +47,7 @@ Usage: imagetool rebase [OPTIONS] | `--target` | Select the target environment in which the created image will be used. Supported values: `Default` (Docker/Kubernetes), `OpenShift`. See [Additional information](#--target). | `Default` | | `--targetImage` | Container image to extend for the domain's new image. | | | `--type` | Installer type. Supported values: `WLS`, `WLSDEV`, `WLSSLIM`, `FMW`, `IDM`, `MFT`, `OAM`, `ODI`, `OHS`, `OIG`, `OUD`, `OUD_WLS`, `OID`, `OSB`, `SOA`, `SOA_OSB`, `SOA_OSB_B2B`, `WCC`, `WCP`, `WCS` | `WLS` | +| `--useBuildx` | Use BuildKit for building the container image. | | | `--user` | Your Oracle support email ID. When supplying `user`, you must supply the password either as an environment variable using `--passwordEnv`, or as a file using `--passwordFile`, or interactively, on the command line with `--password`. | | | `--version` | Installer version. | `12.2.1.3.0` | diff --git a/documentation/site/content/userguide/tools/update-image.md b/documentation/site/content/userguide/tools/update-image.md index e634b1827..a2c06157c 100644 --- a/documentation/site/content/userguide/tools/update-image.md +++ b/documentation/site/content/userguide/tools/update-image.md @@ -49,6 +49,7 @@ Update WebLogic Docker image with selected patches | `--strictPatchOrdering` | Instruct OPatch to apply patches one at a time (uses `apply` instead of `napply`). | | | `--target` | Select the target environment in which the created image will be used. Supported values: `Default` (Docker/Kubernetes), `OpenShift`. See [Additional information](#--target). | `Default` | | `--type` | Installer type. Supported values: `WLS`, `WLSDEV`, `WLSSLIM`, `FMW`, `IDM`, `MFT`, `OAM`, `ODI`, `OHS`, `OIG`, `OUD`, `OUD_WLS`, `OID`, `OSB`, `SOA`, `SOA_OSB`, `SOA_OSB_B2B`, `WCC`, `WCP`, `WCS` | `WLS` | +| `--useBuildx` | Use BuildKit for building the container image. | | | `--user` | Oracle support email ID. When supplying `user`, you must supply the password either as an environment variable using `--passwordEnv`, or as a file using `--passwordFile`, or interactively, on the command line with `--password`. | | | `--wdtArchive` | A WDT archive ZIP file or comma-separated list of files. | | | `--wdtDomainHome` | Path to the `-domain_home` for WDT. | `/u01/domains/base_domain` | diff --git a/imagetool/src/main/java/com/oracle/weblogic/imagetool/builder/BuildCommand.java b/imagetool/src/main/java/com/oracle/weblogic/imagetool/builder/BuildCommand.java index fa55d133e..b5e398216 100644 --- a/imagetool/src/main/java/com/oracle/weblogic/imagetool/builder/BuildCommand.java +++ b/imagetool/src/main/java/com/oracle/weblogic/imagetool/builder/BuildCommand.java @@ -60,6 +60,18 @@ public BuildCommand tag(String value) { return this; } + /** + * Toggle the use of the BuildKit. + * If true, the build command will start "buildx build". + * If false, the build command will start "build". + * @param value true to enable buildx + * @return this + */ + public BuildCommand useBuildx(boolean value) { + useBuildx = value; + return this; + } + /** * Add container build platform. Pass the desired * build architecture to the build process. @@ -72,7 +84,7 @@ public BuildCommand platform(String value) { } command.add("--platform"); command.add(value); - useBuildx = true; + useBuildx(true); return this; } @@ -83,7 +95,8 @@ public BuildCommand platform(String value) { * @return this */ public BuildCommand forceRm(boolean value) { - if (value) { + // Docker removed --force-rm from the buildx build API, and Podman defaults --force-rm=true + if (value && !useBuildx) { command.add("--force-rm"); } return this; 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 af6bddc9d..63eaae583 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 @@ -121,9 +121,10 @@ BuildCommand getInitialBuildCmd(String contextFolder) { logger.entering(); BuildCommand cmdBuilder = new BuildCommand(buildEngine, contextFolder); - cmdBuilder.forceRm(!skipcleanup) - .tag(imageTag) + cmdBuilder.tag(imageTag) + .useBuildx(useBuildx) .platform(buildPlatform) + .forceRm(!skipcleanup) .network(buildNetwork) .pull(buildPull) .additionalOptions(buildOptions) @@ -450,6 +451,12 @@ public Architecture getTargetArchitecture() { ) private String buildPlatform; + @Option( + names = {"--useBuildx"}, + description = "Use the BuildKit for building the container image (default when building multi-architecture)" + ) + private boolean useBuildx; + @Parameters( description = "Container build options.", hidden = true diff --git a/imagetool/src/test/java/com/oracle/weblogic/imagetool/builder/BuilderTest.java b/imagetool/src/test/java/com/oracle/weblogic/imagetool/builder/BuilderTest.java index bfd029ce7..428932125 100644 --- a/imagetool/src/test/java/com/oracle/weblogic/imagetool/builder/BuilderTest.java +++ b/imagetool/src/test/java/com/oracle/weblogic/imagetool/builder/BuilderTest.java @@ -79,4 +79,25 @@ void testBuildWithProxyPass() { cmd.tag("img:3").buildArg("http_proxy", "http://user:pass@blah/blah", true); assertEquals(expected("--tag img:3 --build-arg http_proxy=********"), cmd.toString()); } + + @Test + void testBuildArgsWithPlatform() { + Map argMap = null; + + BuildCommand cmd = new BuildCommand(BUILD_ENGINE, BUILD_CONTEXT) + .tag("img:4") + .pull(true) + .platform("linux/amd64") + .forceRm(true) + .network("private-net") + .buildArg(argMap); + + // expect that "--force-rm" will not be used, expect "buildx build" will be used + assertEquals( + String.format("%s buildx build %s %s", + BUILD_ENGINE, + "--tag img:4 --pull --platform linux/amd64 --network private-net", + BUILD_CONTEXT), + cmd.toString()); + } } diff --git a/pom.xml b/pom.xml index 28812a75a..3338ede07 100644 --- a/pom.xml +++ b/pom.xml @@ -72,7 +72,7 @@ org.junit.jupiter junit-jupiter-engine - 5.11.3 + 5.11.4 test @@ -154,7 +154,7 @@ org.apache.maven.plugins maven-failsafe-plugin - 3.5.0 + 3.5.2 ${test.groups} failing @@ -214,7 +214,7 @@ org.apache.maven.plugins maven-checkstyle-plugin - 3.5.0 + 3.6.0 checkstyle @@ -242,14 +242,14 @@ com.puppycrawl.tools checkstyle - 10.20.2 + 10.21.1 org.apache.maven.plugins maven-surefire-plugin - 3.5.1 + 3.5.2 unit failing diff --git a/tests/src/test/java/com/oracle/weblogic/imagetool/tests/utils/Runner.java b/tests/src/test/java/com/oracle/weblogic/imagetool/tests/utils/Runner.java index 800704101..d9d89e23d 100644 --- a/tests/src/test/java/com/oracle/weblogic/imagetool/tests/utils/Runner.java +++ b/tests/src/test/java/com/oracle/weblogic/imagetool/tests/utils/Runner.java @@ -68,12 +68,13 @@ public static CommandResult run(String command, PrintWriter output) throws IOExc p = pb.start(); - BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream(), UTF_8)); StringBuilder processOut = new StringBuilder(); - String line; - while ((line = reader.readLine()) != null) { - processOut.append(line); - output.println(line); + try (BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream(), UTF_8))) { + String line; + while ((line = reader.readLine()) != null) { + processOut.append(line); + output.println(line); + } } p.waitFor();