-
Notifications
You must be signed in to change notification settings - Fork 30
Description
Context
This Ansible module uses its own parameters to support various docker run command line arguments.
Out of those, multiple types are used:
- Single strings
- Lists
Examples for single strings:
container_networkmaps to--networkcontainer_usermaps to--usercontainer_hostnamemaps to--hostname
Examples for lists:
container_volumesmaps to--volumecontainer_portsmaps to--publishcontainer_hostsmaps to--add-host
This is great and marks explicitly how to use this module.
The big downside on this: You need to add additional support for each docker run command line argument into this module. And the docker run reference is looooong.
One proposal would be to make this Ansible more flexible and avoid the burden of implementing every single docker run command line argument by offering ways to add arbitrarily
- key -> value pairs (for single string values that are only allowed once in a docker run cmd, like
--user) - key -> list[value] pairs (for docker run cmd arguments that are allowed multiple times like
--volume)
How a possible Ansible usage can look like in the future / Usage of the module:
- name: Start image
include_role:
name: mhutter.docker-systemd-service
vars:
container_name: "hello-world"
container_image: "hello:v1"
container_docker_pull_force_source: false
container_single_args:
network: my-network
user: nonroot
hostname: world
[...]
container_multi_args:
publish:
- '127.0.0.1:3030:3000'
- '127.0.0.1:1234:5678'
volume:
- '/opt/foo:/var/lib/bar:rw'
[...]
[...]The top-level keys under container_single_args and container_multi_args are not validated They can be defined to whatever you want.
A few keys, like container_image might be good to keep separate, primarily when those are used in a different context (e.g., to craft the systems unit name).
The same can be done for boolean flags via a list like container_boolean_args for keys like --rm or --tty:
container_boolean_args:
- 'rm'
- 'tty'Open decisions
- Define which keys need to stay separate and used in different contexts
- Align on a naming for single arguments, boolean arguments, multi list arguments
- Align on how to do it (strict breaking change + removing the keys or "smooth" migration via deprecating
- Implementation: Align on several small pull requests or one big one (to keep the default branch working)
Additional notes
- This would indicate a breaking change to the module and a v1.x might be needed for a release
- It might be good to deprecate or directly remove the previous parameters that are replaced by the new capability. Removing directly would free up the code base directly.
- Changelog + Migration guide would be required