Skip to content

Commit

Permalink
feat(script): move plugin-script library to Kestra itself
Browse files Browse the repository at this point in the history
  • Loading branch information
loicmathieu committed Apr 30, 2024
1 parent a35dc85 commit e65e0a0
Show file tree
Hide file tree
Showing 22 changed files with 1,488 additions and 1 deletion.
1 change: 1 addition & 0 deletions cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ dependencies {

// modules
implementation project(":core")
implementation project(":script")

implementation project(":repository-memory")

Expand Down
18 changes: 18 additions & 0 deletions script/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
dependencies {
// Kestra
implementation project(':core')
annotationProcessor project(':processor')

implementation platform("io.micronaut.platform:micronaut-platform:$micronautVersion")
implementation 'io.micronaut:micronaut-context'

implementation ('com.github.docker-java:docker-java:3.3.6') {
exclude group: 'com.github.docker-java', module: 'docker-java-transport-jersey'
}
implementation 'com.github.docker-java:docker-java-transport-zerodep:3.3.6'

testImplementation project(':core').sourceSets.test.output
testImplementation project(':storage-local')
testImplementation project(':repository-memory')
testImplementation project(':runner-memory')
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package io.kestra.plugin.scripts.exec.scripts.models;

import io.kestra.core.models.annotations.PluginProperty;
import io.kestra.plugin.scripts.runner.docker.*;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.util.List;
import java.util.Map;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;

@SuperBuilder(toBuilder = true)
@NoArgsConstructor
@Getter
public class DockerOptions {
@Schema(
title = "Docker API URI."
)
@PluginProperty(dynamic = true)
private String host;

@Schema(
title = "Docker configuration file.",
description = "Docker configuration file that can set access credentials to private container registries. Usually located in `~/.docker/config.json`.",
anyOf = {String.class, Map.class}
)
@PluginProperty(dynamic = true)
private Object config;

@Schema(
title = "Credentials for a private container registry."
)
@PluginProperty(dynamic = true)
private Credentials credentials;

@Schema(
title = "Docker image to use."
)
@PluginProperty(dynamic = true)
@NotNull
@NotEmpty
protected String image;

@Schema(
title = "User in the Docker container."
)
@PluginProperty(dynamic = true)
protected String user;

@Schema(
title = "Docker entrypoint to use."
)
@PluginProperty(dynamic = true)
protected List<String> entryPoint;

@Schema(
title = "Extra hostname mappings to the container network interface configuration."
)
@PluginProperty(dynamic = true)
protected List<String> extraHosts;

@Schema(
title = "Docker network mode to use e.g. `host`, `none`, etc."
)
@PluginProperty(dynamic = true)
protected String networkMode;

@Schema(
title = "List of volumes to mount.",
description = "Must be a valid mount expression as string, example : `/home/user:/app`.\n\n" +
"Volumes mount are disabled by default for security reasons; you must enable them on server configuration by setting `kestra.tasks.scripts.docker.volume-enabled` to `true`."
)
@PluginProperty(dynamic = true)
protected List<String> volumes;

@PluginProperty
@Builder.Default
protected PullPolicy pullPolicy = PullPolicy.ALWAYS;

@Schema(
title = "A list of device requests to be sent to device drivers."
)
@PluginProperty
protected List<DeviceRequest> deviceRequests;

@Schema(
title = "Limits the CPU usage to a given maximum threshold value.",
description = "By default, each container’s access to the host machine’s CPU cycles is unlimited. " +
"You can set various constraints to limit a given container’s access to the host machine’s CPU cycles."
)
@PluginProperty
protected Cpu cpu;

@Schema(
title = "Limits memory usage to a given maximum threshold value.",
description = "Docker can enforce hard memory limits, which allow the container to use no more than a " +
"given amount of user or system memory, or soft limits, which allow the container to use as much " +
"memory as it needs unless certain conditions are met, such as when the kernel detects low memory " +
"or contention on the host machine. Some of these options have different effects when used alone or " +
"when more than one option is set."
)
@PluginProperty
protected Memory memory;

@Schema(
title = "Size of `/dev/shm` in bytes.",
description = "The size must be greater than 0. If omitted, the system uses 64MB."
)
@PluginProperty(dynamic = true)
private String shmSize;

@Deprecated
public void setDockerHost(String host) {
this.host = host;
}

@Deprecated
public void setDockerConfig(String config) {
this.config = config;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.kestra.plugin.scripts.exec.scripts.models;

public enum RunnerType {
PROCESS,
DOCKER
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package io.kestra.plugin.scripts.exec.scripts.models;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.kestra.core.models.annotations.PluginProperty;
import io.kestra.core.models.flows.State;
import io.kestra.core.models.tasks.Output;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Getter;

import java.net.URI;
import java.util.Map;
import java.util.Optional;
import jakarta.validation.constraints.NotNull;

@Builder
@Getter
public class ScriptOutput implements Output {
@Schema(
title = "The value extracted from the output of the executed `commands`."
)
private final Map<String, Object> vars;

@Schema(
title = "The exit code of the entire flow execution."
)
@NotNull
private final int exitCode;

@Schema(
title = "The output files' URIs in Kestra's internal storage."
)
@PluginProperty(additionalProperties = URI.class)
private final Map<String, URI> outputFiles;

@JsonIgnore
private final int stdOutLineCount;

@JsonIgnore
private final int stdErrLineCount;

@JsonIgnore
private Boolean warningOnStdErr;

@Override
public Optional<State.Type> finalState() {
return this.warningOnStdErr != null && this.warningOnStdErr && this.stdErrLineCount > 0 ? Optional.of(State.Type.WARNING) : Output.super.finalState();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.kestra.plugin.scripts.exec.scripts.models;

import io.kestra.core.models.executions.AbstractMetricEntry;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.Map;

@NoArgsConstructor
@Data
public class ScriptOutputFormat<T> {
private Map<String, Object> outputs;
private List<AbstractMetricEntry<T>> metrics;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.kestra.plugin.scripts.exec.scripts.runners;

/**
* @deprecated use {@link io.kestra.core.models.tasks.runners.AbstractLogConsumer} instead.
*/
@Deprecated
public abstract class AbstractLogConsumer extends io.kestra.core.models.tasks.runners.AbstractLogConsumer {
}
Loading

0 comments on commit e65e0a0

Please sign in to comment.