fix: fix tmpfs_size and tmpfs_mode not being set (#580)

* fix: fix tmpfs_size and tmpfs_mode not being set

* fix: wrong file

* fix: add changelog fragment

* fix: update changelog fragment to match formatting

Co-authored-by: Felix Fontein <felix@fontein.de>

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
Kristof Mattei 2023-02-10 05:05:09 -08:00 committed by GitHub
parent 54a3dc151d
commit d2f551fc5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 120 additions and 2 deletions

View File

@ -0,0 +1,2 @@
bugfixes:
- docker_container - fix ``tmfs_size`` and ``tmpfs_mode`` not being set (https://github.com/ansible-collections/community.docker/pull/580).

View File

@ -994,8 +994,8 @@ def _set_values_mounts(module, data, api_version, options, values):
tmpfs_opts['Mode'] = mount.get('tmpfs_mode')
if mount.get('tmpfs_size'):
tmpfs_opts['SizeBytes'] = mount.get('tmpfs_size')
if mount.get('tmpfs_opts'):
mount_res['TmpfsOptions'] = mount.get('tmpfs_opts')
if tmpfs_opts:
mount_res['TmpfsOptions'] = tmpfs_opts
mounts.append(mount_res)
data['HostConfig']['Mounts'] = mounts
if 'volumes' in values:

View File

@ -1165,6 +1165,17 @@ EXAMPLES = '''
# The "NONE" check needs to be specified
test: ["NONE"]
- name: Create a tmpfs with a size and mode
community.docker.docker_container:
name: tmpfs test
image: ubuntu:22.04
state: started
mounts:
- type: tmpfs
target: /cache
tmpfs_mode: "1700" # only readable to the owner
tmpfs_size: "16G"
- name: Start container with block device read limit
community.docker.docker_container:
name: test

View File

@ -161,6 +161,111 @@
- mounts_7 is changed
- mounts_8 is not changed
####################################################################
## tmpfs ###########################################################
####################################################################
- name: tmpfs
docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
mounts:
- target: /cache1
type: tmpfs
tmpfs_mode: "1777"
tmpfs_size: "1GB"
- target: /cache2
type: tmpfs
tmpfs_mode: "1777"
tmpfs_size: "1GB"
force_kill: true
register: tmpfs_1
- name: tmpfs (idempotency)
docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
mounts:
- target: /cache2
type: tmpfs
tmpfs_mode: "1777"
tmpfs_size: "1GB"
- target: /cache1
type: tmpfs
tmpfs_mode: "1777"
tmpfs_size: "1GB"
force_kill: true
register: tmpfs_2
- name: tmpfs (more mounts)
docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
mounts:
- target: /cache1
type: tmpfs
tmpfs_mode: "1777"
tmpfs_size: "1GB"
- target: /cache2
type: tmpfs
tmpfs_mode: "1777"
tmpfs_size: "1GB"
- target: /cache3
type: tmpfs
tmpfs_mode: "1777"
tmpfs_size: "1GB"
force_kill: true
register: tmpfs_3
- name: tmpfs (change mode)
docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
mounts:
- target: /cache1
type: tmpfs
tmpfs_mode: "1700"
tmpfs_size: "1GB"
force_kill: true
register: tmpfs_4
- name: tmpfs (change size)
docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
mounts:
- target: /cache1
type: tmpfs
tmpfs_mode: "1700"
tmpfs_size: "2GB"
force_kill: true
register: tmpfs_5
- name: cleanup
docker_container:
name: "{{ cname }}"
state: absent
force_kill: yes
diff: no
- assert:
that:
- tmpfs_1 is changed
- tmpfs_2 is not changed
- tmpfs_3 is changed
- tmpfs_4 is changed
- tmpfs_5 is changed
####################################################################
## mounts + volumes ################################################
####################################################################