Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: migrate to dynamic properties #199

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import io.kestra.core.models.annotations.Example;
import io.kestra.core.models.annotations.Plugin;
import io.kestra.core.models.annotations.PluginProperty;
import io.kestra.core.models.property.Property;
import io.kestra.core.models.tasks.runners.ScriptService;
import io.kestra.core.models.tasks.runners.TargetOS;
import io.kestra.core.runners.RunContext;
import io.kestra.plugin.scripts.exec.AbstractExecScript;
import io.kestra.plugin.scripts.exec.scripts.models.DockerOptions;
Expand Down Expand Up @@ -31,7 +33,7 @@
code = """
id: jbang_commands
namespace: company.team

tasks:
- id: commands
type: io.kestra.plugin.scripts.jbang.Commands
Expand All @@ -45,7 +47,7 @@ public class Commands extends AbstractExecScript {
private static final String DEFAULT_IMAGE = "jbangdev/jbang-action";

@Builder.Default
private String containerImage = DEFAULT_IMAGE;
private Property<String> containerImage = Property.of(DEFAULT_IMAGE);

@Schema(
title = "JBangs commands to run."
Expand All @@ -58,7 +60,7 @@ public class Commands extends AbstractExecScript {
protected DockerOptions injectDefaults(DockerOptions original) {
var builder = original.toBuilder();
if (original.getImage() == null) {
builder.image(this.getContainerImage());
builder.image(this.getContainerImage().toString());
}

return builder.build();
Expand All @@ -68,9 +70,9 @@ protected DockerOptions injectDefaults(DockerOptions original) {
public ScriptOutput run(RunContext runContext) throws Exception {
List<String> commandsArgs = ScriptService.scriptCommands(
this.interpreter,
getBeforeCommandsWithOptions(),
getBeforeCommandsWithOptions(runContext),
this.commands,
this.targetOS
runContext.render(this.targetOS).as(TargetOS.class).orElse(null)
);

return this.commands(runContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import io.kestra.core.models.annotations.Example;
import io.kestra.core.models.annotations.Plugin;
import io.kestra.core.models.annotations.PluginProperty;
import io.kestra.core.models.property.Property;
import io.kestra.core.models.tasks.runners.ScriptService;
import io.kestra.core.models.tasks.runners.TargetOS;
import io.kestra.core.runners.FilesService;
import io.kestra.core.runners.RunContext;
import io.kestra.plugin.scripts.exec.AbstractExecScript;
Expand Down Expand Up @@ -38,7 +40,7 @@
code = """
id: jbang_script
namespace: company.team

tasks:
- id: script
type: io.kestra.plugin.scripts.jbang.Script
Expand All @@ -60,20 +62,20 @@ public static void main(String[] args) {
code = """
id: jbang_script
namespace: company.team

tasks:
- id: script_with_dependency
type: io.kestra.plugin.scripts.jbang.Script
script: |
//DEPS ch.qos.reload4j:reload4j:1.2.19

import org.apache.log4j.Logger;
import org.apache.log4j.BasicConfigurator;

class classpath_example {

static final Logger logger = Logger.getLogger(classpath_example.class);

public static void main(String[] args) {
BasicConfigurator.configure();\s
logger.info("Hello World");
Expand All @@ -87,7 +89,7 @@ public static void main(String[] args) {
code = """
id: jbang_script
namespace: company.team

tasks:
- id: script_kotlin
type: io.kestra.plugin.scripts.jbang.Script
Expand All @@ -104,7 +106,7 @@ public class Script extends AbstractExecScript {
private static final String DEFAULT_IMAGE = "jbangdev/jbang-action";

@Builder.Default
private String containerImage = DEFAULT_IMAGE;
private Property<String> containerImage = Property.of(DEFAULT_IMAGE);

@Schema(
title = "The inline script content. This property is intended for the script file's content as a (multiline) string, not a path to a file. To run a command from a file such as `jbang hello.java` or an executable JAR, use the `Commands` task instead."
Expand Down Expand Up @@ -136,7 +138,7 @@ public class Script extends AbstractExecScript {
protected DockerOptions injectDefaults(DockerOptions original) {
var builder = original.toBuilder();
if (original.getImage() == null) {
builder.image(this.getContainerImage());
builder.image(this.getContainerImage().toString());
}

return builder.build();
Expand All @@ -157,9 +159,9 @@ public ScriptOutput run(RunContext runContext) throws Exception {

List<String> commandsArgs = ScriptService.scriptCommands(
this.interpreter,
getBeforeCommandsWithOptions(),
String.join(" ", "jbang", quiet ? "--quiet" : "", commands.getTaskRunner().toAbsolutePath(runContext, commands, relativeScriptPath.toString(), this.targetOS)),
this.targetOS
getBeforeCommandsWithOptions(runContext),
String.join(" ", "jbang", quiet ? "--quiet" : "", commands.getTaskRunner().toAbsolutePath(runContext, commands, relativeScriptPath.toString(), runContext.render(this.targetOS).as(TargetOS.class).orElse(null))),
runContext.render(this.targetOS).as(TargetOS.class).orElse(null)
);

return commands
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import io.kestra.core.models.annotations.Example;
import io.kestra.core.models.annotations.Plugin;
import io.kestra.core.models.annotations.PluginProperty;
import io.kestra.core.models.property.Property;
import io.kestra.core.models.tasks.runners.ScriptService;
import io.kestra.core.models.tasks.runners.TargetOS;
import io.kestra.core.runners.RunContext;
import io.kestra.plugin.scripts.exec.AbstractExecScript;
import io.kestra.plugin.scripts.exec.scripts.models.DockerOptions;
Expand Down Expand Up @@ -53,7 +55,7 @@ public class Commands extends AbstractExecScript {
private static final String DEFAULT_IMAGE = "julia";

@Builder.Default
protected String containerImage = DEFAULT_IMAGE;
protected Property<String> containerImage = Property.of(DEFAULT_IMAGE);

@Schema(
title = "The commands to run."
Expand All @@ -66,7 +68,7 @@ public class Commands extends AbstractExecScript {
protected DockerOptions injectDefaults(DockerOptions original) {
var builder = original.toBuilder();
if (original.getImage() == null) {
builder.image(this.getContainerImage());
builder.image(this.getContainerImage().toString());
}

return builder.build();
Expand All @@ -76,9 +78,9 @@ protected DockerOptions injectDefaults(DockerOptions original) {
public ScriptOutput run(RunContext runContext) throws Exception {
List<String> commandsArgs = ScriptService.scriptCommands(
this.interpreter,
getBeforeCommandsWithOptions(),
getBeforeCommandsWithOptions(runContext),
this.commands,
this.targetOS
runContext.render(this.targetOS).as(TargetOS.class).orElse(null)
);

return this.commands(runContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import io.kestra.core.models.annotations.Example;
import io.kestra.core.models.annotations.Plugin;
import io.kestra.core.models.annotations.PluginProperty;
import io.kestra.core.models.property.Property;
import io.kestra.core.models.tasks.runners.ScriptService;
import io.kestra.core.models.tasks.runners.TargetOS;
import io.kestra.core.runners.FilesService;
import io.kestra.core.runners.RunContext;
import io.kestra.plugin.scripts.exec.AbstractExecScript;
Expand Down Expand Up @@ -36,7 +38,7 @@
code = """
id: julia_script
namespace: company.team

tasks:
- id: script
type: io.kestra.plugin.scripts.julia.Script
Expand All @@ -56,7 +58,7 @@ public class Script extends AbstractExecScript {
private static final String DEFAULT_IMAGE = "julia";

@Builder.Default
protected String containerImage = DEFAULT_IMAGE;
protected Property<String> containerImage = Property.of(DEFAULT_IMAGE);

@Schema(
title = "The inline script content. This property is intended for the script file's content as a (multiline) string, not a path to a file. To run a command such as `julia myscript.jl`, use the `Commands` task instead."
Expand All @@ -70,7 +72,7 @@ public class Script extends AbstractExecScript {
protected DockerOptions injectDefaults(DockerOptions original) {
var builder = original.toBuilder();
if (original.getImage() == null) {
builder.image(this.getContainerImage());
builder.image(this.getContainerImage().toString());
}

return builder.build();
Expand All @@ -91,9 +93,9 @@ public ScriptOutput run(RunContext runContext) throws Exception {

List<String> commandsArgs = ScriptService.scriptCommands(
this.interpreter,
getBeforeCommandsWithOptions(),
String.join(" ", "julia", commands.getTaskRunner().toAbsolutePath(runContext, commands, relativeScriptPath.toString(), this.targetOS)),
this.targetOS
getBeforeCommandsWithOptions(runContext),
String.join(" ", "julia", commands.getTaskRunner().toAbsolutePath(runContext, commands, relativeScriptPath.toString(), runContext.render(this.targetOS).as(TargetOS.class).orElse(null))),
runContext.render(this.targetOS).as(TargetOS.class).orElse(null)
);

return commands
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import io.kestra.core.models.annotations.Example;
import io.kestra.core.models.annotations.Plugin;
import io.kestra.core.models.annotations.PluginProperty;
import io.kestra.core.models.property.Property;
import io.kestra.core.models.tasks.runners.ScriptService;
import io.kestra.core.models.tasks.runners.TargetOS;
import io.kestra.core.runners.RunContext;
import io.kestra.plugin.scripts.exec.AbstractExecScript;
import io.kestra.plugin.scripts.exec.scripts.models.DockerOptions;
Expand Down Expand Up @@ -50,7 +52,7 @@ public class Commands extends AbstractExecScript {
private static final String DEFAULT_IMAGE = "node";

@Builder.Default
protected String containerImage = DEFAULT_IMAGE;
protected Property<String> containerImage = Property.of(DEFAULT_IMAGE);

@Schema(
title = "The commands to run."
Expand All @@ -63,7 +65,7 @@ public class Commands extends AbstractExecScript {
protected DockerOptions injectDefaults(DockerOptions original) {
var builder = original.toBuilder();
if (original.getImage() == null) {
builder.image(this.getContainerImage());
builder.image(this.getContainerImage().toString());
}

return builder.build();
Expand All @@ -73,9 +75,9 @@ protected DockerOptions injectDefaults(DockerOptions original) {
public ScriptOutput run(RunContext runContext) throws Exception {
List<String> commandsArgs = ScriptService.scriptCommands(
this.interpreter,
getBeforeCommandsWithOptions(),
getBeforeCommandsWithOptions(runContext),
this.commands,
this.targetOS
runContext.render(this.targetOS).as(TargetOS.class).orElse(null)
);

return this.commands(runContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import io.kestra.core.models.annotations.Example;
import io.kestra.core.models.annotations.Plugin;
import io.kestra.core.models.annotations.PluginProperty;
import io.kestra.core.models.property.Property;
import io.kestra.core.models.tasks.runners.ScriptService;
import io.kestra.core.models.tasks.runners.TargetOS;
import io.kestra.core.runners.FilesService;
import io.kestra.core.runners.RunContext;
import io.kestra.plugin.scripts.exec.AbstractExecScript;
Expand Down Expand Up @@ -51,14 +53,14 @@
@Example(
full = true,
title = """
If you want to generate files in your script to make them available for download and use in downstream tasks, you can leverage the `{{ outputDir }}` variable. Files stored in that directory will be persisted in Kestra's internal storage. To access this output in downstream tasks, use the syntax `{{ outputs.yourTaskId.outputFiles['yourFileName.fileExtension'] }}`.
If you want to generate files in your script to make them available for download and use in downstream tasks, you can leverage the `{{ outputDir }}` variable. Files stored in that directory will be persisted in Kestra's internal storage. To access this output in downstream tasks, use the syntax `{{ outputs.yourTaskId.outputFiles['yourFileName.fileExtension'] }}`.

Alternatively, instead of the `{{ outputDir }}` variable, you could use the `outputFiles` property to output files from your script. You can access those files in downstream tasks using the same syntax `{{ outputs.yourTaskId.outputFiles['yourFileName.fileExtension'] }}`, and you can download the files from the UI's Output tab.
""",
code = """
id: nodejs_script
namespace: company.team

tasks:
- id: node
type: io.kestra.plugin.scripts.node.Script
Expand Down Expand Up @@ -113,15 +115,15 @@

fs.writeFileSync('{{ outputDir }}/orders.csv', csvData);

console.log('Orders saved to orders.csv');
console.log('Orders saved to orders.csv');
"""
)
)
})
public class Script extends AbstractExecScript {
private static final String DEFAULT_IMAGE = "node";

@Builder.Default
protected String containerImage = DEFAULT_IMAGE;
protected Property<String> containerImage = Property.of(DEFAULT_IMAGE);

@Schema(
title = "The inline script content. This property is intended for the script file's content as a (multiline) string, not a path to a file. To run a command from a file such as `bash myscript.sh` or `python myscript.py`, use the `Commands` task instead."
Expand All @@ -135,7 +137,7 @@ public class Script extends AbstractExecScript {
protected DockerOptions injectDefaults(DockerOptions original) {
var builder = original.toBuilder();
if (original.getImage() == null) {
builder.image(this.getContainerImage());
builder.image(this.getContainerImage().toString());
}

return builder.build();
Expand All @@ -156,9 +158,9 @@ public ScriptOutput run(RunContext runContext) throws Exception {

List<String> commandsArgs = ScriptService.scriptCommands(
this.interpreter,
getBeforeCommandsWithOptions(),
String.join(" ", "node", commands.getTaskRunner().toAbsolutePath(runContext, commands, relativeScriptPath.toString(), this.targetOS)),
this.targetOS
getBeforeCommandsWithOptions(runContext),
String.join(" ", "node", commands.getTaskRunner().toAbsolutePath(runContext, commands, relativeScriptPath.toString(), runContext.render(this.targetOS).as(TargetOS.class).orElse(null))),
runContext.render(this.targetOS).as(TargetOS.class).orElse(null)
);

return commands
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import io.kestra.core.models.annotations.Example;
import io.kestra.core.models.annotations.Plugin;
import io.kestra.core.models.annotations.PluginProperty;
import io.kestra.core.models.property.Property;
import io.kestra.core.models.tasks.runners.ScriptService;
import io.kestra.core.models.tasks.runners.TargetOS;
import io.kestra.core.runners.RunContext;
import io.kestra.plugin.scripts.exec.AbstractExecScript;
import io.kestra.plugin.scripts.exec.scripts.models.DockerOptions;
Expand Down Expand Up @@ -47,7 +49,7 @@ public class Commands extends AbstractExecScript {
private static final String DEFAULT_IMAGE = "ghcr.io/kestra-io/powershell:latest";

@Builder.Default
protected String containerImage = DEFAULT_IMAGE;
protected Property<String> containerImage = Property.of(DEFAULT_IMAGE);

@Schema(
title = "The commands to run."
Expand All @@ -68,7 +70,7 @@ public class Commands extends AbstractExecScript {
protected DockerOptions injectDefaults(DockerOptions original) {
var builder = original.toBuilder();
if (original.getImage() == null) {
builder.image(this.getContainerImage());
builder.image(this.getContainerImage().toString());
}
if (original.getEntryPoint() == null) {
builder.entryPoint(Collections.emptyList());
Expand All @@ -81,9 +83,9 @@ protected DockerOptions injectDefaults(DockerOptions original) {
public ScriptOutput run(RunContext runContext) throws Exception {
List<String> commandsArgs = ScriptService.scriptCommands(
this.interpreter,
getBeforeCommandsWithOptions(),
getBeforeCommandsWithOptions(runContext),
this.commands,
this.targetOS
runContext.render(this.targetOS).as(TargetOS.class).orElse(null)
);

return this.commands(runContext)
Expand Down
Loading
Loading