diff --git a/devtools/cli/src/main/java/io/quarkus/cli/image/Build.java b/devtools/cli/src/main/java/io/quarkus/cli/image/Build.java index 47fdf0496586b..a7184efcf27ec 100644 --- a/devtools/cli/src/main/java/io/quarkus/cli/image/Build.java +++ b/devtools/cli/src/main/java/io/quarkus/cli/image/Build.java @@ -8,7 +8,9 @@ import picocli.CommandLine; @CommandLine.Command(name = "build", sortOptions = false, showDefaultValues = true, mixinStandardHelpOptions = false, header = "Build a container image.", description = "%n" - + "This command will build a container image for the project.", subcommands = { Docker.class, Buildpack.class, + + "This command will build a container image for the project.", subcommands = { Docker.class, + Podman.class, + Buildpack.class, Jib.class, Openshift.class }, footer = { "%n" + "For example (using default values), it will create a container image using docker with REPOSITORY='${user.name}/' and TAG=''." diff --git a/devtools/cli/src/main/java/io/quarkus/cli/image/Builder.java b/devtools/cli/src/main/java/io/quarkus/cli/image/Builder.java index d5dad71a9a015..05ee8ffbad23c 100644 --- a/devtools/cli/src/main/java/io/quarkus/cli/image/Builder.java +++ b/devtools/cli/src/main/java/io/quarkus/cli/image/Builder.java @@ -2,6 +2,7 @@ public enum Builder { docker, + podman, jib, buildpack, openshift diff --git a/devtools/cli/src/main/java/io/quarkus/cli/image/Podman.java b/devtools/cli/src/main/java/io/quarkus/cli/image/Podman.java new file mode 100644 index 0000000000000..8a87957c77e44 --- /dev/null +++ b/devtools/cli/src/main/java/io/quarkus/cli/image/Podman.java @@ -0,0 +1,37 @@ +package io.quarkus.cli.image; + +import java.util.Optional; + +import io.quarkus.cli.BuildToolContext; +import picocli.CommandLine; + +@CommandLine.Command(name = "podman", sortOptions = false, showDefaultValues = true, mixinStandardHelpOptions = false, header = "Build a container image using Podman.", description = "%n" + + "This command will build or push a container image for the project, using Podman.", footer = "%n" + + "For example (using default values), it will create a container image using with REPOSITORY='${user.name}/' and TAG=''.", headerHeading = "%n", commandListHeading = "%nCommands:%n", synopsisHeading = "%nUsage: ", parameterListHeading = "%n", optionListHeading = "Options:%n") +public class Podman extends BaseImageSubCommand { + + private static final String PODMAN = "podman"; + private static final String PODMAN_CONFIG_PREFIX = "quarkus.podman."; + private static final String DOCKERFILE_JVM_PATH = "dockerfile-jvm-path"; + private static final String DOCKERFILE_NATIVE_PATH = "dockerfile-native-path"; + + @CommandLine.Option(order = 7, names = { "--dockerfile" }, description = "The path to the Dockerfile.") + public Optional dockerFile; + + @Override + public void populateContext(BuildToolContext context) { + var properties = context.getPropertiesOptions().properties; + properties.put(QUARKUS_CONTAINER_IMAGE_BUILDER, PODMAN); + + dockerFile.ifPresent(d -> properties.put( + PODMAN_CONFIG_PREFIX + (context.getBuildOptions().buildNative ? DOCKERFILE_NATIVE_PATH : DOCKERFILE_JVM_PATH), + d)); + + context.getForcedExtensions().add(QUARKUS_CONTAINER_IMAGE_EXTENSION_KEY_PREFIX + PODMAN); + } + + @Override + public String toString() { + return "Podman {imageOptions='" + imageOptions + "', dockerFile:'" + dockerFile.orElse("") + "'}"; + } +} diff --git a/devtools/cli/src/test/java/io/quarkus/cli/CliHelpTest.java b/devtools/cli/src/test/java/io/quarkus/cli/CliHelpTest.java index 8e5990447fe6f..9917e7c35604f 100644 --- a/devtools/cli/src/test/java/io/quarkus/cli/CliHelpTest.java +++ b/devtools/cli/src/test/java/io/quarkus/cli/CliHelpTest.java @@ -10,6 +10,8 @@ import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestMethodOrder; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import io.quarkus.devtools.messagewriter.MessageIcons; import io.quarkus.devtools.messagewriter.MessageWriter; @@ -218,32 +220,18 @@ public void testImageBuildHelp() throws Exception { assertThat(result.stdout).contains("Usage"); assertTrue(result.getStdout().contains("Commands:"), "Should list subcommands\n"); assertTrue(result.getStdout().contains("docker"), "Should list docker subcommand\n"); + assertTrue(result.getStdout().contains("podman"), "Should list podman subcommand\n"); assertTrue(result.getStdout().contains("jib"), "Should list jib subcommand\n"); assertTrue(result.getStdout().contains("openshift"), "Should list openshift subcommand\n"); assertTrue(result.getStdout().contains("buildpack"), "Should list buildpack subcommand\n"); } - @Test + @ParameterizedTest @Order(93) - public void testImageBuildDockerHelp() throws Exception { - CliDriver.Result result = CliDriver.execute(workspaceRoot, "image", "build", "docker", "--help"); - result.echoSystemOut(); - assertThat(result.stdout).contains("Usage"); - } - - @Test - @Order(94) - public void testImageBuildJibHelp() throws Exception { - CliDriver.Result result = CliDriver.execute(workspaceRoot, "image", "build", "jib", "--help"); - result.echoSystemOut(); - assertThat(result.stdout).contains("Usage"); - } - - @Test - @Order(95) - public void testImageBuildOpenshiftHelp() throws Exception { - CliDriver.Result result = CliDriver.execute(workspaceRoot, "image", "build", "openshift", "--help"); + @ValueSource(strings = { "docker", "podman", "jib", "openshift", "buildpack" }) + public void testImageBuildBuilderHelp(String builder) throws Exception { + CliDriver.Result result = CliDriver.execute(workspaceRoot, "image", "build", builder, "--help"); result.echoSystemOut(); assertThat(result.stdout).contains("Usage"); } @@ -260,34 +248,11 @@ public void testImagePushHelp() throws Exception { assertThat(result.stdout).contains("--registry-password-stdin"); } - @Test + @ParameterizedTest @Order(97) - public void testImagePushDockerHelp() throws Exception { - CliDriver.Result result = CliDriver.execute(workspaceRoot, "image", "push", "docker", "--help"); - result.echoSystemOut(); - assertThat(result.stdout).contains("Usage"); - } - - @Test - @Order(98) - public void testImagePushJibHelp() throws Exception { - CliDriver.Result result = CliDriver.execute(workspaceRoot, "image", "push", "jib", "--help"); - result.echoSystemOut(); - assertThat(result.stdout).contains("Usage"); - } - - @Test - @Order(99) - public void testImagePushOpenshiftHelp() throws Exception { - CliDriver.Result result = CliDriver.execute(workspaceRoot, "image", "push", "openshift", "--help"); - result.echoSystemOut(); - assertThat(result.stdout).contains("Usage"); - } - - @Test - @Order(100) - public void testImagePushBuildpackHelp() throws Exception { - CliDriver.Result result = CliDriver.execute(workspaceRoot, "image", "push", "buildpack", "--help"); + @ValueSource(strings = { "docker", "podman", "jib", "openshift", "buildpack" }) + public void testImagePushBuilderHelp(String builder) throws Exception { + CliDriver.Result result = CliDriver.execute(workspaceRoot, "image", "push", builder, "--help"); result.echoSystemOut(); assertThat(result.stdout).contains("Usage"); } diff --git a/devtools/cli/src/test/java/io/quarkus/cli/image/CliImageGradleTest.java b/devtools/cli/src/test/java/io/quarkus/cli/image/CliImageGradleTest.java index 28787b5d7ddad..bf2f35a16b399 100644 --- a/devtools/cli/src/test/java/io/quarkus/cli/image/CliImageGradleTest.java +++ b/devtools/cli/src/test/java/io/quarkus/cli/image/CliImageGradleTest.java @@ -111,6 +111,11 @@ public void testUsage() throws Exception { assertTrue(result.getStdout().contains("--builder=docker")); assertTrue(result.getStdout().contains("--init-script=")); + result = CliDriver.execute(project, "image", "build", "podman", "--dry-run"); + assertEquals(CommandLine.ExitCode.OK, result.getExitCode(), "Expected OK return code." + result); + assertTrue(result.getStdout().contains("--builder=podman")); + assertTrue(result.getStdout().contains("--init-script=")); + result = CliDriver.execute(project, "image", "build", "jib", "--dry-run"); assertEquals(CommandLine.ExitCode.OK, result.getExitCode(), "Expected OK return code." + result); assertTrue(result.getStdout().contains("--builder=jib"));