dagu icon indicating copy to clipboard operation
dagu copied to clipboard

SSH executor

Open fishnux opened this issue 4 years ago • 6 comments

Similar to issue https://github.com/yohamta/dagu/issues/298 for creating a container executor, I propose the creation of a SSH executor to run tasks on remote servers

Current workaround is to execute ssh command

fishnux avatar Sep 05 '22 23:09 fishnux

Thanks for the suggestion! That sounds like a really useful idea. I'm just trying to figure out how to make it a generic feature that would work for a variety of Executors, including SSH, Docker, and HTTP hooks. A naive way might be something like this. However, this approach might seem a bit complicated with more fields required for various Executors. Any ideas?

steps:
  - name: step1
    executor: ssh
    host: xxx
    port: 22
    key: /home/dagu/.ssh/xxx
    command: java /home/app/app.jar
  - name: step2
    executor: docker
    context: /home/app/Dockerfile
    command: node app.js
    depends:
       - step1

yohamta0 avatar Sep 06 '22 00:09 yohamta0

I think one way might be to extend the Executor interface.

package dag
type DAG struct {
  // ...
  Executor: string
  ExecutorConfig: map[string]interface{}
}

package executor
type Executor interface {
  SetStdout(out io.Writer)
  SetStderr(out io.Writer)
  Kill(sig os.Signal) error
  Run() error
  // For loading Executor specific config
  LoadConfig(dag *dag.DAG, execConfig map[string]interface{}) error
}

In this case, the DAG is defined as follows.

steps:
  - name: step1
    executor: ssh
    executorConfig:
      host: xxx
      port: 22
      key: /home/dagu/.ssh/xxx
    command: java /home/app/app.jar
  - name: step2
    executor: docker
    executorConfig:
      context: /home/app/Dockerfile
    command: node app.js
    depends:
       - step1

This will work for a variety of Executors.

yohamta0 avatar Sep 06 '22 02:09 yohamta0

Your proposed solution sounds nice! 👍

On a side-note, food for thought: what if I want to run a Docker container (executor) through SSH? 😮

fishnux avatar Sep 06 '22 05:09 fishnux

Thanks! In that case, I thought we could set DOCKER_HOST environ variable to run containers on a remote server via ssh :)

steps:
  - name: step1
    executor: docker
    env:
     - DOCKER_HOST: ssh://[email protected]
    executorConfig:
      context: /home/app/Dockerfile
    command: node app.js

Let's see if it would work.

Also, let's add the host field in the executor config.

steps:
  - name: step1
    executor: docker
    executorConfig:
      context: /home/app/Dockerfile
      host: ssh://[email protected]
    command: node app.js

yohamta0 avatar Sep 06 '22 06:09 yohamta0

Now I think we can implement SSH executor. Here's a gist that might be useful. https://gist.github.com/josephspurrier/e83bcdbf9e6865500004

yohamta0 avatar Sep 10 '22 02:09 yohamta0

It is now implemented in v1.9.0 but I think it will need further improvements. readme: https://github.com/yohamta/dagu#ssh-executor

yohamta0 avatar Oct 10 '22 11:10 yohamta0