[2.8] docker_image: fix compatibility bugs (#57085)
* docker_image: fix default handling of old docker-build options nocache and rm (#56610) * Fix usage of nocache parameter. * Fix defaults. * Add changelog. (cherry picked from commit56e2d48612
) * docker_image: fix module failing when build option is used without specifying path (#56940) * Fix module failing when build option is used without specifying path. * Add changelog. (cherry picked from commit86928a5f74
) * Extend docker_image tests. (#57090) (cherry picked from commitc54d79bc13
)
This commit is contained in:
parent
6857fb2c39
commit
5c88199db3
4 changed files with 57 additions and 4 deletions
|
@ -0,0 +1,3 @@
|
|||
bugfixes:
|
||||
- "docker_image - if ``nocache`` set to ``yes`` but not ``build.nocache``, the module failed."
|
||||
- "docker_image - if ``build`` was not specified, the wrong default for ``build.rm`` is used."
|
2
changelogs/fragments/56940-docker_image-fail.yml
Normal file
2
changelogs/fragments/56940-docker_image-fail.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- "docker_image - module failed when ``source: build`` was set but ``build.path`` options not specified."
|
|
@ -453,11 +453,11 @@ class ImageManager(DockerBaseClass):
|
|||
self.load_path = parameters.get('load_path')
|
||||
self.name = parameters.get('name')
|
||||
self.network = build.get('network')
|
||||
self.nocache = build.get('nocache')
|
||||
self.nocache = build.get('nocache', False)
|
||||
self.build_path = build.get('path')
|
||||
self.pull = build.get('pull')
|
||||
self.repository = parameters.get('repository')
|
||||
self.rm = build.get('rm')
|
||||
self.rm = build.get('rm', True)
|
||||
self.state = parameters.get('state')
|
||||
self.tag = parameters.get('tag')
|
||||
self.http_timeout = build.get('http_timeout')
|
||||
|
@ -879,14 +879,14 @@ def main():
|
|||
if client.module.params[option] != default_value:
|
||||
if client.module.params['build'] is None:
|
||||
client.module.params['build'] = dict()
|
||||
if client.module.params['build'].get(build_option) != default_value:
|
||||
if client.module.params['build'].get(build_option, default_value) != default_value:
|
||||
client.fail('Cannot specify both %s and build.%s!' % (option, build_option))
|
||||
client.module.params['build'][build_option] = client.module.params[option]
|
||||
client.module.warn('Please specify build.%s instead of %s. The %s option '
|
||||
'has been renamed and will be removed in Ansible 2.12.' % (build_option, option, option))
|
||||
if client.module.params['source'] == 'build':
|
||||
if (not client.module.params['build'] or not client.module.params['build'].get('path')):
|
||||
client.module.fail('If "source" is set to "build", the "build.path" option must be specified.')
|
||||
client.fail('If "source" is set to "build", the "build.path" option must be specified.')
|
||||
if client.module.params['build'].get('pull') is None:
|
||||
client.module.warn("The default for build.pull is currently 'yes', but will be changed to 'no' in Ansible 2.12. "
|
||||
"Please set build.pull explicitly to the value you need.")
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
---
|
||||
- name: Registering image name
|
||||
set_fact:
|
||||
iname: "{{ name_prefix ~ '-old-options' }}"
|
||||
|
||||
- name: Registering image name
|
||||
set_fact:
|
||||
inames: "{{ inames }} + [iname]"
|
||||
|
||||
####################################################################
|
||||
## build ###########################################################
|
||||
####################################################################
|
||||
|
||||
- name: build with old-style options
|
||||
docker_image:
|
||||
name: "{{ iname }}"
|
||||
path: "{{ role_path }}/files"
|
||||
dockerfile: Dockerfile
|
||||
http_timeout: 60
|
||||
nocache: yes
|
||||
pull: no
|
||||
rm: no
|
||||
buildargs:
|
||||
TEST1: val1
|
||||
TEST2: val2
|
||||
TEST3: "True"
|
||||
container_limits:
|
||||
memory: 5000000
|
||||
memswap: 7000000
|
||||
source: build
|
||||
register: build
|
||||
|
||||
- name: cleanup
|
||||
docker_image:
|
||||
name: "{{ iname }}"
|
||||
state: absent
|
||||
force_absent: yes
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- '"Please specify build.container_limits instead of container_limits. The container_limits option has been renamed and will be removed in Ansible 2.12." in build.warnings'
|
||||
- '"Please specify build.dockerfile instead of dockerfile. The dockerfile option has been renamed and will be removed in Ansible 2.12." in build.warnings'
|
||||
- '"Please specify build.http_timeout instead of http_timeout. The http_timeout option has been renamed and will be removed in Ansible 2.12." in build.warnings'
|
||||
- '"Please specify build.nocache instead of nocache. The nocache option has been renamed and will be removed in Ansible 2.12." in build.warnings'
|
||||
- '"Please specify build.path instead of path. The path option has been renamed and will be removed in Ansible 2.12." in build.warnings'
|
||||
- '"Please specify build.pull instead of pull. The pull option has been renamed and will be removed in Ansible 2.12." in build.warnings'
|
||||
- '"Please specify build.rm instead of rm. The rm option has been renamed and will be removed in Ansible 2.12." in build.warnings'
|
||||
- '"Please specify build.args instead of buildargs. The buildargs option has been renamed and will be removed in Ansible 2.12." in build.warnings'
|
Loading…
Reference in a new issue