Skip to content
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
15 changes: 9 additions & 6 deletions src/main/java/io/kestra/plugin/dbt/cli/AbstractDbt.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public void setDockerOptions(DockerOptions dockerOptions) {

private List<String> outputFiles;

protected abstract java.util.List<String> dbtCommands(RunContext runContext, Path workingDirectory) throws IllegalVariableEvaluationException;
protected abstract java.util.List<String> dbtCommands(RunContext runContext) throws IllegalVariableEvaluationException;

@Override
public ScriptOutput run(RunContext runContext) throws Exception {
Expand All @@ -170,7 +170,8 @@ public ScriptOutput run(RunContext runContext) throws Exception {
public void accept(String line, Boolean isStdErr) {
LogService.parse(runContext, line);
}
});
})
.withEnableOutputDirectory(true); //force output files on task runners
Path workingDirectory = commandsWrapper.getWorkingDirectory();

if (profiles != null && !profiles.isEmpty()) {
Expand All @@ -188,7 +189,7 @@ public void accept(String line, Boolean isStdErr) {
List<String> commandsArgs = ScriptService.scriptCommands(
List.of("/bin/sh", "-c"),
null,
List.of(createDbtCommand(runContext, workingDirectory))
List.of(createDbtCommand(runContext))
);

ScriptOutput run = commandsWrapper
Expand All @@ -204,7 +205,7 @@ public void accept(String line, Boolean isStdErr) {
return run;
}

private String createDbtCommand(RunContext runContext, Path workingDirectory) throws IllegalVariableEvaluationException {
private String createDbtCommand(RunContext runContext) throws IllegalVariableEvaluationException {
List<String> commands = new ArrayList<>(List.of(
runContext.render(dbtPath),
"--log-format json"
Expand All @@ -222,10 +223,12 @@ private String createDbtCommand(RunContext runContext, Path workingDirectory) th
commands.add("--warn-error");
}

commands.addAll(dbtCommands(runContext, workingDirectory));
commands.addAll(dbtCommands(runContext));

if (this.projectDir != null) {
commands.add("--project-dir " + runContext.render(this.projectDir));
commands.add("--project-dir {{" + ScriptService.VAR_WORKING_DIR + "}}" + runContext.render(this.projectDir));
} else {
commands.add("--project-dir {{" + ScriptService.VAR_WORKING_DIR + "}}");
}

return String.join(" ", commands);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/io/kestra/plugin/dbt/cli/AbstractRun.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.kestra.core.exceptions.IllegalVariableEvaluationException;
import io.kestra.core.models.annotations.PluginProperty;
import io.kestra.core.models.tasks.runners.ScriptService;
import io.kestra.core.runners.RunContext;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
Expand Down Expand Up @@ -57,10 +58,10 @@ public abstract class AbstractRun extends AbstractDbt {
abstract protected String dbtCommand();

@Override
protected java.util.List<String> dbtCommands(RunContext runContext, Path workingDirectory) throws IllegalVariableEvaluationException {
protected java.util.List<String> dbtCommands(RunContext runContext) throws IllegalVariableEvaluationException {
java.util.List<String> commands = new ArrayList<>(java.util.List.of(
this.dbtCommand(),
"--profiles-dir " + workingDirectory.resolve(".profile").toAbsolutePath()));
"--profiles-dir {{" + ScriptService.VAR_WORKING_DIR + "}}/.profile"));

if (this.thread != null) {
commands.add("--threads " + this.thread);
Expand Down
7 changes: 3 additions & 4 deletions src/test/java/io/kestra/plugin/dbt/cli/BuildTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,14 @@ void run() throws Exception {
env.put("GOOGLE_APPLICATION_CREDENTIALS", runContext.workingDir().resolve(Path.of("sa.json")).toString());
Build task = Build.builder()
.thread(8)
.projectDir(runContext.workingDir().path().toString())
.env(env)
.build();

ScriptOutput runOutput = task.run(runContext);

assertThat(runOutput.getExitCode(), is(0));
//FIXME, also assert on dynamic tasks generation
// assertTrue(runOutput.getOutputFiles().containsKey("run_results.json"));
// assertTrue(runOutput.getOutputFiles().containsKey("manifest.json"));
assertTrue(runOutput.getOutputFiles().containsKey("run_results.json"));
assertTrue(runOutput.getOutputFiles().containsKey("manifest.json"));
assertThat(runContext.dynamicWorkerResults(), hasSize(13));
}
}