moby / swarmkit

A toolkit for orchestrating distributed systems at any scale. It includes primitives for node discovery, raft-based consensus, task scheduling and more.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Templated config and secrets issue

aaronovz1 opened this issue · comments

commented

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?

commented

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.