├── .gitignore ├── .travis.yml ├── LICENSE ├── README.rst ├── compose_addons ├── __init__.py ├── config_utils.py ├── includes.py ├── merge.py └── namespace.py ├── setup.py ├── tests ├── __init__.py ├── includes_test.py ├── merge_test.py └── namespace_test.py └── tox.ini /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | *.swp 3 | dist/ 4 | .tox 5 | *.egg-info/ 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | env: 3 | - TOX_ENV=py27 4 | - TOX_ENV=py34 5 | install: 6 | - pip install --use-mirrors tox 7 | script: tox -e $TOX_ENV 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | 2 | docker-compose addons 3 | ===================== 4 | 5 | A set of command line tools to supplement the features already available 6 | in docker-compose. These tools generally focus on development or testing 7 | environment use-cases. 8 | 9 | .. image:: https://img.shields.io/pypi/v/compose-addons.svg 10 | :target: https://pypi.python.org/pypi/compose-addons 11 | :alt: Latest PyPI version 12 | 13 | .. image:: https://travis-ci.org/dnephin/compose-addons.svg?branch=master 14 | :target: https://travis-ci.org/dnephin/compose-addons 15 | :alt: Travis CI 16 | 17 | 18 | .. contents:: 19 | :backlinks: none 20 | 21 | 22 | Install 23 | ------- 24 | 25 | Currently the only install option is pip 26 | 27 | .. code:: sh 28 | 29 | pip install compose-addons 30 | 31 | 32 | dcao-include 33 | ------------ 34 | 35 | Given a docker-compose.yml file, fetch each configuration in the include 36 | section and merge it into a base docker-compose.yml. If any of the included 37 | files have include sections continue to fetch and merge each of them until 38 | there are no more files to include. 39 | 40 | Use Cases 41 | ~~~~~~~~~ 42 | 43 | - If you have a service-oriented architecture, where each of your services 44 | is developed and deployed in a separate code repo, and each has its own 45 | docker-compose.yml. When you want to create a full testing or development 46 | environment for an individual service, you need to include all the 47 | downstream services. Instead of duplicating the topology of each 48 | downstream service, you can include the ``docker-compose.yml`` from the 49 | downstream service. Including (instead of duplicating) this topology 50 | allows you to change dependencies in a single place without worrying 51 | about breaking the test suite of dependent services. 52 | - If the scope of your composition can change based on the task you're 53 | performing. Your application might have a "core" set of services that are 54 | always run, and some adhoc, or administrative services that are only run 55 | sometimes. You can split your composition into two (or more) files. 56 | The core ``docker-compose.yml`` would only contain the core services. The 57 | ``compose-admin.yml`` would include the ``docker-compose.yml`` and add 58 | extra services which could link to or use volumes from the core services, 59 | without having to duplicate any of the service configuration. 60 | - If your composition varies by environment (dev vs prod). Similar to the 61 | case above, the core ``docker-compose.yml`` would remain the same for all 62 | environments, but ``docker-compose-dev.yml`` could include the "core" 63 | services, and add additional service, like database or proxies. 64 | 65 | Working with Includes 66 | ~~~~~~~~~~~~~~~~~~~~~ 67 | 68 | ``dcao-include`` works with a configuration that is different from the 69 | ``docker-compose`` config in a few ways: 70 | 71 | - an optional top level ``include`` key, which contains a list of urls (which 72 | may be local file paths, http(s) urls, or s3 paths) 73 | - a required top level ``namespace`` key, which is used by a config to link 74 | to services in an included file. For example, if a config includes 75 | http://example.com/compositions/servicea.yaml which has a ``namespace`` 76 | of ``servicea``, all "public" services in ``servicea.yaml`` should start 77 | with ``servicea.``. 78 | - since configuration can be included from a remote url, or different 79 | directories, the configuration should not include anything that depends 80 | on the host. There should be no ``build`` keys in any service, and no 81 | host volumes. 82 | 83 | Example 84 | ~~~~~~~ 85 | 86 | An example composition file with includes: 87 | 88 | .. code:: yaml 89 | 90 | include: 91 | - http://example.com/compositions/servicea.yaml 92 | - http://example.com/compositions/serviceb.yaml 93 | 94 | namespace: core 95 | 96 | web: 97 | image: example/service_a:latest 98 | links: ['servicea.web', 'serviceb.api'] 99 | 100 | **servicea.yaml** might look something like this 101 | 102 | .. code:: yaml 103 | 104 | namespace: servicea 105 | 106 | servicea.web: 107 | image: services/a:latest 108 | 109 | **serviceb.yaml** might look something like this 110 | 111 | .. code:: yaml 112 | 113 | namespace: serviceb 114 | 115 | serviceb.api: 116 | image: services/b:latest 117 | 118 | Usage 119 | ~~~~~ 120 | 121 | To use ``dcao-include`` with ``docker-compose`` you have a couple options: 122 | 123 | Use it with a pipe to stdin: 124 | 125 | .. code:: sh 126 | 127 | dcao-include compose-with-includes.yml | docker-compose -f - up -d 128 | 129 | 130 | Use it once to generate a new file: 131 | 132 | .. code:: sh 133 | 134 | dcao-include -o docker-compose.yml compose-with-includes.yml 135 | docker-compose up -d 136 | docker-compose ps 137 | 138 | 139 | dcao-namespace 140 | -------------- 141 | 142 | Given a standard ``docker-compose.yml`` file, add a namespace key, and prefix 143 | all instances of service names with that namespace. This command is used to 144 | prepare a standard ``docker-compose.yml`` file for being used as an include 145 | by ``dcao-include``. This could be considered the "export" step required 146 | before a compose file can be included by another project. 147 | 148 | 149 | Example 150 | ~~~~~~~ 151 | 152 | Given a ``docker-compose.yml``: 153 | 154 | .. code:: yaml 155 | 156 | web: 157 | image: example.com/web:latest 158 | links: ['db'] 159 | volumes_from: ['configs'] 160 | db: 161 | image: example.com/db:latest 162 | configs: 163 | image: example.com/configs:latest 164 | 165 | running ``dcao-namespace docker-compose.yml myservice`` would produce 166 | 167 | .. code:: yaml 168 | 169 | namespace: myservice 170 | myservice.web: 171 | image: example.com/web:latest 172 | links: ['myservice.db:db'] 173 | volumes_from: ['myservice.configs'] 174 | myservice.db: 175 | image: example.com/db:latest 176 | myservice.configs: 177 | image: example.com/configs:latest 178 | 179 | 180 | Usage 181 | ~~~~~ 182 | 183 | First generate the namespaced config 184 | 185 | .. code:: sh 186 | 187 | dcao-namespace -o myservice.yml docker-compose.yml myservice 188 | 189 | Next you'll want to make ``myservice.yml`` available to other services. In this 190 | example we'll assume we're using an s3 bucket 191 | 192 | .. code:: sh 193 | 194 | aws s3 cp myservice.yml s3://some-bucket/compose-registry/myservice.yml 195 | 196 | 197 | Now we can use that configuration as an include in another service. In a 198 | different services ``compose-with-includes.yml`` (which will be consumed by 199 | ``dcao-include``) 200 | 201 | .. code:: sh 202 | 203 | include: 204 | - s3://some-bucket/compose-registry/myservice.yml 205 | 206 | 207 | dcao-merge 208 | ---------- 209 | 210 | Merge ``docker-compose.yml`` configuration files by overriding values in the 211 | base configuration with values from other files. It is used to transform a 212 | configuration without having to duplicate any fields that should remain 213 | consistent. 214 | 215 | Use Cases 216 | ~~~~~~~~~ 217 | 218 | - Often in development you'll want to include code using a volume for faster 219 | iteration, but for testing on a CI you want to include the source in the 220 | container with ``ADD`` (or ``COPY``). You could use an ``overrides-dev.yml`` to add 221 | volumes to the configuration, and skip that step during CI. 222 | - If the composition is running on a shared host each developer needs to use a 223 | different host port. This variation can be included in a file maintained by 224 | each developer outside of version control. 225 | - If a ``docker-compose.yml`` contains ``build`` directives for local 226 | development, but needs ``image`` directives in other environments (testing, 227 | stage, prod, etc), merge can be used to rewrite ``build`` to ``image`` with 228 | the correct image tag. 229 | 230 | 231 | Usage 232 | ~~~~~ 233 | 234 | To rewrite a configuration to use image instead of build, and remove any host 235 | specific configuration: 236 | 237 | .. code:: sh 238 | 239 | dcao-merge -o export.yml docker-compose.yml compose-overrides.yml 240 | 241 | Where ``docker-compose.yml`` is: 242 | 243 | .. code:: yaml 244 | 245 | web: 246 | build: . 247 | links: ['db'] 248 | volumes: ['./logs:/app/logs'] 249 | db: 250 | build: database/ 251 | 252 | and ``compose-overrides.yml``: 253 | 254 | .. code:: yaml 255 | 256 | web: 257 | image: example.com/web:latest 258 | volumes: [] 259 | db: 260 | image: example.com/db:latest 261 | 262 | would produce an ``export.yml`` 263 | 264 | .. code:: yaml 265 | 266 | web: 267 | image: example.com/web:latest 268 | links: ['db'] 269 | volumes: [] 270 | db: 271 | image: example.com/db:latest 272 | -------------------------------------------------------------------------------- /compose_addons/__init__.py: -------------------------------------------------------------------------------- 1 | version = '0.2.0' 2 | -------------------------------------------------------------------------------- /compose_addons/config_utils.py: -------------------------------------------------------------------------------- 1 | import yaml 2 | 3 | 4 | def read_config(content): 5 | return yaml.safe_load(content) 6 | 7 | 8 | def write_config(config, target): 9 | yaml.dump( 10 | config, 11 | stream=target, 12 | indent=4, 13 | width=80, 14 | default_flow_style=False) 15 | -------------------------------------------------------------------------------- /compose_addons/includes.py: -------------------------------------------------------------------------------- 1 | """Include and merge docker-compose configurations into a single file. 2 | 3 | Given a docker-compose.yml file, fetch each configuration in the include 4 | section and merge it into a base docker-compose.yml. If any of the included 5 | files have include sections continue to fetch and merge each of them until 6 | there are no more files to include. 7 | 8 | """ 9 | import argparse 10 | import logging 11 | import sys 12 | 13 | import requests 14 | import requests.exceptions 15 | from six.moves.urllib.parse import urlparse 16 | 17 | from compose_addons import version 18 | from compose_addons.config_utils import read_config, write_config 19 | 20 | log = logging.getLogger(__name__) 21 | 22 | 23 | class ConfigError(Exception): 24 | pass 25 | 26 | 27 | class FetchExternalConfigError(ConfigError): 28 | pass 29 | 30 | 31 | def normalize_url(url): 32 | url = urlparse(url) 33 | return url if url.scheme else url._replace(scheme='file') 34 | 35 | 36 | def get_project_from_file(url): 37 | # Handle urls in the form file://./some/relative/path 38 | path = url.netloc + url.path if url.netloc.startswith('.') else url.path 39 | with open(path, 'r') as fh: 40 | return read_config(fh) 41 | 42 | 43 | # TODO: integration test for this 44 | def get_project_from_http(url, config): 45 | try: 46 | response = requests.get( 47 | url.geturl(), 48 | timeout=config.get('timeout', 20), 49 | verify=config.get('verify_ssl_cert', True), 50 | cert=config.get('ssl_cert', None), 51 | proxies=config.get('proxies', None)) 52 | response.raise_for_status() 53 | except requests.exceptions.RequestException as e: 54 | raise FetchExternalConfigError("Failed to include %s: %s" % ( 55 | url.geturl(), e)) 56 | return read_config(response.text) 57 | 58 | 59 | # Return the connection from a function, so it can be mocked in tests 60 | def get_boto_conn(): 61 | # Local import so that boto is only a dependency if it's used 62 | import boto.s3.connection 63 | return boto.s3.connection.S3Connection() 64 | 65 | 66 | def get_project_from_s3(url): 67 | import boto.exception 68 | try: 69 | conn = get_boto_conn() 70 | bucket = conn.get_bucket(url.netloc) 71 | except (boto.exception.BotoServerError, boto.exception.BotoClientError) as e: 72 | raise FetchExternalConfigError( 73 | "Failed to include %s: %s" % (url.geturl(), e)) 74 | 75 | key = bucket.get_key(url.path) 76 | if not key: 77 | raise FetchExternalConfigError( 78 | "Failed to include %s: Not Found" % url.geturl()) 79 | 80 | return read_config(key.get_contents_as_string()) 81 | 82 | 83 | def fetch_external_config(url, fetch_config): 84 | log.info("Fetching config from %s" % url.geturl()) 85 | 86 | if url.scheme in ('http', 'https'): 87 | return get_project_from_http(url, fetch_config) 88 | 89 | if url.scheme == 'file': 90 | return get_project_from_file(url) 91 | 92 | # TODO: pass fetch_config, for timeout 93 | if url.scheme == 's3': 94 | return get_project_from_s3(url) 95 | 96 | raise ConfigError("Unsupported url scheme \"%s\" for %s." % ( 97 | url.scheme, 98 | url)) 99 | 100 | 101 | class ConfigCache(object): 102 | """Cache each config by url. Always return a new copy of the cached dict. 103 | """ 104 | 105 | def __init__(self, fetch_func): 106 | self.cache = {} 107 | self.fetch_func = fetch_func 108 | 109 | def get(self, url): 110 | if url not in self.cache: 111 | self.cache[url] = self.fetch_func(url) 112 | return dict(self.cache[url]) 113 | 114 | 115 | def apply_namespace(name, namespace, service_names): 116 | if name.startswith(namespace) or name not in service_names: 117 | return name 118 | return '%s.%s' % (namespace, name) 119 | 120 | 121 | def merge_configs(base, configs): 122 | for config in configs: 123 | base.update(config) 124 | return base 125 | 126 | 127 | def fetch_includes(base_config, cache): 128 | return [fetch_include(cache, url) for url in base_config.pop('include', [])] 129 | 130 | 131 | def fetch_include(cache, url): 132 | config = cache.get(normalize_url(url)) 133 | 134 | namespace = config.pop('namespace', None) 135 | if not namespace: 136 | raise ConfigError("Configuration %s requires a namespace" % url) 137 | 138 | configs = fetch_includes(config, cache) 139 | return merge_configs(config, configs) 140 | 141 | 142 | def include(base_config, fetch_config): 143 | def fetch(url): 144 | return fetch_external_config(url, fetch_config) 145 | 146 | cache = ConfigCache(fetch) 147 | # Remove the namespace key from the base config, if it exists 148 | base_config.pop('namespace', None) 149 | return merge_configs(base_config, fetch_includes(base_config, cache)) 150 | 151 | 152 | def get_args(args=None): 153 | parser = argparse.ArgumentParser(description=__doc__) 154 | parser.add_argument('--version', action='version', version=version) 155 | parser.add_argument( 156 | 'compose_file', 157 | type=argparse.FileType('r'), 158 | default=sys.stdin, 159 | help="Path to a docker-compose configuration with includes.") 160 | parser.add_argument( 161 | '-o', '--output', 162 | type=argparse.FileType('w'), 163 | default=sys.stdout, 164 | help="Output filename, defaults to stdout.") 165 | # TODO: separate argument group for fetch config args 166 | parser.add_argument( 167 | '--timeout', 168 | help="Timeout used when making network calls.", 169 | type=int) 170 | 171 | return parser.parse_args(args=args) 172 | 173 | 174 | # TODO: other fetch config args 175 | def build_fetch_config(args): 176 | return { 177 | 'timeout': args.timeout, 178 | } 179 | 180 | 181 | def main(args=None): 182 | args = get_args(args=args) 183 | config = include(read_config(args.compose_file), build_fetch_config(args)) 184 | write_config(config, args.output) 185 | -------------------------------------------------------------------------------- /compose_addons/merge.py: -------------------------------------------------------------------------------- 1 | """ 2 | Merge a yaml configuration file with others to produce a single configuration. 3 | 4 | May be used to override a default configuration with temporary or local 5 | configuration options. 6 | 7 | Example: 8 | 9 | From a base configuration, expose volumes and use a different image for 10 | debugging. 11 | 12 | **base.yml** 13 | 14 | .. code-block:: yaml 15 | 16 | web: 17 | build: . 18 | links: 19 | - db 20 | - serviceb 21 | 22 | db: 23 | build: database/ 24 | 25 | serviceb: 26 | image: example.com/services_b:latest 27 | 28 | **overrides.yml** 29 | 30 | .. code-block:: yaml 31 | 32 | web: 33 | volumes: 34 | - '.:/code' 35 | 36 | serviceb: 37 | image: my_version_of_service_b:abf4a 38 | 39 | 40 | Run: 41 | 42 | .. code-block:: sh 43 | 44 | 45 | $ fig-merge base.yml overrides.yml > fig.yml 46 | 47 | 48 | **fig.yml** would contain: 49 | 50 | 51 | .. code-block:: yaml 52 | 53 | web: 54 | build: . 55 | links: 56 | - db 57 | - serviceb 58 | volumes: 59 | - '.:/code' 60 | 61 | db: 62 | build: database/ 63 | 64 | serviceb: 65 | image: my_version_of_service_b:abf4a 66 | """ 67 | import argparse 68 | import sys 69 | 70 | import yaml 71 | 72 | 73 | def deep_merge(base, override): 74 | def merge(base, override): 75 | for key in set(base) | set(override): 76 | value = override.get(key, base.get(key)) 77 | if isinstance(value, dict): 78 | yield key, dict(merge( 79 | base.get(key) or {}, 80 | override.get(key) or {})) 81 | else: 82 | yield key, value 83 | 84 | return dict(merge(base, override)) 85 | 86 | 87 | def merge_config(base, override): 88 | for name, service in base.items(): 89 | if 'build' in service and 'image' in override.get(name, {}): 90 | service.pop('build') 91 | if 'image' in service and 'build' in override.get(name, {}): 92 | service.pop('image') 93 | return deep_merge(base, override) 94 | 95 | 96 | def merge_files(base, overrides, output): 97 | base = yaml.load(base) 98 | for override in overrides: 99 | base = merge_config(base, yaml.load(override)) 100 | 101 | yaml.dump(base, output, default_flow_style=False, width=80, indent=4) 102 | 103 | 104 | def parse_args(args): 105 | parser = argparse.ArgumentParser(description='Merge configuration files.') 106 | parser.add_argument( 107 | 'base', 108 | type=argparse.FileType('r'), 109 | help="Base configuration file.") 110 | parser.add_argument( 111 | 'files', 112 | type=argparse.FileType('r'), 113 | nargs="+", 114 | help="Files to merge onto the base.") 115 | parser.add_argument( 116 | '-o', '--output', 117 | type=argparse.FileType('w'), 118 | default=sys.stdout, 119 | help="Output file, defaults to stdout.") 120 | return parser.parse_args(args=args) 121 | 122 | 123 | def main(args=None): 124 | args = parse_args(args) 125 | merge_files(args.base, args.files, args.output) 126 | 127 | 128 | if __name__ == "__main__": 129 | main() 130 | -------------------------------------------------------------------------------- /compose_addons/namespace.py: -------------------------------------------------------------------------------- 1 | """Namespace services in a docker-compose.yml so they can be used as an include. 2 | 3 | Service names, links, net, and volumes from are updated to include a prefix 4 | and a ``namespace`` key is added to the configuration with this prefix. 5 | """ 6 | import argparse 7 | import sys 8 | from functools import partial 9 | 10 | from compose_addons import version 11 | from compose_addons.config_utils import read_config, write_config 12 | 13 | 14 | def add_namespace(config, namespace): 15 | service_names = set(config) 16 | prefix = namespace + '.' 17 | 18 | def add_to_service(name, service_config): 19 | namespace_links(service_config, prefix, service_names) 20 | namespace_volumes_from(service_config, prefix, service_names) 21 | namespace_net(service_config, prefix, service_names) 22 | return prefix + name, service_config 23 | 24 | config = dict( 25 | add_to_service(service, conf) 26 | for service, conf in config.items() 27 | ) 28 | config['namespace'] = namespace 29 | return config 30 | 31 | 32 | def namespace_volumes_from(service, namespace, service_names): 33 | def namespace_each(service): 34 | if service not in service_names: 35 | return service 36 | return namespace + service 37 | 38 | set_field(service, 'volumes_from', partial(list_map, namespace_each)) 39 | 40 | 41 | def namespace_links(service, namespace, service_names): 42 | def namespace_link(link): 43 | service, alias = parse_field(link, 2) 44 | alias = alias or service 45 | if service not in service_names: 46 | return link 47 | return '%s:%s' % (namespace + service, alias) 48 | 49 | set_field(service, 'links', partial(list_map, namespace_link)) 50 | 51 | 52 | def namespace_net(service, namespace, service_names): 53 | def namespace_field(value): 54 | type, name = parse_field(value, 2) 55 | if type != 'container' or name not in service_names: 56 | return value 57 | return 'container:' + namespace + name 58 | 59 | set_field(service, 'net', namespace_field) 60 | 61 | 62 | def list_map(func, seq): 63 | return list(map(func, seq)) 64 | 65 | 66 | def set_field(service, field, partial_func): 67 | if field not in service: 68 | return 69 | service[field] = partial_func(service[field]) 70 | 71 | 72 | def parse_field(field, length): 73 | parts = field.split(':', length - 1) 74 | return parts + [None] * (length - len(parts)) 75 | 76 | 77 | def get_args(args=None): 78 | parser = argparse.ArgumentParser(description=__doc__) 79 | parser.add_argument('--version', action='version', version=version) 80 | parser.add_argument( 81 | 'compose_file', 82 | type=argparse.FileType('r'), 83 | default=sys.stdin, 84 | help="Path to a docker-compose configuration to namespace.") 85 | parser.add_argument( 86 | 'namespace', 87 | help="Namespace to add to all service names.") 88 | parser.add_argument( 89 | '-o', '--output', 90 | type=argparse.FileType('w'), 91 | default=sys.stdout, 92 | help="Output filename, defaults to stdout.") 93 | 94 | return parser.parse_args(args=args) 95 | 96 | 97 | def main(args=None): 98 | args = get_args(args=args) 99 | config = add_namespace(read_config(args.compose_file), args.namespace) 100 | write_config(config, args.output) 101 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | 3 | from compose_addons import version 4 | 5 | setup( 6 | name="compose-addons", 7 | version=version, 8 | provides=["compose_addons"], 9 | author="Daniel Nephin", 10 | author_email="dnephin@gmail.com", 11 | url="http://github.com/dnephin/compose-addons", 12 | description='Tools to supplement', 13 | classifiers=[ 14 | "Programming Language :: Python", 15 | "Operating System :: OS Independent", 16 | "License :: OSI Approved :: Apache Software License", 17 | "Intended Audience :: Developers", 18 | ], 19 | license="Apache License 2.0", 20 | packages=['compose_addons'], 21 | install_requires=[ 22 | 'requests', 23 | 'six', 24 | 'pyyaml', 25 | ], 26 | extras_require={ 27 | 's3': ['boto'], 28 | }, 29 | entry_points={ 30 | 'console_scripts': [ 31 | 'dcao-include = compose_addons.includes:main', 32 | 'dcao-namespace = compose_addons.namespace:main', 33 | 'dcao-merge = compose_addons.merge:main', 34 | ], 35 | }, 36 | ) 37 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnephin/compose-addons/75edb1c6ba5cd2c997147d7c59adf17b197e582b/tests/__init__.py -------------------------------------------------------------------------------- /tests/includes_test.py: -------------------------------------------------------------------------------- 1 | import boto.exception 2 | import boto.s3.connection 3 | import mock 4 | import pytest 5 | import yaml 6 | 7 | from compose_addons import includes 8 | from compose_addons.includes import ( 9 | ConfigCache, 10 | ConfigError, 11 | FetchExternalConfigError, 12 | fetch_external_config, 13 | get_project_from_file, 14 | get_project_from_s3, 15 | normalize_url, 16 | ) 17 | 18 | 19 | def test_normalize_url_with_scheme(): 20 | url = normalize_url('HTTPS://example.com') 21 | assert url.scheme == 'https' 22 | 23 | 24 | def test_normalize_url_without_scheme(): 25 | url = normalize_url('./path/to/somewhere') 26 | assert url.scheme == 'file' 27 | 28 | 29 | class TestGetProjectFromS3Test(object): 30 | 31 | @mock.patch('compose_addons.includes.get_boto_conn', autospec=True) 32 | def test_get_project_from_s3(self, mock_get_conn): 33 | mock_bucket = mock_get_conn.return_value.get_bucket.return_value 34 | mock_key = mock_bucket.get_key.return_value 35 | mock_key.get_contents_as_string.return_value = 'foo:\n build: .' 36 | url = normalize_url('s3://bucket/path/to/key/compose_addons.yml') 37 | 38 | project = get_project_from_s3(url) 39 | assert project == {'foo': {'build': '.'}} 40 | 41 | mock_get_conn.assert_called_once_with() 42 | mock_get_conn.return_value.get_bucket.assert_called_once_with('bucket') 43 | mock_bucket.get_key.assert_called_once_with( 44 | '/path/to/key/compose_addons.yml') 45 | 46 | @mock.patch('compose_addons.includes.get_boto_conn', autospec=True) 47 | def test_get_project_from_s3_not_found(self, mock_get_conn): 48 | mock_bucket = mock_get_conn.return_value.get_bucket.return_value 49 | mock_bucket.get_key.return_value = None 50 | url = normalize_url('s3://bucket/path/to/key/compose_addons.yml') 51 | 52 | with pytest.raises(FetchExternalConfigError) as exc_context: 53 | get_project_from_s3(url) 54 | expected = "Failed to include %s: Not Found" % url.geturl() 55 | assert expected in str(exc_context.exconly()) 56 | 57 | @mock.patch('compose_addons.includes.get_boto_conn', autospec=True) 58 | def test_get_project_from_s3_bucket_error(self, mock_get_conn): 59 | mock_get_bucket = mock_get_conn.return_value.get_bucket 60 | mock_get_bucket.side_effect = boto.exception.S3ResponseError( 61 | 404, "Bucket Not Found") 62 | 63 | url = normalize_url('s3://bucket/path/to/key/fig.yml') 64 | with pytest.raises(FetchExternalConfigError) as exc_context: 65 | get_project_from_s3(url) 66 | 67 | expected = ( 68 | "Failed to include %s: " 69 | "S3ResponseError: 404 Bucket Not Found" % url.geturl()) 70 | assert expected in str(exc_context.exconly()) 71 | 72 | 73 | @pytest.fixture 74 | def local_config(tmpdir): 75 | filename = tmpdir.join('fig.yml') 76 | 77 | filename.write(""" 78 | web: 79 | image: example/web:latest 80 | db: 81 | image: example/db:latest 82 | """) 83 | return filename 84 | 85 | 86 | class TestGetProjectFromFile(object): 87 | 88 | expected = {'web', 'db'} 89 | 90 | def test_fetch_from_file_relative_no_context(self, local_config): 91 | with local_config.dirpath().as_cwd(): 92 | config = get_project_from_file(normalize_url(local_config.basename)) 93 | assert set(config.keys()) == self.expected 94 | 95 | def test_fetch_from_file_relative_with_context(self, local_config): 96 | url = './' + local_config.basename 97 | with local_config.dirpath().as_cwd(): 98 | config = get_project_from_file(normalize_url(url)) 99 | assert set(config.keys()) == self.expected 100 | 101 | def test_fetch_from_file_absolute_path(self, local_config): 102 | config = get_project_from_file(normalize_url(str(local_config))) 103 | assert set(config.keys()) == self.expected 104 | 105 | def test_fetch_from_file_relative_with_scheme(self, local_config): 106 | url = 'file://./' + local_config.basename 107 | with local_config.dirpath().as_cwd(): 108 | config = get_project_from_file(normalize_url(url)) 109 | assert set(config.keys()) == self.expected 110 | 111 | def test_fetch_from_file_absolute_with_scheme(self, local_config): 112 | url = 'file://' + str(local_config) 113 | with local_config.dirpath().as_cwd(): 114 | config = get_project_from_file(normalize_url(url)) 115 | assert set(config.keys()) == self.expected 116 | 117 | 118 | class TestFetchExternalConfig(object): 119 | 120 | def test_unsupported_scheme(self): 121 | with pytest.raises(ConfigError) as exc: 122 | fetch_external_config(normalize_url("bogus://something"), None) 123 | assert 'Unsupported url scheme "bogus"' in str(exc.exconly()) 124 | 125 | def test_fetch_from_file(self, local_config): 126 | config = fetch_external_config(normalize_url(str(local_config)), None) 127 | assert set(config.keys()) == {'db', 'web'} 128 | 129 | 130 | def test_config_cache(): 131 | url, fetch_func = mock.Mock(), mock.Mock(return_value=dict(a=1)) 132 | cache = ConfigCache(fetch_func) 133 | assert cache.get(url) == fetch_func.return_value 134 | assert cache.get(url) == fetch_func.return_value 135 | assert cache.get(url) is not fetch_func.return_value 136 | fetch_func.assert_called_once_with(url) 137 | 138 | 139 | def test_merge_configs(): 140 | result = includes.merge_configs(dict(a=1), [dict(b=2), dict(c=3, d=4)]) 141 | assert result == dict(a=1, b=2, c=3, d=4) 142 | 143 | 144 | def test_fetch_includes_no_includes(): 145 | config = {'web': {'image': 'foo'}} 146 | assert includes.fetch_includes(config, {}) == [] 147 | 148 | 149 | def test_fetch_include_missing_namespace(): 150 | url = 'http://example.com/project.yml' 151 | cache = mock.create_autospec(ConfigCache) 152 | cache.get.return_value = {} 153 | with pytest.raises(ConfigError) as exc: 154 | includes.fetch_include(cache, url) 155 | expected = "Configuration %s requires a namespace" % url 156 | assert expected in str(exc.exconly()) 157 | 158 | 159 | def test_fetch_include(): 160 | url = 'http://example.com/project.yml' 161 | fetch_func = mock.Mock(side_effect=[ 162 | { 163 | 'namespace': 'a', 164 | 'include': ['b', 'c'], 165 | 'a.web': {'image': 'a', 'links': ['b.web', 'c.web', 'a.db']}, 166 | 'a.db': {'image': 'db'}, 167 | }, 168 | { 169 | 'namespace': 'b', 170 | 'include': ['c'], 171 | 'b.web': {'image': 'b', 'links': ['c.web']}, 172 | }, 173 | { 174 | 'namespace': 'c', 175 | 'c.web': {'image': 'c'}, 176 | }, 177 | ]) 178 | cache = ConfigCache(fetch_func) 179 | config = includes.fetch_include(cache, url) 180 | expected = { 181 | 'a.web': {'image': 'a', 'links': ['b.web', 'c.web', 'a.db']}, 182 | 'a.db': {'image': 'db'}, 183 | 'b.web': {'image': 'b', 'links': ['c.web']}, 184 | 'c.web': {'image': 'c'}, 185 | } 186 | assert config == expected 187 | 188 | 189 | @pytest.mark.acceptance 190 | def test_include_end_to_end(tmpdir, capsys): 191 | tmpdir.join('docker-compose.yml').write(""" 192 | include: 193 | - ./api_a/docker-compose.yml 194 | - ./api_b/docker-compose.yml 195 | namespace: core 196 | web: 197 | image: example/web:latest 198 | links: ['api_a.web', 'db', 'api_b.web'] 199 | volumes_from: ['configs'] 200 | db: 201 | image: example/db:latest 202 | configs: 203 | image: example/configs:latest 204 | """) 205 | tmpdir.mkdir('api_a').join('docker-compose.yml').write(""" 206 | include: 207 | - ./api_b/docker-compose.yml 208 | namespace: api_a 209 | api_a.web: 210 | image: services/a:latest 211 | links: ['api_a.db', 'api_b.web'] 212 | api_a.db: 213 | image: services/db_a:latest 214 | """) 215 | tmpdir.mkdir('api_b').join('docker-compose.yml').write(""" 216 | namespace: api_b 217 | api_b.web: 218 | image: services/b:latest 219 | """) 220 | 221 | expected = { 222 | 'web': { 223 | 'image': 'example/web:latest', 224 | 'links': ['api_a.web', 'db', 'api_b.web'], 225 | 'volumes_from': ['configs'], 226 | }, 227 | 'db': {'image': 'example/db:latest'}, 228 | 'configs': {'image': 'example/configs:latest'}, 229 | 'api_a.web': { 230 | 'image': 'services/a:latest', 231 | 'links': ['api_a.db', 'api_b.web'], 232 | }, 233 | 'api_a.db': {'image': 'services/db_a:latest'}, 234 | 'api_b.web': {'image': 'services/b:latest'}, 235 | } 236 | 237 | with tmpdir.as_cwd(): 238 | includes.main(args=['docker-compose.yml']) 239 | out, err = capsys.readouterr() 240 | assert yaml.load(out) == expected 241 | -------------------------------------------------------------------------------- /tests/merge_test.py: -------------------------------------------------------------------------------- 1 | import textwrap 2 | 3 | import pytest 4 | import yaml 5 | 6 | from compose_addons import merge 7 | 8 | 9 | def test_merge_file_build_to_image(): 10 | base = { 11 | 'web': { 12 | 'build': '.', 13 | 'ports': [] 14 | } 15 | } 16 | override = { 17 | 'web': { 18 | 'image': 'service:latest', 19 | 'environment': [], 20 | } 21 | } 22 | expected = { 23 | 'web': { 24 | 'image': 'service:latest', 25 | 'environment': [], 26 | 'ports': [], 27 | } 28 | } 29 | assert merge.merge_config(base, override) == expected 30 | 31 | 32 | def test_merge_file_image_to_build(): 33 | base = { 34 | 'web': { 35 | 'image': 'service:latest', 36 | 'ports': [] 37 | } 38 | } 39 | override = { 40 | 'web': { 41 | 'build': '.', 42 | 'environment': [], 43 | } 44 | } 45 | expected = { 46 | 'web': { 47 | 'build': '.', 48 | 'environment': [], 49 | 'ports': [], 50 | } 51 | } 52 | assert merge.merge_config(base, override) == expected 53 | 54 | 55 | @pytest.mark.acceptance 56 | def test_merge_end_to_end(tmpdir, capsys): 57 | tmpdir.join('base.yaml').write(textwrap.dedent(""" 58 | web: 59 | build: . 60 | links: 61 | - db 62 | - serviceb 63 | 64 | db: 65 | build: database/ 66 | 67 | serviceb: 68 | image: example.com/services_b:latest 69 | """)) 70 | tmpdir.join('overrides.yaml').write(textwrap.dedent(""" 71 | web: 72 | volumes: 73 | - '.:/code' 74 | 75 | serviceb: 76 | image: my_version_of_service_b:abf4a 77 | """)) 78 | 79 | expected = { 80 | 'web': { 81 | 'build': '.', 82 | 'links': ['db', 'serviceb'], 83 | 'volumes': ['.:/code'], 84 | }, 85 | 'db': { 86 | 'build': 'database/', 87 | }, 88 | 'serviceb': { 89 | 'image': 'my_version_of_service_b:abf4a', 90 | } 91 | } 92 | 93 | with tmpdir.as_cwd(): 94 | merge.main(['base.yaml', 'overrides.yaml']) 95 | 96 | out, err = capsys.readouterr() 97 | assert yaml.load(out) == expected 98 | -------------------------------------------------------------------------------- /tests/namespace_test.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | import yaml 3 | 4 | from compose_addons import namespace 5 | 6 | 7 | def test_add_namespace(): 8 | config = { 9 | 'web': { 10 | 'image': 'example/web', 11 | 'links': ['db:alias', 'other', 'external.web'], 12 | 'volumes_from': ['config', 'external.config'], 13 | 'net': 'container:db', 14 | }, 15 | 'db': { 16 | 'image': 'example/db', 17 | 'environment': ['isstillhere=yes'], 18 | }, 19 | 'config': {'image': 'example/config'}, 20 | 'other': { 21 | 'image': 'example/other', 22 | 'links': ['db'], 23 | }, 24 | } 25 | expected = { 26 | 'namespace': 'star', 27 | 'star.web': { 28 | 'image': 'example/web', 29 | 'links': ['star.db:alias', 'star.other:other', 'external.web'], 30 | 'volumes_from': ['star.config', 'external.config'], 31 | 'net': 'container:star.db', 32 | }, 33 | 'star.db': { 34 | 'image': 'example/db', 35 | 'environment': ['isstillhere=yes'], 36 | }, 37 | 'star.config': {'image': 'example/config'}, 38 | 'star.other': { 39 | 'image': 'example/other', 40 | 'links': ['star.db:db'], 41 | }, 42 | } 43 | 44 | result = namespace.add_namespace(config, 'star') 45 | assert result == expected 46 | 47 | 48 | def test_parse_field_exact(): 49 | assert namespace.parse_field('a:b:c:d', 4) == ['a', 'b', 'c', 'd'] 50 | 51 | 52 | def test_parse_field_under(): 53 | assert namespace.parse_field('a', 3) == ['a', None, None] 54 | assert namespace.parse_field('a:b', 3) == ['a', 'b', None] 55 | 56 | 57 | def test_parse_field_over(): 58 | assert namespace.parse_field('a:b:c:d', 2) == ['a', 'b:c:d'] 59 | 60 | 61 | def test_namespace_net_not_container(): 62 | service = orig = {'net': 'host'} 63 | namespace.namespace_net(service, 'namespace', {'host'}) 64 | assert service == orig 65 | 66 | 67 | def test_namespace_net_external_service(): 68 | service = orig = {'net': 'container:ext.foo'} 69 | namespace.namespace_net(service, 'namespace', {'db', 'config'}) 70 | assert service == orig 71 | 72 | 73 | def test_namespace_net_internal_service(): 74 | service = {'net': 'container:db'} 75 | namespace.namespace_net(service, 'namespace.', {'db', 'config'}) 76 | assert service == {'net': 'container:namespace.db'} 77 | 78 | 79 | @pytest.mark.acceptance 80 | def test_namespace_end_to_end(tmpdir): 81 | tmpdir.join('docker-compose.yml').write(""" 82 | web: 83 | image: example/web:latest 84 | links: [db] 85 | volumes_from: [config] 86 | db: 87 | image: example/db:latest 88 | environment: ['REPO=/db'] 89 | config: 90 | image: example/config:latest 91 | """) 92 | 93 | expected = { 94 | 'namespace': 'servicea', 95 | 'servicea.web': { 96 | 'image': 'example/web:latest', 97 | 'links': ['servicea.db:db'], 98 | 'volumes_from': ['servicea.config'], 99 | }, 100 | 'servicea.db': { 101 | 'image': 'example/db:latest', 102 | 'environment': ['REPO=/db'], 103 | }, 104 | 'servicea.config': { 105 | 'image': 'example/config:latest', 106 | }, 107 | } 108 | 109 | with tmpdir.as_cwd(): 110 | namespace.main(args=['-o', 'out.yml', 'docker-compose.yml', 'servicea']) 111 | assert yaml.load(tmpdir.join('out.yml').read()) == expected 112 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | [tox] 2 | envlist = py27,py34 3 | 4 | [testenv] 5 | deps = 6 | pytest 7 | mock 8 | flake8 9 | boto 10 | commands = 11 | py.test -v --tb=short {posargs:tests} 12 | flake8 compose_addons tests setup.py 13 | 14 | [testenv:docs] 15 | deps = 16 | {[testenv]deps} 17 | sphinx >= 1.0 18 | sphinx_rtd_theme 19 | changedir = docs 20 | commands = 21 | sphinx-build -b html -d build/doctrees source build/html 22 | 23 | [flake8] 24 | max-line-length = 85 25 | --------------------------------------------------------------------------------