Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reusing only part(s) of scripts #53

Closed
mumoshu opened this issue Feb 4, 2019 · 1 comment
Closed

Reusing only part(s) of scripts #53

mumoshu opened this issue Feb 4, 2019 · 1 comment

Comments

@mumoshu
Copy link
Owner

mumoshu commented Feb 4, 2019

I tend to organize my variant scripts to the "header" and the "body" like seen in the following example:

    script: |
      # header
      {{ $env    := get "environment" }}
      {{ $state  := merge (get $env) (get "file" | readFile | fromYaml) }}
      {{ $name   := $state | dig "name" }}
      {{ $bucket := get "bucket" }}
      {{ $ns     := $state | dig "namespace" }}

      # body
      cat <<EOF > state.yaml
      {{ $state | toYaml }}
      EOF

      aws s3 cp state.yaml s3://{{ $bucket }}/eks/environments/{{ $env }}/namespaces/{{ $ns }}/{{ $name }}/state.yaml 

What if you want to reuse the "header` in various variant scripts, to that you can tidy up your variant command for more focus on the "body"s of it? There's no way atm.

I propose to extend script: to optionally accept an array, so that you can use YAML anchors for reusing headers:

mixins:
  header: &header
      {{ $env    := get "environment" }}
      {{ $state  := merge (get $env) (get "file" | readFile | fromYaml) }}
      {{ $name   := $state | dig "name" }}
      {{ $bucket := get "bucket" }}
      {{ $ns     := $state | dig "namespace" }}

tasks:
  foo:
    parameters:
    # ....
    script:
    - *header
    - |
      cat <<EOF > state.yaml
      {{ $state | toYaml }}
      EOF

      # ...
@mumoshu mumoshu closed this as completed in 1773d6b Feb 6, 2019
@osterman
Copy link
Sponsor

osterman commented Feb 6, 2019

Hah! That's cool. I like the use of anchors here as well as the list of commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants