/dad

Small configuration management tool for Clojure

Primary LanguageClojureEclipse Public License 2.0EPL-2.0

Dad

badge dad

My father is a greate chef :)

Dad is a small configuration management tool for Clojure. This project is heavily inspired by mitamae.

Concept

  • Easy to start — Download single binary and run it.

  • Minimum to remember — May not write code for Dad often

Getting Started

Download binary from releases.

# Download latest dad to the current working directory
curl -L https://raw.githubusercontent.com/liquidz/dad/master/script/download | bash
./dad your_task.clj

Here is a example to install Clojure command line tools.

#!/usr/bin/env dad --no-color --dry-run

(package ["curl" "rlwrap"])

;; You can define function as you like
(defn curl [m]
  (let [{:keys [path url]} m]
    ;; `file-exists?` is a built-in function in dad.
    (when (and (not (file-exists? path))
               (string? url))
      (execute (str "curl -sfLo " path " " url)))))

(curl {:path "/tmp/install.sh"
       :url "https://download.clojure.org/install/linux-install-1.10.1.489.sh"})

(file {:path "/tmp/install.sh" :mode "755"})
(execute {:cwd "/tmp" :command "./install.sh"})
(file {:path "/tmp/install.sh" :action :delete})

Supports

Example

Reference

Note
You can refer all documents in codes. (evaluate (dad/doc) or (help))

Built-in vars / functions

Name Var/Func Description

dad/doc

Func

Print dad documents.

dad/env

Var

Map of environmental variables.

dad/file-exists?

Func

Return true if the specified path exists.

dad/os-type

Func

OS name string such as "linux" or "mac".

dad/render

Func

Render a template string with a data.

help

Func

Alias for dad/doc.

load-file

Func

Load another recipe file.

See sci/impl/namespaces.cljc for other core functions.

Resources

Resources are called like follows. <main-arg> will be associated to the main key for the resource.

(resource-name {:key :value ...})
(resource-name <main-arg> {:key :value ...})

;; E.g. following codes are equivalent because `directory` resource's main key is `path`.
(directory "foo/bar" {:owner "alice"})
(directory {:path "foo/bar" :owner "alice"})
Resource name Description

directory

Create directories.

download

Download a file from remote host.

execute

Execute a shell command.

file

Create a file.

git

Execute git command.

link

Create a symbolic link.

package

Install packages.

template

Create a text file from the specified template files.

nREPL

Dad provides nREPL server that does not affect your environment. (same as --dry-run option) Dad’s nREPL server uses random empty port by default.

$ dad --nrepl
Started nREPL server at 0.0.0.0:50057

If you’d like to specify port number, use --port option.

$ dad --nrepl --port=1667
Started nREPL server at 0.0.0.0:1667

After starting nREPL server, you can connect from your client like CIDER, vim-iced, and so on.

E.g. vim-iced connection
:IcedConnect 1667

REPL

Dad also provides REPL mode that does not affect your environment. (same as --dry-run option)

$ dad --repl

user=> (println "hello from dad")
hello from dad
nil

user=> (+ 1 2 3)
6

user=> (package "sl")
apt-update [sl] ... will change
package-install [sl] ... will change

user=> (package "sl" {:action :uninstall})
package-uninstall [sl] ... WILL NOT change

License

Copyright © 2019-2020 Masashi Iizuka

This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0.

This Source Code may also be made available under the following Secondary Licenses when the conditions for such availability set forth in the Eclipse Public License, v. 2.0 are satisfied: GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version, with the GNU Classpath Exception which is available at https://www.gnu.org/software/classpath/license.html.