docker-archive / deploykit

A toolkit for creating and managing declarative, self-healing infrastructure.
Apache License 2.0
2.25k stars 264 forks source link

Depends template #887

Closed chungers closed 6 years ago

chungers commented 6 years ago

This PR adds a new template function for playbooks to simplify the notation of dependencies.

For example:

  az1-net1:
    plugin: az1/net
    labels:
      az: az1
      type: network
    Properties:
             # ....
 az1-net2:
    plugin: az1/net
    labels:
      az: az1
      type: network
    Properties:
      wait: {{ depend `az1-net1/ID` }}
      cidr: 10.20.200.0/24
      gateway: 10.20.0.1

The expression {{ depend "az1-net1/ID" }} denotes a dependency on the ID property of the resource az1-net1.

The depend template function is available only for playbooks. To turn a document yml into a playbook, simply add this line {{/* =% text %= */}} at the top of the file (see the .yml files in this PR). This makes it possible to include arbitrary text file into a playbook (e.g. referencing it in a playbook.yml and subsequently with infrakit use <playbook> <friendly_name_of_file_in_index>. The playbook support in the infrakit CLI will download all the referenced files and cache them locally. This simplifies working with yml config files as they no longer need to be referenced via the file:// url to read locally. Instead, we can just use playbook commands like

 infrakit local mystack/resource commit -y <(infrakit use res chain2.yml)

Signed-off-by: David Chung david.chung@docker.com