-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plugin system for compose #3905
Conversation
4217719
to
a0c9988
Compare
Signed-off-by: Alexander Schneider <alexanderschneider85@gmail.com>
Signed-off-by: Alexander Schneider <alexanderschneider85@gmail.com>
Write plugin class tests Make sure that all existing tests pass Signed-off-by: Alexander Schneider <alexanderschneider85@gmail.com>
Add decorators for adding commands and patching functions Remove redundant functions Signed-off-by: Alexander Schneider <alexanderschneider85@gmail.com>
Signed-off-by: Alexander Schneider <alexanderschneider85@gmail.com>
Signed-off-by: Alexander Schneider <alexanderschneider85@gmail.com>
Signed-off-by: Alexander Schneider <alexanderschneider85@gmail.com>
Signed-off-by: Alexander Schneider <alexanderschneider85@gmail.com>
Signed-off-by: Alexander Schneider <alexanderschneider85@gmail.com>
Add old version for plugin update method Signed-off-by: Alexander Schneider <alexanderschneider85@gmail.com>
Signed-off-by: Alexander Schneider <alexanderschneider85@gmail.com>
Signed-off-by: Alexander Schneider <alexanderschneider85@gmail.com>
…stem Signed-off-by: Alexander Schneider <alexanderschneider85@gmail.com>
a0c9988
to
92b5a62
Compare
67a21f4
to
92b5a62
Compare
…stem Signed-off-by: Alexander Schneider <alexanderschneider85@gmail.com>
Adjust config v2.1 test Signed-off-by: Alexander Schneider <alexanderschneider85@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally would to see this appear in docker-compose as it would allow those (like myself) who have some corner case projects that docker-compose almost covers but not quite fill, to implement a plugin to cover the project needs rather than having to wrap it with scripts or look at different tools to replace it completely.
command_help = cleandoc(self.command_class.__modified_doc__) | ||
else: | ||
command_help = getdoc(self.command_class) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was http://bugs.python.org/issue12773 not fixed before python 3.3 released?
https://github.com/python/cpython/blob/3.3/Misc/NEWS#L4652 suggests it was, and testing against python 2.7.12, 3.3.5 and 3.5 locally there doesn't appear to be an issue in mutating the __doc__
string on user defined classes. So wondering if this part is really needed?
except (errors.ConnectionError, StreamParseError): | ||
sys.exit(1) | ||
|
||
|
||
def dispatch(): | ||
plugin_manager = PluginManager(get_plugin_dir()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be after setup_logging() in case you need to log something from the PluginManager class setup?
Just found you PR and curious: wouldn't it be more consistent to use yaml instead of JSON? |
@andreyrusanov I used json for the package description because other package managers like composer and npm using it. But there is no preference by my side and switching to yaml shouldn't be the problem. But first I need some feedback from the docker guys if the PR has a change to get merged, before I invest more time. |
@@ -1,3 +1,4 @@ | |||
.idea |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be in your global gitignore file. Or edit $repo_dir/info/exclude
I understand this took time and effort to bring to life, and I thank you for sharing it with us and offering to contribute to the project. Unfortunately this is not something we can commit to supporting in the long term, and as such, I don't see us ever merging this. Thank you nevertheless. Maybe this can live as a fork of the project if there's interest? |
@shin- does that mean that you don't want to support hooks/plugins at all? see issues #374 & #1341, seems like people want a way to cover a small number of scenarios around the edges. My personal use case would have been to use a different build command rather. Mainly around the possibility of optimization such as working out from a multiple set of Dockerfiles what base images are common to each and also what tag identifies the resulting container in case I want to use it as a base image for one of the other services as well. Additionally might want to template our Dockerfiles to resolve some information dynamically to be recorded as labels (e.g. have a git command use a specific branch and resolve to SHA1 that is stored in both the RUN command and labels for searching). Maybe some enhancements might subsequently move into docker-compose but right now it seems like can't use docker-compose as the entry point, and it's unclear as to whether any changes would ever get accepted if we forked. Instead something else will have to do it, and that seems to make it more likely that adopting a different tool-chain entirely would be more useful in the long term. |
What?
This pull request introduces an plugin system for docker compose. The plugin system uses python packages as plugin which
makes it easy to use the already existing classes and functions from compose.
Why?
There is always a missing functionality in your application software. A plugin system gives you the ability to extend
existing or add new functionalities. In addition it keeps the core clean, slim and result in more robust software.
How?
The pull request adds a new command plugin to docker-compose. The plugin has the following sub commands:
Minimal plugin example
The following describes a minimal plugin setup and could be used as boilerplate code.
docker-compose.yml
There is a new entry for the
docker-compose.yml
calledplugins
where the config for the plugin can be set. If aplugin is listed here it's required and it will be checked if the plugin is installed after the config was loaded. The
version option is optional and defines the lowest required version of the plugin. The setting made under options are
passed through the constructor of the plugin class as dictionary.
Folder structure
init.py
plugin.json
New decorators
The are two new decorator which makes it easy to monkey patch existing functions/methods (
compose_patch
) and addnew commands (
compose_command
).@compose_patch(compose.service.Service, "build")
compose_command
Restrictions
command executed at the plugin dir:
pip install --target=${PWD}/libs THIRD_PARTY_PACKAGE
TODOs
Example plugin
For an example plugin see: https://github.com/GM-Alex/compose-bi