Skip to content

Improve Compose extends and make it less verbose and more powerful. #1380

Description

@Vad1mo

Currently compose extends is very verbose.

We use extends in the way that we have a base file and then for each environment we replace the significant parts that we want to override or have different.

In the current state of extends if you want to achieve the same you need almost rewrite everything.
Look at out actual example and how verbose it is. There are only two lines that matter.

common.yaml

elasticsearch:
image: zinvoice/elasticsearchhostname: elasticsearchrestart: alwaysdns: 172.17.42.1ports:
- "9200:9200"volumes:
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
- /data/elasticsearch:/opt/elasticsearch/data/elasticsearchlogstash:
image: zinvoice/logstashhostname: logstashdns: 172.17.42.1restart: alwaysports:
- "5000:5000"volumes:
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:rokibana:
image: zinvoice/kibanahostname: kibanadns: 172.17.42.1restart: alwaysports:
- "5601:5601"volumes:
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:rologspout:
image: zinvoice/logspouthostname: logspoutcommand: logstash://logstash.docker:5000restart: alwaysdns: 172.17.42.1ports:
- "8003:8000"volumes:
- /var/run/docker.sock:/tmp/docker.sockdoorman:
image: zinvoice/doormanhostname: doormanrestart: alwaysdns: 172.17.42.1ports:
- "8085:8085"

child.yaml

elasticsearch:
extends:
file: ../common.ymlservice: elasticsearchlogstash:
extends:
file: ../common.ymlservice: logstashkibana:
extends:
file: ../common.ymlservice: kibanalogspout:
extends:
file: ../common.ymlservice: logspoutdoorman:
environment:
- DOORMAN_GITHUB_APPID=xxxxxxxx
- DOORMAN_GITHUB_APPSECRET=xxxxxxlinks:
- nginxtrustedextends:
file: ../common.ymlservice: doorman

With the new extends feature one would add a global_extends/import like this:

extended_child.yaml

global_extends: - common.yaml
- extra.yaml doorman:
environment:
- DOORMAN_GITHUB_APPID=xxxxxxxx
- DOORMAN_GITHUB_APPSECRET=xxxxxx

Thats it.

Advantages

  1. A less verbose code is easy to maintain and understand
  2. You can add remove service in the base.yaml without adding/removing entries in the children. (Missing a container in Prod because someone forgot to ad it as into the prod.yaml.
  3. You can aggregate services into one.
  4. The configuration can be easily created by CI or or maintained by an application.
  5. You have a nice overview what gets set and you can check in this in a repo.
  6. This will make Interpolate environment variables in docker-compose.yml #1377 and Pass variables inside fig.yml on runtime #495 obsolete and 75 +1er happy :)

Main featues

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions