deploy-configs

command module
v1.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 13, 2023 License: MIT Imports: 3 Imported by: 0

README

Deploy-configs

Go Reference Tests Codecov Go Report

It serves to deploy config files to pc by yaml description.

It can:

  • create symlinks
  • expand templates
  • execute commands

It shows execution log gracefully:

  • what was changed
  • what wasn't changed
  • what wasn't able to succeed

Installation

By go compiler tools:

go install github.com/backdround/deploy-configs@main

Example

Lets create sample config repository to deploy:

./configs
├── .git
├── deploy-configs.yaml
└── terminal
    ├── tmux
    └── gitconfig

deploy-configs.yaml contains yaml that drives deploying process:

instances:
  home:
    links:
      tmux:
        target: "{{.GitRoot}}/terminal/tmux"
        link: "{{.Home}}/.tmux.conf"
      git:
        target: "{{.GitRoot}}/terminal/gitconfig"
        link: "{{.Home}}/.gitconfig"

To deploy home instance we execute application:

deploy-configs home

Result user home tree with deployed configs:

/home/user/
├── .gitconfig -> /home/user/configs/terminal/gitconfig
├── .tmux.conf -> /home/user/configs/terminal/tmux
└── configs
    └── ... # output truncated

Complex example


# Config repository to deploy
./configs
├── .git
├── deploy-configs.yaml
├── desktop
│   ├── flameshot.ini
│   └── i3_template
├── git
│   └── gitconfig
└── terminal
    └── tmux
# deploy-configs.yaml
instances:
  home:

    links:
      tmux:
        target: "{{.GitRoot}}/terminal/tmux"
        link: "{{.Home}}/.tmux.conf"
      git:
        target: "{{.GitRoot}}/git/gitconfig"
        link: "{{.Home}}/.gitconfig"

    commands:
      flameshot:
        input: "{{.GitRoot}}/desktop/flameshot.ini"
        output: "{{.Home}}/.config/flameshot/flameshot.ini"
        command: "sed \"s~%HOMEDIR%~$HOME~g\" '{{.Input}}' > '{{.Output}}'"

    templates:
      i3:
        input: "{{.GitRoot}}/desktop/i3_template"
        output: "{{.Home}}/.config/i3/config"
        data:
          telegram:
            size: "525 700"
            position: "1348 96"
          monitors:
            left: "DP-2"
            right: "HDMI-3"
# Deploying `home` instance
deploy-configs home
# Result home tree with deployed configs
/home/user/
├── .config
│   ├── flameshot
│   │   └── flameshot.ini
│   └── i3
│       └── config
├── .gitconfig -> /home/user/configs/git/gitconfig
├── .tmux.conf -> /home/user/configs/terminal/tmux
└── configs
    └── ... # output truncated

Yaml format

Application deploys config files in accordance with deploy-configs.yaml. It searches file recursively from current directory to root.

Main structure

Schematic example:

# Arbitrary data that you need in your instances
<any-shared-data>:
  any:
    - shared
    - data

# Field contains a dictionary with all possible instances.
instances:
  # Instance is a set of deploying operation for performing at once.
  <instance-one>:
    [links:]
    [templates:]
    [commands:]

  <instance-two>:
    [links:]
    [templates:]
    [commands:]

  ...

Real example:

.dev-links: &dev-links
  tmux:
    target: "{{.GitRoot}}/terminal/tmux"
    link: "{{.Home}}/.tmux.conf"
  zsh:
    target: "{{.GitRoot}}/terminal/zshrc"
    link: "{{.Home}}/.zshrc"

instances:
  home:
    links:
      <<: *dev-links
  work:
    links:
      <<: *dev-links
    templates:
      ...

Links

Links field describes links that are needed to be created.

Ripped out example:

links:
  # Name is used in logs.
  tmux:
    # Target is a destination for link.
    target: "{{.GitRoot}}/terminal/tmux"
    # Link is used as a path to link creation.
    link: "{{.Home}}/.tmux.conf"
  zsh:
    target: "{{.GitRoot}}/terminal/zshrc"
    link: "{{.Home}}/.zshrc"

Templates

Templates field describes templates that are needed to be expanded and deployed.

Ripped out example:

templates:
  # Name is used in logs.
  i3:
    # Input is a path to a `go` template (text/template).
    input: "{{.GitRoot}}/desktop/i3_template"
    # Output is a path to an expanded template.
    output: "{{.Home}}/.config/i3/config"
    # Data is an arbitrary structured data for template expantion.
    data:
      telegram:
        size: "525 700"
        position: "1348 96"
      monitors:
        left: "DP-2"
        right: "HDMI-3"

Commands

Commands field describes commands that create output files after execution.

Ripped out example:

commands:
  # Name is used in logs.
  flameshot:
    # Input is a path to a command source config.
    input: "{{.GitRoot}}/desktop/flameshot.ini"
    # Output is a path to a generated config.
    output: "{{.Home}}/.config/flameshot/flameshot.ini"
    # Command converts the `input` config to an `output` config.
    # It allows {{.Input}} and {{.Output}} substitutions accordingly.
    command: "sed \"s~%HOMEDIR%~$HOME~g\" '{{.Input}}' > '{{.Output}}'"

Path replacement

There are some replacements to define paths:

  • {{.GitRoot}} - expands into current git directory.
  • {{.Home}} - expands into current user home directory.

It expands only in specific fields which are used for path holding.

Example:

links:
  git:
    target: "{{.GitRoot}}/git/gitconfig"
    link: "{{.Home}}/.gitconfig"

It will expand to:

links:
  git:
    target: "/home/user/configs/git/gitconfig"
    link: "/home/user/.gitconfig"

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
internal
config
config Validates and parses user yaml config to Config structure.
config Validates and parses user yaml config to Config structure.
dataconverter
dataconverter converts config data structures to deploy data structures.
dataconverter converts config data structures to deploy data structures.
deploy/commands
commands describes commandExecuter which receives a bunch of commands, that create files from inputFiles, executes these and logs all outcomes.
commands describes commandExecuter which receives a bunch of commands, that create files from inputFiles, executes these and logs all outcomes.
deploy/links
links describes linkMaker which receives a bunch of links, creates these and logs all outcomes.
links describes linkMaker which receives a bunch of links, creates these and logs all outcomes.
deploy/templates
templates describes templateMaker which receives a bunch of templates, expands these and logs all outcomes.
templates describes templateMaker which receives a bunch of templates, expands these and logs all outcomes.
pathexpander
Describes pathexpander that expands paths in given templates.
Describes pathexpander that expands paths in given templates.
pkg
fstestutility
fstestutility describes functions that are useful for tests
fstestutility describes functions that are useful for tests
logger
logger describes type logger that log messages to system terminal
logger describes type logger that log messages to system terminal
tests
testcase
Package testcase used for integration tests
Package testcase used for integration tests

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL