Skip to content

Git Sync ​

Git Sync keeps the server's workflows in a Git repository. A pull copies DAG files, the scripts and templates they use, Wiki pages, Wiki attachments, and business calendars from a branch into Dagu. A publish commits edits made in Dagu and pushes them to the same branch.

A pull never overwrites a file that was changed in Dagu. That file becomes a conflict for you to resolve.

Git Sync page with DAGs, calendars, Wiki pages, attachments, and supporting filesGit Sync page with DAGs, calendars, Wiki pages, attachments, and supporting files

Set Up ​

  1. Add git_sync to config.yaml:

    yaml
    git_sync:
      enabled: true
      repository: github.com/acme/automation
      branch: main
      path: workflows        # omit to use the repository root
      auth:
        type: token
        token_file: /run/secrets/git-token
      auto_sync:
        enabled: true
        interval: 300        # seconds
  2. Restart the server.

  3. Pull once and check the result:

    bash
    dagu sync pull
    dagu sync status

With auto_sync.enabled, the server pulls when it starts and then every interval seconds. Without it, pull from the Git Sync page or with dagu sync pull.

Repository Layout ​

Dagu reads only the files under git_sync.path and places each one by its location:

text
repository/
└── workflows/                    git_sync.path
    ├── daily-report.yaml         → paths.dags_dir
    ├── scripts/generate.py       → paths.dags_dir/scripts
    ├── calendars/jp-banking.yaml → paths.calendars_dir
    └── wiki/                     → paths.wiki_dir
        ├── operations/runbook.md
        └── .attachments/…

Each synced file is an item with an ID and a kind. The web UI, dagu sync, and the REST API name items by ID:

Repository fileKindItem ID
daily-report.yamldagdaily-report
scripts/generate.pyfilescripts/generate.py
calendars/jp-banking.yamlcalendarcalendars/jp-banking
wiki/operations/runbook.mddocwiki/operations/runbook
wiki/.attachments/operations/runbook/chart.pngdoc-assetwiki/.attachments/operations/runbook/chart.png

DAG, calendar, and Wiki page IDs drop the .yaml, .yml, or .md extension. Other IDs keep the full path.

  • DAGs: .yaml and .yml files, except base.yaml, which is never synced.
  • Calendars: calendars/<name>.yaml directly under the path. Deeper files under calendars/ are DAGs or supporting files.
  • Wiki: Markdown files under wiki/. A repository that has docs/ and no wiki/ keeps using docs/. A repository with both fails to pull.
  • Supporting files: every other regular file, such as scripts, SQL, templates, certificates, and binaries. The executable bit is kept.
  • Not synced: symlinks, submodules, and files outside git_sync.path.

Two files that map to the same ID, such as report.yaml and report.yml, fail the pull before anything is written.

Set the path in a shared repository

A pull copies every supporting file under git_sync.path into paths.dags_dir. In a repository that holds other code, set path to the workflows directory.

Pull, Edit, and Publish ​

StatusMeaning
syncedMatches the last pulled or published version.
modifiedChanged in Dagu since then.
untrackedCreated in Dagu and never published.
conflictChanged in Dagu and in the repository, or changed in Dagu and deleted in the repository.
missingTracked, but the local file is gone.

On a pull:

  • Files that are synced take the repository's version.
  • modified files keep the local edit. If the repository also changed them, they become conflict.
  • A file deleted in the repository is deleted locally when it is unchanged, and becomes conflict when it was edited. Empty directories left behind are removed.
  • untracked files are left alone.

To publish, select items on the Git Sync page, or run dagu sync publish. Dagu commits them as commit.author_name and pushes to branch. If the push fails, the commit is rolled back.

To resolve a conflict, compare the two versions in the diff view, then either discard the local copy to take the repository's version, or publish with force to replace the repository's version.

Dagu finds new DAG files, Wiki pages, attachments, and calendars created on the server. It does not find new supporting files. Commit those to the repository and pull.

Read-Only Servers ​

Set push_enabled: false on a server that should only follow a branch, such as production:

yaml
git_sync:
  enabled: true
  repository: github.com/acme/automation
  branch: production
  push_enabled: false
  auto_sync:
    enabled: true
    interval: 60

The server then refuses every change to DAGs and calendars from the web UI and API, and every Git Sync action there, including pull. It takes new commits through auto-sync, and dagu sync pull on the server host pulls on demand. Promote reviewed commits between branches as described in Multi-Environment Deployments.

Supporting Files in Workflows ​

Set working_dir: . so a step runs from the directory that holds the DAG file:

yaml
working_dir: .

steps:
  - id: generate
    run: python scripts/generate.py --template templates/summary.html

On a distributed worker, the files are not there. List them under dependencies so the worker receives a copy:

yaml
steps:
  - id: generate
    run: python scripts/generate.py --template templates/summary.html
    dependencies:
      - scripts/generate.py
      - templates/summary.html

The worker still needs the runtime, such as Python. See File Dependencies.

Node Inventories ​

Set git_sync.inventory_path to keep the server's node inventories in the repository. The path starts at the repository root, not at git_sync.path. The file is a JSON array in the format that dagu nodes export prints.

text
repository/
├── workflows/              git_sync.path
│   └── deploy.yaml
└── inventories/
    ├── staging.json        inventory_path on the staging server
    └── production.json     inventory_path on the production server

Each server names its own file, so staging and production run the same workflows against different hosts. To start, export the current inventories and commit the file:

bash
dagu nodes export > inventories/production.json

After every pull, Dagu makes the inventories match the file:

  • An inventory in the file replaces the one with the same name, compared without case, and keeps its ID. A new name creates an inventory.
  • An inventory that is not in the file is deleted.
  • The whole file is checked first, as dagu nodes import checks it. If the file is invalid or missing, the pull fails and no inventory changes.
  • The check runs even when the repository has not changed, so the next pull undoes edits made on the Nodes page or with dagu nodes. Edit the file instead.
  • Dagu never writes the file, and it is not a sync item.
  • Trusted host keys are not part of an inventory. Pin each node's key with host_key in the file. A node that keeps its name keeps any key already trusted for it.

dagu sync pull prints Node inventories updated when a pull changed them. Without inventory_path, Git Sync leaves the inventories alone.

Authentication ​

yaml
git_sync:
  repository: github.com/acme/automation
  auth:
    type: token
    token_file: /run/secrets/git-token   # or token: ${GITHUB_TOKEN}
yaml
git_sync:
  repository: git@github.com:acme/automation.git
  auth:
    type: ssh
    ssh_key_path: /home/dagu/.ssh/id_ed25519
    ssh_passphrase_file: /run/secrets/ssh-passphrase

A repository without a scheme, such as github.com/acme/automation, is cloned over HTTPS. Set ssh_passphrase_file only for a key that has a passphrase. For an SSH user other than git, put it in the URL: deploy@git.example.com:acme/automation.git.

token_file and ssh_passphrase_file read the secret from a file, such as a mounted Docker or Kubernetes secret. Do not set both forms of one secret. See Secrets From Files.

Configuration Reference ​

Every key has an environment variable: git_sync.auto_sync.interval is DAGU_GITSYNC_AUTOSYNC_INTERVAL, and git_sync.auth.token_file is DAGU_GITSYNC_AUTH_TOKEN_FILE.

KeyDefaultDescription
enabledfalseTurns on Git Sync.
repositorynonegithub.com/org/repo, or an https://, http://, ssh://, or git@ URL.
branchmainBranch to pull from and push to.
pathrepository rootSubdirectory that holds the Dagu files.
inventory_pathnoneJSON file of node inventories, from the repository root.
push_enabledtruefalse makes the server read-only.
auth.typenonetoken or ssh.
auth.token, auth.token_filenoneAccess token, or a file that holds it.
auth.ssh_key_pathnoneSSH private key.
auth.ssh_passphrase, auth.ssh_passphrase_filenonePassphrase of the key, or a file that holds it.
auto_sync.enabledfalsePull in the background while the server runs.
auto_sync.on_startuptrueWith auto-sync, pull when the server starts.
auto_sync.interval300Seconds between background pulls. 0 pulls only at startup.
commit.author_nameDaguAuthor of published commits.
commit.author_emaildagu@localhostAuthor email of published commits.

Permissions ​

Treat the repository as code that runs on the server. Review changes before they reach the synced branch, limit who can push to it, and keep secrets out of tracked files.

ActionRequires, when authentication is on
View status, diffs, and settingsAccess to all workspaces
Pull, publish, discard, move, delete, forget, clean upThe above, the developer role or higher, permissions.write_dags, and push_enabled: true
Change settings or test the connectionAdmin role

CLI and REST API ​

bash
dagu sync status
dagu sync pull
dagu sync publish daily-report -m "Update daily report"
dagu sync publish --all -m "Update automation files"
dagu sync discard scripts/generate.py
dagu sync mv scripts/generate.py scripts/render.py
dagu sync delete scripts/render.py -m "Remove report script"
dagu sync forget old-report   # drop the record of a missing item
dagu sync cleanup             # drop the records of all missing items

The commands work on the local server's directories and need git_sync.enabled. See CLI Reference for every flag, and REST API for the /api/v1/sync/* endpoints. In REST paths, URL-encode item IDs: scripts/report.py becomes scripts%2Freport.py.

Dagu is open source under the GNU General Public License v3.0.