Skip to content
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

docker_swarm_service: Extend env and add env_files support #51762

Merged
merged 7 commits into from Feb 12, 2019

Conversation

hannseman
Copy link
Contributor

SUMMARY

This PR adds the possibility the specify env as a dict.

env:
  KEY1: VALUE1
  KEY2: VALUE2

It also adds a new option called env_files which accepts a list of paths to env-files.

env_files:
  - path/to/file.env
  - some/other/file.env

The order in this list matters where the last file will override variables already defined in previous files. It is useful for sharing env-files for different environments where a common file with defaults can be overridden by an environment specific file.

I chose to not map the behaviour of env_files to the docker-compose equivalent called env_file which accepts both a list and a string. Then we could not rely on the argument spec path type validation but would be required to implement our own validation that the specified files exist.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

docker_swarm_service

@ansibot
Copy link
Contributor

ansibot commented Feb 5, 2019

@ansibot ansibot added affects_2.8 This issue/PR affects Ansible v2.8 cloud core_review In order to be merged, this PR must follow the core review workflow. docker feature This issue/PR relates to a feature request. module This issue/PR relates to a module. needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. needs_triage Needs a first human triage before being processed. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. support:community This issue/PR relates to code supported by the Ansible community. support:core This issue/PR relates to code supported by the Ansible Engineering Team. test This PR relates to tests. labels Feb 5, 2019
@ansibot
Copy link
Contributor

ansibot commented Feb 5, 2019

The test ansible-test sanity --test pylint [explain] failed with 1 error:

test/units/modules/cloud/docker/test_docker_swarm_service.py:70:31: ansible-format-automatic-specification Format string contains automatic field numbering specification

click here for bot help

@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed core_review In order to be merged, this PR must follow the core review workflow. needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. labels Feb 5, 2019
@felixfontein
Copy link
Contributor

felixfontein commented Feb 5, 2019

TwoThree quick comments:

  • type='path' in argument_spec does not check that the file exists, it only treats the argument like a path and does some basic tilde and variable expansion;
  • type='list' also accepts strings and splits them by comma, and accepts ints and floats, so you need to emulate that behavior, too (see here for details; it might make sense to actually call that method of AnsibleModule so you don't have to reimplement all details);
  • I think we should deprecate the non-dict form for env. Any opinions on this, in particular also from @dariko and @jwitko?

@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. and removed needs_triage Needs a first human triage before being processed. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Feb 5, 2019
@hannseman
Copy link
Contributor Author

hannseman commented Feb 5, 2019

type='path' in argument_spec does not check that the file exists, it only treats the argument like a path and does some basic tilde and variable expansion;

Ah yes, I somehow mixed that up.

Unfortunately the AnsibleModule-instance is not available in DockerService where validation / modification of arguments normally are handled. Do you think we should pass it to the DockerService class or create a new instance with an empty argument_spec (if that is possible?) or copy the details to our implementation?

@felixfontein
Copy link
Contributor

You can always access it via client.module, if client is the AnsibleDockerClient instance.

@hannseman
Copy link
Contributor Author

hannseman commented Feb 5, 2019

The DockerService is initialised like this:

new_service = DockerService.from_ansible_params(
    module.params,
    current_service,
    image_digest
)

Since only params is passed to DockerService.from_ansible_params, neither module or client is available. If module where to be passed instead of module.params it would then be required to be passed to the function get_docker_environment.

I guess that don't really need the int / float handling made in _check_type_list since that would generate an invalid environment anyway. If you agree then we could just add value.split(",") to get_docker_environment if the value is a string and then handle it as a list.

Edit: I made a commit which should make it a bit clearer.

@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. core_review In order to be merged, this PR must follow the core review workflow. and removed core_review In order to be merged, this PR must follow the core review workflow. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Feb 7, 2019
lib/ansible/modules/cloud/docker/docker_swarm_service.py Outdated Show resolved Hide resolved
@@ -769,7 +825,7 @@ def compare(self, os):
force_update = False
if self.endpoint_mode is not None and self.endpoint_mode != os.endpoint_mode:
differences.add('endpoint_mode', parameter=self.endpoint_mode, active=os.endpoint_mode)
if self.env != os.env:
if self.env is not None and self.env != os.env:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.env will never be None, it will always be a dict

Copy link
Contributor Author

@hannseman hannseman Feb 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm can it not be None from ansible parameters?

If no environment is parsed into env_list in get_docker_environment it will default to None:
https://github.com/hannseman/ansible/blob/68a2543f0bd0d2d44ef16b2575c43760e52aebd5/lib/ansible/modules/cloud/docker/docker_swarm_service.py#L600

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry, I apparently completely missed the or None. Yes, you are totally right!

@ansibot ansibot added needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed community_review In order to be merged, this PR must follow the community review workflow. labels Feb 10, 2019
@hannseman hannseman force-pushed the docker_swarm_service-env-options branch from 2c347ee to e3e5446 Compare February 11, 2019 00:18
@ansibot ansibot removed the needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html label Feb 11, 2019
@ansibot ansibot added community_review In order to be merged, this PR must follow the community review workflow. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Feb 11, 2019
@felixfontein
Copy link
Contributor

LGTM

@jwitko
Copy link
Contributor

jwitko commented Feb 11, 2019

shipit

@felixfontein
Copy link
Contributor

shipit

@felixfontein
Copy link
Contributor

bot_status

@ansibot ansibot added shipit This PR is ready to be merged by Core and removed community_review In order to be merged, this PR must follow the community review workflow. labels Feb 11, 2019
@ansibot
Copy link
Contributor

ansibot commented Feb 11, 2019

Components

changelogs/fragments/51762-docker_swarm_service-extend-env-and-add-env-file.yml
support: community
maintainers:

lib/ansible/modules/cloud/docker/docker_swarm_service.py
support: community
maintainers: DBendit WojciechowskiPiotr akshay196 danihodovic dariko felixfontein jwitko kassiansun tbouvet

test/integration/targets/docker_swarm_service/files/env-file-1
support: community
maintainers: DBendit WojciechowskiPiotr akshay196 danihodovic dariko felixfontein jwitko kassiansun tbouvet

test/integration/targets/docker_swarm_service/files/env-file-2
support: community
maintainers: DBendit WojciechowskiPiotr akshay196 danihodovic dariko felixfontein jwitko kassiansun tbouvet

test/integration/targets/docker_swarm_service/tasks/tests/options.yml
support: community
maintainers: DBendit WojciechowskiPiotr akshay196 danihodovic dariko felixfontein jwitko kassiansun tbouvet

test/units/modules/cloud/docker/test_docker_swarm_service.py
support: community
maintainers: DBendit WojciechowskiPiotr akshay196 danihodovic dariko felixfontein jwitko kassiansun tbouvet

Metadata

waiting_on: maintainer
changes_requested_by: null
needs_info: False
needs_revision: False
needs_rebase: False
merge_commits: []
too many files or commits: False
mergeable_state: clean
shippable_status: success
maintainer_shipits (module maintainers): 1
community_shipits (namespace maintainers): 0
ansible_shipits (core team members): 1
shipit_actors (maintainers or core team members): felixfontein jwitko
shipit_actors_other: []
automerge: automerge !module file(s) test failed

click here for bot help

@gundalow gundalow merged commit 70d8f02 into ansible:devel Feb 12, 2019
@gundalow
Copy link
Contributor

@hannseman Thank you for the PR
@felixfontein @jwitko Thank you for the reviews

Merged into devel for release in Ansible 2.8

@felixfontein
Copy link
Contributor

Thanks everyone! :)

@hannseman hannseman deleted the docker_swarm_service-env-options branch March 11, 2019 19:24
@ansible ansible locked and limited conversation to collaborators Jul 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.8 This issue/PR affects Ansible v2.8 cloud docker feature This issue/PR relates to a feature request. module This issue/PR relates to a module. shipit This PR is ready to be merged by Core support:community This issue/PR relates to code supported by the Ansible community. test This PR relates to tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants