{"id":15020036,"url":"https://github.com/brettmc/docker-compose-generator","last_synced_at":"2025-10-24T22:31:58.659Z","repository":{"id":48788018,"uuid":"153275255","full_name":"brettmc/docker-compose-generator","owner":"brettmc","description":"generate templated docker-compose files","archived":false,"fork":false,"pushed_at":"2021-07-12T07:07:22.000Z","size":103,"stargazers_count":10,"open_issues_count":3,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-31T04:26:45.551Z","etag":null,"topics":["docker-compose"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brettmc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-16T11:36:30.000Z","updated_at":"2023-10-18T17:15:11.000Z","dependencies_parsed_at":"2022-08-31T11:04:08.806Z","dependency_job_id":null,"html_url":"https://github.com/brettmc/docker-compose-generator","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brettmc%2Fdocker-compose-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brettmc%2Fdocker-compose-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brettmc%2Fdocker-compose-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brettmc%2Fdocker-compose-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brettmc","download_url":"https://codeload.github.com/brettmc/docker-compose-generator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238043569,"owners_count":19407056,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker-compose"],"created_at":"2024-09-24T19:54:30.009Z","updated_at":"2025-10-24T22:31:53.364Z","avatar_url":"https://github.com/brettmc.png","language":"PHP","readme":"# docker-compose generator\n[![Build Status](https://travis-ci.com/brettmc/docker-compose-generator.svg?branch=master)](https://travis-ci.com/brettmc/docker-compose-generator)\n[![Coverage Status](https://coveralls.io/repos/github/brettmc/docker-compose-generator/badge.svg?branch=master)](https://coveralls.io/github/brettmc/docker-compose-generator?branch=master)\n\nA tool for populating a docker-compose file from one or more templates, using mustache-like replacement.\n\n# Installation/usage\n\nComposer package:\n```\ncomposer require brettmc/docker-compose-generator\n```\n\nDocker image:\n```\ndocker run --rm -it brettmc/docker-compose-generator --help\n```\n\n# Overview\nIf you need to maintain multiple, slightly-different, [docker-compose](https://docs.docker.com/compose) configurations\nwhich change per-environment, you've come to the right place.\n\nThis is being used in production in my day job for a couple of medium-sized projects, and is usually used as follows:\n\n* git commit triggers a CI/CD pipeline\n* pipeline tests, builds and tags some docker images, ready to be deployed\n* pipeline executes a shell script, which tests some variables to work out which environment it is deploying to, and which files it should include:\n    * tags -\u003e prod env\n    * develop -\u003e test env\n    * everything else -\u003e build env\n* generate docker-compose config by combining a main template file with one or more environment-specific files, as well as optionally a main and environment-specific .ini file, and finally any dynamic values via the `-e` switch\n* pass the generated file to `docker stack deploy`\n\n## Per-environment differences\nFor example, commits to development branches are built and deployed to a dev swarm. Each dev deployment gets its own database, but test and prod deployments do not.\n\n## Multiple input files\nMerge multiple `yaml` templates. For example, a `main.yml` template can be extended by having `dev.yml`\nadd additional services. These will be merged together before applying later operations.\nIf templates are provided from both `stdin` and via the `--input` option, `stdin` is processed first.\nMultiple inputs provided via `--input` are processed in order.\n\n## Variable substitution\nAfter merging all templates, perform variable substitution across the result, based on values from `.ini` files, then environment variables and finally variables from `-e` flags.\n\n## Define variables in numerous ways\nAccepts variables from INI-style environment files, or command switches, in the following order:\n\n* `.ini` files (eg `--ini global.ini --ini local.ini`) are processed in the order they are provided, with duplicate keys overriding earlier; then\n* environment variables; then\n* command-line variables (`-e FOO=foo`); and finally\n* nullable command-line variables (`-o FOO=` or `-o FOO=foo`) - _if an empty value is given, it is ignored and does not clobber an earlier setting_\n\n# Usage\n\n`main.yml`\n```\nversion: '3.4'\nnetworks:\n  front:\n  back:\nservices:\n  my-service:\n    image: \"my-service:{{TAG_OR_HASH}}\"\n    environment:\n      BAR: \"{{BAR}}\"\n```\n\n`dev.yml`\n```\nservices:\n  my-service:\n    ports:\n      - \"80:80\"\n  db:\n    image: \"postgres\"\n```\n\n`prod.yml`\n```\nservices:\n  my-service:\n    image: \"my-service:{{TAG_OR_HASH}}\"\n```\n\n`prod.ini`\n```\nDB_HOST=prod.db.example.com\nAUTH=prod.signon.example.com\n```\n\n`dev.ini`\n```\nAUTH=dev.signon.example.com\n```\n\nYou can then roll your own logic to work out which files to apply after `main.yml`, eg\n\n```\n#!/bin/bash\necho \"generating for env: ${CI_ENV} #pre-defined variable, eg from a cicd system\ncase ${CI_ENV} in\n  BUILD)\n    HOST=docker-build-swarm-manager.example.com\n    STACK=${CI_COMMIT_HASH}\n    TAG_OR_HASH=${CI_COMMIT_HASH}\n    BAR=something\n    ;;\n  PROD)\n    HOST=docker-prod-swarm-manager.example.com\n    STACK=prod\n    TAG_OR_HASH=${CI_COMMIT_TAG}\n    BAR=something-else\n    ;;\nesac\nbin/dcgen.php generate -e HASH=${CI_COMMIT_HASH} -e BAR=${BAR} --ini ${CI_ENV}.ini --input main.yml --input ${CI_ENV}.yml \u003e docker-compose.yml\ndocker -H ${HOST} stack deploy --prune --with-registry-auth -c docker-compose.yml ${STACK}\n```\n\n# Run via docker\nNB, do not attach a TTY (ie, do not use docker's `-t` switch) if you are piping input\n```\n$ docker run --rm -i brettmc/docker-compose-generator generate -e FOO=foo -e BAR=bar \u003c main.yml \u003e output.yml\n```\nor\n```\n$ cat main.yml | docker run --rm -i brettmc/docker-compose-generator generate -e FOO=foo -e BAR=bar \u003e output.yml\n```\nor just use volumes:\n```\n$ docker run --rm -v $(pwd)/conf:/srv/conf -v $(pwd)/template:/srv/template brettmc/docker-compose-generator generate --input /srv/template/main.yml --input /srv/template/dev.yml --ini /srv/conf/dev.ini -e DB_HOST=${HOST} \u003e output.yml\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrettmc%2Fdocker-compose-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrettmc%2Fdocker-compose-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrettmc%2Fdocker-compose-generator/lists"}