Skip to content

Commit

Permalink
fix(tasks): allow overriding docker default (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
loicmathieu authored Aug 25, 2023
1 parent bb1171b commit bcd786f
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions src/main/java/io/kestra/plugin/azure/cli/AzCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,40 +83,42 @@
}
)
public class AzCLI extends Task implements RunnableTask<ScriptOutput> {
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
@NotEmpty
private List<String> 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,
Expand All @@ -125,13 +127,12 @@ public class AzCLI extends Task implements RunnableTask<ScriptOutput> {
protected Map<String, String> 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 {
Expand All @@ -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"),
Expand All @@ -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<String> getLoginCommands(RunContext runContext) throws IllegalVariableEvaluationException {
List<String> loginCommands = new ArrayList<>();
if (this.username != null) {
Expand Down

0 comments on commit bcd786f

Please sign in to comment.