pupssman
pupssman

Reputation: 541

Managing docker-compose override files

We are developing a small project consisting of a mongodb, java backend and express-js based front-end. We've chose docker-compose as a deployment tool for all but production uses and so far it's been fairly good with one exception.

Currently, we use it for:

To handle all those various tweaks per environment we've deduced a set of docker-compose files: docker-compose.yml, d-c.override.yml, d-c.test.yml, d-c.load.yml and d-c.demo.yml (docker-compose replaced with d-c for brevity).

This makes us use enourmously long command-line invocations to do anything except for basic tasks. For example:

docker-compose -f docker-compose.yml -f docker-compose.test.yml up -d --build
docker-compose -f docker-compose.yml -f docker-compose.test.yml exec test_container ./do_tests.sh

And it goes worse.

So far we've got couple ideas about improving that:

  1. use full docker-compose files instead of partial to save up typing -- but extra maintenance when app structure changes / extra parameters are introduced;
  2. (variation of the former) use extends for services and minimize the copy-paste (but adds extra complexity);
  3. store all those lengthy commands in a Makefile (or a bash script). Ease of use, but feels like sweeping complexity under the rug;
  4. (variation of the former) develop docker-compose plugin / own tooling -- may be more explicit in handling our needs, but extra maintenance and deployment complexity.

All of those ideas have their drawbacks -- I wonder what are proper solutions for that and what tools already exist.

Upvotes: 2

Views: 2966

Answers (1)

dnephin
dnephin

Reputation: 28090

I think 3 sounds like a good solution. It's not "hiding complexity", it's just automating a repetitive task (typing long command lines).

A Makefile would work, but you might also be interested in dobi (disclaimer: I am the author of this tool). dobi allows you to define all your project tasks in a yaml file, including running Compose with different files and project name. An example config for your project might look something like this

compose=dev:
  files: [docker-compose.yaml, d-c.override.yml]

compose=test:
  files: [docker-compose.yaml, d-c.test.yml]

compose=load:
  files: [docker-compose.yaml, d-c.load.yml]

Then you can run a task with dobi dev, etc.

You might even find that some of the one-off tasks can be moved to the dobi config, removing the need to have extra compose overrides.

Upvotes: 1

Related Questions