grammarly / rocker-compose

Docker composition tool with idempotency features for deploying apps composed of multiple containers.
Other
407 stars 26 forks source link

Array passing #24

Closed mancvso closed 9 years ago

mancvso commented 9 years ago

Currently we are trying to "link" more than one instance of a specific service (like mongodb) to a container defined in a YAML file similar to this one

namespace: {{ .namespace }}
containers:
  _box:
    image: {{ .image }}:{{ .imagetag }}
    expose: {{ or .expose "8080" }}
    env:
      VIRTUAL_HOST: {{ .VIRTUAL_HOST }}
      PORT: {{ or .PORT "8080" }}
    volumes_from: data
    links:
{{ range $link := .links }}
      -{{ $link.external }}:{{ $link.internal }}
{{ end }}

  data:
    image: some/image:latest
    state: created
    cmd: true
    volume:
      - /usr/data/app

  {{ range $n := seq .n }}
  box_{{$n}}:
    extends: _box
    cmd: some_command
  {{ end }}

But we cannot manage to make rocker-compose recognize the array of objects (in this case, the links). Those containers are started separately from this composition.

Does rocker-compose supports the passing of arrays?

ybogdanov commented 9 years ago

Hey @mancvso

You can pass a comma separated list and then use strings.Split inside your compose.yml.

Like this:

{{ range $link := split .links "," }}
      - {{ $link }}
{{ end }}

Take a look at rocker/template for the documentation.

Also, rocker-compose dev branch now supports loading variables from YAML and JSON files, so it's possible to load more sophisticated data structures. It will be merged soon.

mancvso commented 9 years ago

I may be missing something but... :crying_cat_face:

function "split" not defined
ybogdanov commented 9 years ago

Ah, it's in the new version that is not released yet :( I will release it soon, by now you can install from HEAD:

brew tap grammarly/tap
brew install grammarly/tap/rocker-compose --HEAD

Don't forget to uninstall the old version first.

mancvso commented 9 years ago

Compiled from source

rocker-compose 0.1.2 - 7d9dac2 (master) 2015-10-26_15:09_GMT
go version go1.5.1 linux/amd64

Everything works as expected. Closing now.