Skip to content

dag: Support Go template syntax #738

Open
@yottahmd

Description

@yottahmd

Overview
Enhance Dagu's configuration files with Go template support, enabling dynamic content generation and variable substitution using Go's template/text package. Additionally, incorporate the rich set of utility functions from sprig to provide powerful template operations.

Features

  • Full Go template syntax support in most configuration fields
  • Access to all sprig template functions (string operations, math, lists, etc.)
  • Variable substitution across configuration
  • Environment variable support
  • Built-in helper functions

Example Usage

Basic variable substitution:

name: example
params:
  NAME: "World"
  GREETING: "Hello"
steps:
  - name: simple-greeting
    command: "{{.GREETING}}, {{.NAME}}!"

Using sprig functions:

name: templating-example
params:
  USER: "alice"
  ENV: "production"
steps:
  - name: conditional-step
    command: |
      {{- if eq .ENV "production" -}}
      deploy --production --user {{.USER | upper}}
      {{- else -}}
      deploy --staging --user {{.USER | lower}}
      {{- end -}}

  - name: date-based-task
    command: "backup-{{now | date \"2006-01-02\"}}.tar.gz"

Environment variables can be accessed using the env function:

steps:
  - name: env-aware
    command: "deploy --token {{env "API_TOKEN"}}"

This enhancement would make Dagu configurations more flexible and powerful, allowing for dynamic content generation based on variables, environment, and runtime conditions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature to be implemented

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions