From bcd786fe37a5ef014224e71d1fa866f259486c77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mathieu?= Date: Fri, 25 Aug 2023 19:07:30 +0200 Subject: [PATCH] fix(tasks): allow overriding docker default (#45) --- .../io/kestra/plugin/azure/cli/AzCLI.java | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/main/java/io/kestra/plugin/azure/cli/AzCLI.java b/src/main/java/io/kestra/plugin/azure/cli/AzCLI.java index ecf4005..0d7b739 100644 --- a/src/main/java/io/kestra/plugin/azure/cli/AzCLI.java +++ b/src/main/java/io/kestra/plugin/azure/cli/AzCLI.java @@ -83,8 +83,10 @@ } ) public class AzCLI extends Task implements RunnableTask { + private static final String DEFAULT_IMAGE = "mcr.microsoft.com/azure-cli"; + @Schema( - title = "The commands to run." + title = "The commands to run." ) @PluginProperty(dynamic = true) @NotNull @@ -92,31 +94,31 @@ public class AzCLI extends Task implements RunnableTask { private List commands; @Schema( - title = "Account username. If set, it will use `az login` before running the commands." + title = "Account username. If set, it will use `az login` before running the commands." ) @PluginProperty(dynamic = true) private String username; @Schema( - title = "Account password." + title = "Account password." ) @PluginProperty(dynamic = true) private String password; @Schema( - title = "Tenant id to use." + title = "Tenant id to use." ) @PluginProperty(dynamic = true) private String tenant; @Schema( - title = "Is the account a service principal ?" + title = "Is the account a service principal ?" ) @PluginProperty private boolean servicePrincipal; @Schema( - title = "Additional environment variables for the current process." + title = "Additional environment variables for the current process." ) @PluginProperty( additionalProperties = String.class, @@ -125,13 +127,12 @@ public class AzCLI extends Task implements RunnableTask { protected Map env; @Schema( - title = "Docker options for the `DOCKER` runner." + title = "Docker options for the `DOCKER` runner.", + defaultValue = "{image=" + DEFAULT_IMAGE + ", pullPolicy=ALWAYS}" ) @PluginProperty @Builder.Default - protected DockerOptions docker = DockerOptions.builder() - .image("mcr.microsoft.com/azure-cli") - .build(); + protected DockerOptions docker = DockerOptions.builder().build(); @Override public ScriptOutput run(RunContext runContext) throws Exception { @@ -140,7 +141,7 @@ public ScriptOutput run(RunContext runContext) throws Exception { CommandsWrapper commands = new CommandsWrapper(runContext) .withWarningOnStdErr(true) .withRunnerType(RunnerType.DOCKER) - .withDockerOptions(this.docker) + .withDockerOptions(injectDefaults(getDocker())) .withCommands( ScriptService.scriptCommands( List.of("/bin/sh", "-c"), @@ -153,6 +154,15 @@ public ScriptOutput run(RunContext runContext) throws Exception { return commands.run(); } + private DockerOptions injectDefaults(DockerOptions original) { + var builder = original.toBuilder(); + if (original.getImage() == null) { + builder.image(DEFAULT_IMAGE); + } + + return builder.build(); + } + List getLoginCommands(RunContext runContext) throws IllegalVariableEvaluationException { List loginCommands = new ArrayList<>(); if (this.username != null) {