container: fix legacy docker_volumes compatibility, add missing arguments to argument specs

This commit is contained in:
uumas
2023-02-07 18:00:06 +02:00
parent 5a20226105
commit 5991385def
5 changed files with 47 additions and 22 deletions

View File

@@ -30,7 +30,7 @@ argument_specs:
choices:
- postgres
- mariadb
- mongodb
- mongo
- none
default: none
databse_passwords:
@@ -47,7 +47,7 @@ argument_specs:
default: []
docker_volume_type:
description: "Defines whether to use named volumes or bind mounts for volume definitions with name"
description: "Defines whether to use named volumes or bind mounts for mounts with name"
type: str
required: false
choices:
@@ -55,7 +55,13 @@ argument_specs:
- bind
default: named
docker_volumes:
description: "List of docker volumes to be mounted inside the container. Each element is a dict with path and exactly one of name, src, template or rclone."
description: "DEPRECATED List of docker volumes to mount inside the container. Use docker_mounts instead. DEPRECATED"
type: list
required: false
default: []
elements: str
docker_mounts:
description: "List of bind mounts or volumes to be mounted inside the container. Each element is a dict with path and exactly one of name, src or template"
type: list
required: false
default: []
@@ -77,10 +83,6 @@ argument_specs:
description: "Name of template without .j2 extension. Will be templated at /opt/<service>[/suffix]/mounts/<template> and mounted inside the container."
type: str
required: false
rclone:
description: "Name of the rclone volume to mount. Must be defined using the rclone_config variable."
type: str
required: false
reverse_proxy_type:
description: "Defines which kind of reverse proxy to configure for the container. Traefik support is experimental."
type: str
@@ -100,9 +102,18 @@ argument_specs:
required: false
docker_vhost_domains:
description: "docker_vhost_domains[docker_service] is a list which defines which domains should be proxied to the container. Required if reverse_proxy_type is not none"
docker_published_ports:
description: "A list of published ports in docker format (<host listen address>:<host port>:<container port>)"
type: list
required: false
default: []
docker_env:
description: "A dict of environment variables for the container"
type: dict
required: false
default: {}
docker_entrypoint:
description: "Docker entrypoint as list of command and arguments"
type: list
required: false
elements: str

View File

@@ -4,6 +4,7 @@
set_fact:
docker_volume_definition: []
container_published_ports: []
docker_volumes_new: []
final_docker_volumes: "{{ docker_volumes }}"
- name: Set docker service full name
@@ -11,16 +12,18 @@
docker_service_name: "{{ docker_service }}_{{ docker_service_suffix }}"
when: docker_service_suffix is defined
- name: Warn about docker_volumes legacy format
debug:
msg: "docker_volumes is deprecated. This support may be removed after december 2022. Use docker_mounts instead!"
when: docker_volumes | length > 0
- name: Convert docker_volumes from legacy format
when: docker_volumes | length > 0 and docker_volumes[0] is not mapping
block:
- name: Warn about docker_volumes legacy format
debug:
msg: "docker_volumes is set in a legacy, deprecated format. This support may be removed after december 2022."
- name: Add legacy docker volumes to docker_volumes_new using the new format
set_fact:
docker_volumes_new: "{{ docker_volumes_new | default([]) + [{'name': item.split(':')[0], 'path': item.split(':')[1]}] }}"
docker_volumes_new: "{{ docker_volumes_new | default([]) + [{'name': item.split(':')[0] | regex_replace('^' + docker_service_name + '_', ''), 'path': item.split(':')[1]}] }}"
when: "'/' not in item.split(':')[0]"
loop: "{{ docker_volumes }}"
- name: Add legacy docker src bind mounts to docker_volumes_new using the new format
@@ -31,3 +34,8 @@
- name: Set final_docker_volumes variable
set_fact:
final_docker_volumes: "{{ docker_volumes_new }}"
- name: Convert final_docker_volumes to docker_mounts
set_fact:
docker_mounts: "{{ final_docker_volumes }}"
when: docker_mounts | length == 0 and final_docker_volumes | length > 0

View File

@@ -73,3 +73,8 @@
networks: "{{ container_networks | default(omit) }}"
log_driver: local
register: container_out
- name: Reset docker_mounts if converted from docker_volumes
set_fact:
docker_mounts: []
when: final_docker_volumes | length > 0

View File

@@ -2,8 +2,8 @@
- name: Create directories and put files in them
when:
- docker_volumes | length > 0
- (docker_volume_type == 'bind') or (docker_volumes | selectattr('template', 'defined') | list | length > 0)
- docker_mounts | length > 0
- (docker_volume_type == 'bind' and docker_mounts | selectattr('name', 'defined') | list | length > 0) or (docker_mounts | selectattr('template', 'defined') | list | length > 0)
block:
- name: Create directory /opt/{{ docker_service + '/' + docker_service_suffix }}
file:
@@ -42,33 +42,33 @@
owner: "{{ mount_owner if (item.set_owner is not defined or item.set_owner) and mount_owner | length > 0 else omit }}"
group: "{{ mount_group if (item.set_group is not defined or item.set_group) and mount_group | length > 0 else omit }}"
when: item.name is defined
loop: "{{ docker_volumes }}"
loop: "{{ docker_mounts }}"
- name: Set docker_volume_definition for named binds
set_fact:
docker_volume_definition: "{{ docker_volume_definition + [{'source': docker_mounts_dir + '/' + item.name, 'target': item.path, 'type': 'bind'}] }}"
when: item.name is defined
loop: "{{ docker_volumes }}"
loop: "{{ docker_mounts }}"
- name: Template docker template mounts for {{ docker_service_name }}
template:
src: "{{ item.template }}.j2"
dest: "{{ docker_mounts_dir }}/{{ item.template }}"
when: item.template is defined
loop: "{{ docker_volumes }}"
loop: "{{ docker_mounts }}"
- name: Set docker_volume_definition for template mounts
set_fact:
docker_volume_definition: "{{ docker_volume_definition + [{'source': docker_mounts_dir + '/' + item.template, 'target': item.path, 'type': 'bind', 'read_only': true}] }}"
when: item.template is defined
loop: "{{ docker_volumes }}"
loop: "{{ docker_mounts }}"
- name: Set docker_volume_definition for named volumes
set_fact:
docker_volume_definition: "{{ docker_volume_definition + [{'source': docker_service_name + '_' + item.name, 'target': item.path, 'type': 'volume'}] }}"
when: docker_volume_type == 'named' and item.name is defined
loop: "{{ final_docker_volumes }}"
loop: "{{ docker_mounts }}"
- name: Set docker_volume_definition for src binds
set_fact:
docker_volume_definition: "{{ docker_volume_definition + [{'source': item.src, 'target': item.path, 'type': 'bind'}] }}"
when: item.src is defined
loop: "{{ final_docker_volumes }}"
loop: "{{ docker_mounts }}"

View File

@@ -7,7 +7,8 @@ docker_proxy_target_protocol: http
docker_additional_env: {}
docker_database: none
docker_volumes: []
docker_volumes: [] # DEPRECATED
docker_mounts: []
docker_networks: []
docker_env: {}