Implement service profiles#7930
Conversation
acran
left a comment
There was a problem hiding this comment.
I comment on some code lines which probably require some attention
| 'active profiles. ' | ||
| 'You may fix this by adding a common profile to ' | ||
| '"{dep_name}" and "{service_name}".' | ||
| .format(dep_name=dep.name, service_name=service.name) |
There was a problem hiding this comment.
Is this a suitable error message making it clear to the user what went wrong, why and how to fix it?
|
|
||
| def remove_images(self, remove_image_type): | ||
| for service in self.get_services(): | ||
| for service in self.services: |
There was a problem hiding this comment.
The call to self.get_services was actually unnecessary before, since without any parameters it would just return self.services.
But now it would filter services by enabled profiles, so this was changed so remove_images and thus down would act on all defined services.
|
|
||
| def restart(self, service_names=None, **options): | ||
| # filter service_names by enabled profiles | ||
| service_names = [s.name for s in self.get_services(service_names)] |
There was a problem hiding this comment.
restart should consider the enabled profiles so to not start services disabled by profile with docker-compose restart
|
@acran Can you rebase please? |
|
@aiordache yes, done |
ulyssessouza
left a comment
There was a problem hiding this comment.
LGTM in general, just missing changes
Implement profiles as introduced in compose-spec/compose-spec#110 fixes docker#7919 closes docker#1896 closes docker#6742 closes docker#7539 Signed-off-by: Roman Anasal <[email protected]>
|
I updated the PR again with the feedback from @ulyssessouza. For this I did a little refactoring and created |
ulyssessouza
left a comment
There was a problem hiding this comment.
LGTM
Thanks @acran !
Adds docs for the new service profiles feature introduced in docker/compose#7930
Adds docs for the new service profiles feature introduced in docker/compose#7930 Co-authored-by: Chris Crone <[email protected]>
Adds docs for the new service profiles feature introduced in docker/compose#7930 Co-authored-by: Chris Crone <[email protected]>
Implement profiles as introduced in compose-spec/compose-spec#110
This is a first draft and probably needs some more discussion. Things I'm not quite sure about yet which may need further discussion:
How to specify profiles to enable
--profileflag for the main command, multiple profiles may be passedCOMPOSE_PROFILEwith:as separator for multiple profilesprofilesof a service from multiple configuration files are just added togetherprofilesoption all together with override configurations. Should there be?Affected commands
The main logic is implemented in
Project.get_services()which was already used in the code paths for and therefor add profiles support to:buildcreateupstartpullpushThe following functions use
Project.containers()instead which is unchanged and therefor ignore profiles:stopdownremove_stoppedwhich already usedProject.containers()remove_imageswhich I changed to ignore profiles to be consistent with the restpauseunpausekillI couldn't quite decide if the latter commands should be consider profiles, too, because the behavior expected by the user would most probably not consider them, most notably with
docker-compose down:Executing
docker-compose downthe user expects that all defined services will be removed. But services assigned to specific profiles only could be missed here whendocker-compose downis called without enabling those profiles.Then those services would need to be considered orphans. But this would be inconsistent with notion of orphans since those services are actually defined in the configuration, just not enabled.
On the other hand
docker-compose --profile foo downmight suggest that services with thefooprofile only would be removed, but actually the spec would require all services without profiles and services with thefooprofile.That's why I thought it to be most consistent/intuitive for
docker-compose downand the other commands to just ignore profiles and act on all defined services (and because changing the logic ofProject.containers()would require the refactoring/verification of a whole lot more code paths and tests).Tests
Using the example
docker-compose.ymlfrom compose-spec/compose-spec#110 I implemented a test case for each of the examples in the spec as well as an extra test case for merging profiles from multiple configuration files.Are there more tests needed here?
Small disclaimer: Since I'm neither familiar with the code base nor python even, please don't hold back with any feedback on the coding style/formatting/performance :)
Resolves #7919, #1896, #6742, #7539