nickthecook/ops

add top-level `forwards` section

Closed this issue · 2 comments

Consider a project in which there is:

  • a top-level infrastructure project, e.g. terraform code, that creates infrastructure and deploys an app to it
  • an app directory, self-contained, with its own ops.yml, that can be run on a development machine or on deployed infrastructure

It's common in this case to have the top-level project provide secrets and config that are also needed by the app project. In that case, the developer must choose one of the following options for using top-level secrets and config in the app:

  • duplicate the config and secrets (not great)
  • generate app config and secrets in the top-level project (it's a pain to generate an ejson file from terraform in all your apps, and makes it harder for a developer to find the config and secrets since they're not checked into the app directory where they're used)
  • "forward" a bunch of ops commands to the app dir from the top-level dir (verbose and ugly - see below)

"Forwarding" in ops looks like this:

actions:
  pack:
    command: cd packer && ops pack-all
    alias: p
  pack-force:
    command: cd packer && ops pack-force-all
    alias: pf
  pack-all:
    command: cd packer && ops pack-all
    alias: pa
  pack-force-all:
    command: cd packer && ops pack-force-all
    alias: pfa

But fowarding could look like this:

forwards:
  packer:
    - pack, p
    - pack-force, pf
    - pack-all, pa
    - pack-force-all, pfa

This is more idiomatic, communicating more clearly to the reader that a subdirectory handles these. It's like the difference between a for loop and the ruby .each: obvious intent (and less typing).

In the case of having subprojects inherit top-level secrets and config, however, it doesn't work when running on deployed infrastructure. The top-level dir shouldn't be copied to the infrastructure at all. Is there another use case where this does make sense?

Even better, forward an action like app to the app directory, so, e.g.:

forwards:
  app: app

would result in ops app start running ops start in app/. ops app stop would run ops stop in app/. No need to forward each action, but the user will still know where to look to find a command that is being run.

Fixed in 0.19.0, as comment described it.