[FEATURE] Multi service docker support#99
[FEATURE] Multi service docker support#99jakeberesford-palmetto wants to merge 45 commits intopalmetto:developfrom
Conversation
norton120
left a comment
There was a problem hiding this comment.
few nitts but great addition!
| own command, ensure you use the ``@click.pass_obj`` decorator for your command, | ||
| then use ``environment.run_in_docker(command)``. | ||
|
|
||
| Note that in multi-service applications, ``run_in_docker`` will run proxy your command |
There was a problem hiding this comment.
future iteration, should we have it say things like that with maybe an --plan flag? that instead of running the command, it describes in detail what the command would do?
| plugin_name = self.plugin_manager.plugin_command_dict.get( | ||
| subcommand | ||
| ) | ||
| plugin_name = plugin_name.replace("_", " ") |
There was a problem hiding this comment.
❤️ this has bit me before trying to be smarter than the service
| Returns: | ||
| str: The name of the running service | ||
| """ | ||
| cmd = 'docker ps -a --filter name={service} --format {{{{.Names}}}}'.format( |
There was a problem hiding this comment.
eventually it'd be nice to move to dockerpy, but at the same time it looks like Docker is (terrifyingly enough) slowing down support for dockerpy - so shelling may stay the safest option long-run
| click.secho( | ||
| "This command is only available in multi-service repos", fg="red" | ||
| ) | ||
| raise Exception("exec_in_docker only available in multi-service repos") |
There was a problem hiding this comment.
nitt - should it link you to the docs on how to enable multiservice? lots of editors like vscode will give you an easy cmd+ to open the link from the response in the browser
| is not found or does not have a config | ||
| """ | ||
| plugin = self.plugin_manager.plugins.get(plugin_name) | ||
| plugin = self.get_plugin(plugin_name) |
There was a problem hiding this comment.
way nicer interface here 💥
|
|
||
| def __init__( | ||
| self, | ||
| message: str = "No running services found, start your services with `palm up` and try again", |
| def cli(environment, flags: tuple): | ||
| """Bring up all services""" | ||
| # This sucks. Don't commit this. | ||
| flags = [f"-{flag}" if len(flag) == 1 else f"--{flag}" for flag in flags] |
There was a problem hiding this comment.
can you just do [f"--{flag}" for flag in flags] and let it join the single element?
|
|
||
| @click.command("up") | ||
| @click.option( | ||
| "--no-detach", "-nd", is_flag=True, help="Run containers in the background." |
There was a problem hiding this comment.
should the help be "don't run containers in the background?"
| from collections import OrderedDict | ||
|
|
||
|
|
||
| def choice_prompt(prompt: str, options: List[str]) -> str: |
…m init` which is much easier to remember.
- Add new multi-service plugin - Add detection of multi-service docker setup - Add container selection to run_in_docker
Adds new UI to allow users to select from a list
This will be used to get a list of services to support multi-service projects, but may be extended in the future to provide additional information about the docker configuration
- default to showing last 50 log lines
Allows users to exec arbitrary commands in any running container.
Create shared abstraction for choice prompt, this is useful in many contexts, not only environment.
This could be useful for other features and provides a consistent way to access the compose yml
…want. - Get a list of service names - Check to make sure some services are running - Make exec_in_docker work as expected
Auto installing could lead to regressions for projects already using palm some projects may have secondary services that most users do not interact with directly forcing them into multi-service makes the UX of palm weird
5bb0b99 to
0462082
Compare
Pull request checklist
Before submitting your PR, please review the following checklist:
palm test)palm lint) has passed locally and any fixes were made for failuresBreaking changes
What does this implement/fix? Explain your changes.
Adds support for projects with multiple services in docker-compose.
Palm was originally built for very simple applications with a single 'primary' service. This has worked well for our needs, but doesn't allow folks to use palm for more complex projects.
Does this close any currently open issues?
#16
Any other comments?
I also added some new utilities to support this functionality:
environment.get_pluginallows you to get a plugin by name, useful if a plugin provides a method for re-useenvironment.palmHousekeeping:
palm scaffold config- this was replaced bypalm initlong ago and is unused.Note: This is still a WIP. I need to add tests and docs for all of this. Opening the PR now to get feedback on the functionality from users.
Testing instructions
To test this functionality, you will need a codebase with multiple docker services in your compose file.
python3 -m pip install .palm initto set your repo up for using palm if you haven't already done so..palm/config.yamlit should look like this:palmto see available commands, you should see a section for 'Multi Service' with up/down/logs/exec - try them out!Don't forget to re-install palm from pypi after you're done testing!
pip install -U palmWhere has this been tested?
Operating System: MacOS
Platform: Python 3.9