Skip to content

Commit

Permalink
feat: task runner
Browse files Browse the repository at this point in the history
  • Loading branch information
loicmathieu committed Jun 24, 2024
1 parent 9089286 commit 0aff260
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions src/main/java/io/kestra/plugin/aws/cli/AwsCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
import io.kestra.core.models.annotations.PluginProperty;
import io.kestra.core.models.tasks.runners.ScriptService;
import io.kestra.core.models.tasks.*;
import io.kestra.core.models.tasks.runners.TaskRunner;
import io.kestra.core.runners.RunContext;
import io.kestra.plugin.aws.AbstractConnection;
import io.kestra.plugin.scripts.exec.scripts.models.DockerOptions;
import io.kestra.plugin.scripts.exec.scripts.models.RunnerType;
import io.kestra.plugin.scripts.exec.scripts.models.ScriptOutput;
import io.kestra.plugin.scripts.exec.scripts.runners.CommandsWrapper;
import io.kestra.plugin.scripts.runner.docker.Docker;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.*;
Expand Down Expand Up @@ -75,12 +78,25 @@ public class AwsCLI extends AbstractConnection implements RunnableTask<ScriptOut
protected Map<String, String> env;

@Schema(
title = "Docker options to be used along with for the `DOCKER` runner.",
defaultValue = "{image=" + DEFAULT_IMAGE + ", pullPolicy=ALWAYS}"
title = "Deprecated, use 'taskRunner' instead"
)
@PluginProperty
@Deprecated
private DockerOptions docker;

@Schema(
title = "The task runner to use.",
description = "Task runners are provided by plugins, each have their own properties."
)
@PluginProperty
@Builder.Default
protected DockerOptions docker = DockerOptions.builder().build();
@Valid
private TaskRunner taskRunner = Docker.INSTANCE;

@Schema(title = "The task runner container image, only used if the task runner is container-based.")
@PluginProperty(dynamic = true)
@Builder.Default
private String containerImage = DEFAULT_IMAGE;

@Schema(
title = "Expected output format for AWS commands (can be overridden with --format parameter)."
Expand All @@ -101,14 +117,15 @@ public ScriptOutput run(RunContext runContext) throws Exception {
.withWarningOnStdErr(true)
.withRunnerType(RunnerType.DOCKER)
.withDockerOptions(injectDefaults(getDocker()))
.withTaskRunner(this.taskRunner)
.withContainerImage(this.containerImage)
.withCommands(
ScriptService.scriptCommands(
List.of("/bin/sh", "-c"),
null,
this.commands)
);

commands = commands.withEnv(this.getEnv(runContext))
)
.withEnv(this.getEnv(runContext))
.withNamespaceFiles(namespaceFiles)
.withInputFiles(inputFiles)
.withOutputFiles(outputFiles);
Expand All @@ -117,6 +134,10 @@ public ScriptOutput run(RunContext runContext) throws Exception {
}

private DockerOptions injectDefaults(DockerOptions original) {
if (original == null) {
return null;
}

var builder = original.toBuilder();
if (original.getImage() == null) {
builder.image(DEFAULT_IMAGE);
Expand Down

0 comments on commit 0aff260

Please sign in to comment.