Skip to content
This repository has been archived by the owner on Apr 3, 2023. It is now read-only.

maxadamski/ricecooker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rice Cooker 🍚

Rice Cooker is a bash configuration management framework. It allows you to abstract out the control flow of arbitrary blocks of code (modules), with a hierarchical approach, making multi-system configurations easy to manage and modify.

Motivation

Reapplying configuration should be fast. For example, if you only change fonts or colors, there is no need to copy other system configuration - you only run modules related to the look and feel. Being just a bash script, Rice Cooker can be sourced in your shell (assuming bash or zsh) for rapid configuration development.

The philosophy of Rice Cooker is to give the user full control over their scripts. Only module names are "convention over configuration", everything else is done explicitly, although without needless verbosity. By passing your commands to rice::exec (or a shorter alias of choice) control over code execution in modules is given, and features like transactions and extensive logging are made possible.

All features are opt-in, so only ones you find useful may be picked. Common operations like templating are also provided to automate the boring stuff, with more planned for the future.

Features

  • Define system configuration in a more "declarative" manner
  • The configuration is a bash file
  • Bootstrap multiple systems using the same configuration
  • Share modules (parts of the configuration) between different systems
  • Flexible module execution
  • Use ricecooker functions interactively from bash
  • Use a template engine (mustache by default) to keep your configuration DRY
  • Works great with version control
  • Easy-to-use CLI utility for managing and applying configurations (built into the configuration)

Future features (sorted by priority)

  • Convenient functions for automating the boring stuff (symlinks, comparing files before copying…)
  • Each module opens a transaction, which can be audited or rolled back before committing
  • Generate nice reports
  • Abstract the distribution details (like package management)

Quick Start

1. Create configuration directory

First you have to download ricecooker, and place it in your configuration directory.

mkdir dotfiles; cd dotfiles; git init
curl -sL https://github.com/maxadamski/ricecooker/releases/download/v0.1.0/ricecooker.sh -o ricecooker.sh
echo ricecooker.sh >> .gitignore

2. Create a ricefile

Now create your configuration file.

dotfiles/ricefile:

#!/usr/bin/env bash

# 1. Source ricecooker
. ricecooker.sh

# 2. Declare and add a module
rice::add hello_world
hello_world() {
  rice::exec echo "Hello, World!"
}

# 3. Pass cli arguments
$@

The configuration script requires execute permissions.

chmod +x ricefile

3. Run modules

You're basically done! Now execute rice::* functions like this:

./ricefile rice::run @

4. Optimize your workflow (optional)

You don't have to type ./ricefile rice::run ... every time you want to rebuild your configuration.

Save yourself precious keystrokes by defining a function like this in the ricefile:

rebuild() {
  # assuming you have these modules added
  rice::run -w "(system_packages|system_config|user_config)$RICE_TREE_SUFFIX" "$@"
}

You can alse export the selector for your setup in the shell (hint: use templates to do this), and make an alias to the ricefile.

alias rice=~/.dotfiles/ricefile
export RICE_TREE_SUFFIX=':arch:work'
# more flexible:
#{{#rice_tree_suffix}}
#export RICE_TREE_SUFFIX='{{rice_tree_suffix}}'
#{{/rice_tree_suffix}}

Now you can run common actions effortlessly!

rice rebuild

It's still possible to pass additional arguments:

rice rebuild -p -system_packages..

Examples

Sample ricefiles are inside the examples directory.

Also check out my dotfiles for real world usage.

Requirements

  • bash >= 4

Optional:

  • make (to easily run unit tests)
  • kcov (to generate coverage reports)
  • ruby (for built-in template support)

Documentation

The documentation is available on the wiki.