- Examples
- Printing "Hello World"
- Executing Conditional Steps
- Writing to a File
- Passing Output to Next Step
- Running a Docker Container
- Executing Commands over SSH
- Sending HTTP Requests
- Querying JSON Data with jq
- Formatting JSON Data with jq
- Outputting Raw Values with jq
- Sending Email Notifications
- Sending Email
- Customizing Signal Handling on Stop
This example demonstrates how to print "hello world" to the log.
name: hello world
steps:
- name: "hello"
command: echo hello world
- name: "done"
command: echo done!
depends:
- "1"
This example demonstrates how to execute conditional steps.
params: foo
steps:
- name: "step1"
command: echo start
- name: "foo"
command: echo foo
depends:
- "step1"
preconditions:
- condition: "$1"
expected: foo
- name: "bar"
command: echo bar
depends:
- "step1"
preconditions:
- condition: "$1"
expected: bar
This example demonstrates how to write text to a file.
steps:
- name: write hello to '/tmp/hello.txt'
command: echo hello
stdout: /tmp/hello.txt
This example demonstrates how to pass output from one step to the next. It will print "hello world" to the log.
steps:
- name: pass 'hello'
command: echo hello
output: OUT1
- name: output 'hello world'
command: bash
script: |
echo $OUT1 world
depends:
- pass 'hello'
This example demonstrates how to run a Docker container.
steps:
- name: deno_hello_world
executor:
type: docker
config:
image: "denoland/deno:1.10.3"
host:
autoRemove: true
command: run https://examples.deno.land/hello-world.ts
Example log output:
You can configure the Docker host with the environment variable DOCKER_HOST
.
For example:
env:
- DOCKER_HOST : "tcp://XXX.XXX.XXX.XXX:2375"
steps:
- name: deno_hello_world
executor:
type: docker
config:
image: "denoland/deno:1.10.3"
autoRemove: true
command: run https://examples.deno.land/hello-world.ts
You can config the Docker container (e.g., volumes
, env
, etc) by passing more detailed options.
For example:
steps:
- name: deno_hello_world
executor:
type: docker
config:
image: "denoland/deno:1.10.3"
container:
volumes:
/app:/app:
env:
- FOO=BAR
host:
autoRemove: true
command: run https://examples.deno.land/hello-world.ts
See the Docker's API documentation for all available options.
- For
container
, see ContainerConfig. - For
host
, see HostConfig.
If you are running dagu
using a container, you need the setup below.
- Run a
socat
conainer with the command below.
docker run -v /var/run/docker.sock:/var/run/docker.sock -p 2376:2375 bobrik/socat TCP4-LISTEN:2375,fork,reuseaddr UNIX-CONNECT:/var/run/docker.sock
- Then you can set the
DOCKER_HOST
environment as follows.
env:
- DOCKER_HOST : "tcp://host.docker.internal:2376"
steps:
- name: deno_hello_world
executor:
type: docker
config:
image: "denoland/deno:1.10.3"
autoRemove: true
command: run https://examples.deno.land/hello-world.ts
For more details, see this page.
steps:
- name: print ec2 instance id
executor:
type: ssh
config:
user: ec2-user
ip: "XXX.XXX.XXX.XXX"
key: /Users/XXXXX/.ssh/prod-ec2instance-keypair.pem
StrictHostKeyChecking: false
command: ec2-metadata -i
steps:
- name: get fake json data
executor: http
command: GET https://jsonplaceholder.typicode.com/comments
script: |
{
"timeout": 10,
"headers": {},
"query": {
"postId": "1"
},
"body": ""
}
steps:
- name: run query
executor: jq
command: '{(.id): .["10"].b}'
script: |
{"id": "sample", "10": {"b": 42}}
log output:
{
"sample": 42
}
steps:
- name: format json
executor: jq
script: |
{"id": "sample", "10": {"b": 42}}
log output:
{
"10": {
"b": 42
},
"id": "sample"
}
steps:
- name: output raw value
executor:
type: jq
config:
raw: true
command: '.id'
script: |
{"id": "sample", "10": {"b": 42}}
log output:
sample
steps:
- name: Sending Email on Finish or Error
command: echo "hello world"
mailOn:
failure: true
success: true
smtp:
host: "smtp.foo.bar"
port: "587"
username: "<username>"
password: "<password>"
errorMail:
from: "[email protected]"
to: "[email protected]"
prefix: "[Error]"
infoMail:
from: "[email protected]"
to: "[email protected]"
prefix: "[Info]"
smtp:
host: "smtp.foo.bar"
port: "587"
username: "<username>"
password: "<password>"
steps:
- name: step1
executor:
type: mail
config:
to: <to address>
from: <from address>
subject: "Urgent Request: Help Me Find My Sanity"
message: |
I'm in a bit of a pickle.
I seem to have lost my sanity somewhere between my third cup of coffee and my fourth Zoom meeting of the day.
If you see it lying around, please let me know.
Thanks for your help!
Best,
steps:
- name: step1
command: bash
script: |
for s in {1..64}; do trap "echo trap $s" $s; done
sleep 60
signalOnStop: "SIGINT"
In the above example, the script waits indefinitely for a SIGINT
signal, but a custom handler is defined to print a message and exit with code 130 when the signal is received. The signals section is used to configure dagu to send SIGINT
signals when the user stops the pipeline.