Git Product home page Git Product logo

dy's Introduction

dy Go Report Card CircleCI GoDoc

Construct YAML from a directory tree

Description

The entire world seems to think declarative configuration is best represented as YAML. This is especially prevalent in the land of Kubernetes and related tools. Terrible ideas have a tendency to accumulate leading to awful solutions to the wrong problems.

Whilst this tool doesn't pretend to move the mountain it does try to nudge it back in the right direction.

Put simply, dy allows one to build a YAML document from a directory tree containing snippets of YAML. The aim is to make the document easier to reason about and maintain.

It is useful everywhere complex YAML configuration is employed: CI pipelines, Cloudformation, Kubernetes, etc. See the examples for inspiration, especially in tandem with envsubst.

Introducing Divvy Yaml

divvy /ˈdɪvi/ - To share out. Informal, British - A foolish or stupid person

dy parses a directory tree according to the following rules:

  • A directory is a text key
  • A file name has contents that are rendered under a key named after the file prefix
  • A file name that begins with an underscore is rendered without a key at the current indentation level

Consider the following example:

$ tree k8s_deployment/
k8s_deployment/
├── _header.yaml
├── metadata.yaml
└── spec
    ├── _replicas.yaml
    ├── selector.yaml
    └── template
        ├── metadata
        │   └── labels.yaml
        └── spec
            └── containers.yaml

4 directories, 6 files
$ dy k8s_deployment/
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx
          image: nginx:1.7.9
          ports:
          - containerPort: 80
$ dy k8s_deployment/ | kubectl apply --validate=true --dry-run=true -f -
deployment.apps/nginx-deployment created (dry run)

You may pass multiple directories as arguments and they will each be parsed and emitted as documents in their own right. In this way a single dy invocation can be used to produce a valid multi-document YAML stream.

Installing

Homebrew

brew tap sampointer/dy
brew install dy

Manually

Download the appropriate package for your distribution from the releases page.

dy's People

Contributors

sampointer avatar dependabot[bot] avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.