kayac / ecspresso

ecspresso is a deployment tool for Amazon ECS
MIT License
826 stars 90 forks source link

Add external plugin #760

Open fujiwara opened 2 weeks ago

fujiwara commented 2 weeks ago

external plugin runs any external commands as template functions.

Execute external commands

The external plugin introduces functions to execute any external commands.

For example, jq -n "{ Now: now | todateiso8601" } returns the current date in ISO8601 format as a JSON object.

$ jq -n "{ Now: now | todateiso8601 }"
{
  "Now": "2024-10-25T16:13:22Z"
}

You can use this command as a template function in the definition files.

First, define the plugin in the configuration file.

ecspresso.yml

plugins:
  - name: external
    config:
      name: jq
      command: ["jq", "-n"]
      num_args: 1
      timeout: 5

The config section defines the following parameters:

And use the template function in the definition files as follows.

local jq = std.native('jq');
{
  today: jq('{ Now: now | todateiso8601 }').Now,
}
{
  "today": "{{ (jq `{Now: now | todateiso8601}`).Now }}"
}