swarmkit icon indicating copy to clipboard operation
swarmkit copied to clipboard

Templated config and secrets issue

Open aaronovz1 opened this issue 4 years ago • 1 comments

Hi

I am trying to have my services load different configs/secrets based on their ID/Slot.

I have the following which is failing:

{{ secret private_key_{{.Task.Slot}} }}

Error: bad character U+007B '{'"

I have tried a few combinations but I can't get it to substitute the inner templated variable Task.Slot.

Can anyone assist in the correct syntax?

aaronovz1 avatar Jun 29 '20 01:06 aaronovz1

Ok. I solve this problem by doing: {{ printf "private_key_%s" .Task.Slot | secret }}

But I realised that this is referencing the target and not the source, and overall I'm not sure it'll do what I need.

In compose, I'm trying to do the following to have dynamic scaling where services select a key from a "pool":

version: '3.8'
services:
  myapp:
    image: 127.0.0.1:6666/myapp
    build: ./myapp
    secrets:
      - source: private_key_{{.Task.Slot}}
        target: private_key

secrets:
  private_key_1:
    name: private_key_1
    file: ./keys/private_key_1
  private_key_2:
    name: private_key_2
    file: ./keys/private_key_2
  private_key_3:
    name: private_key_3
    file: ./keys/private_key_3

However, compose does not do variable substitution for {{.Task.Slot}} in the secrets section.

aaronovz1 avatar Jun 29 '20 18:06 aaronovz1