From c7b70a3c671a484b8091ba4ad66060d583107443 Mon Sep 17 00:00:00 2001 From: Elie CHARRA Date: Fri, 8 Dec 2017 11:10:31 +0100 Subject: [PATCH 1/3] Add docker default global labels --- defaults/main.yml | 1 + templates/default.service.j2 | 1 + tests/goss-systemd.yaml | 1 + tests/units/nginx.yml | 2 ++ 4 files changed, 5 insertions(+) diff --git a/defaults/main.yml b/defaults/main.yml index 79d7b3d..523b847 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -3,4 +3,5 @@ default_volumes: - /etc/localtime:/etc/localtime:ro container_data_home: '/home/cloud/containers' default_docker_options: '' +default_docker_labels: [] default_network_name: default_network diff --git a/templates/default.service.j2 b/templates/default.service.j2 index a393ba4..3ab7332 100644 --- a/templates/default.service.j2 +++ b/templates/default.service.j2 @@ -57,6 +57,7 @@ ExecStart=/usr/bin/docker run {{ default_docker_options }} {%- endfor %} {%- endif %} {% if unit.labels is defined %}{% for label in unit.labels %}--label {{ label }} {% endfor %}{% endif %} + {% for label in default_docker_labels %}--label {{ label }} {% endfor %} {%- if unit.links is not defined %} {% set network = unit.network|default(default_network_name) %} --network={{ network }} diff --git a/tests/goss-systemd.yaml b/tests/goss-systemd.yaml index 95e0b97..442a3e6 100644 --- a/tests/goss-systemd.yaml +++ b/tests/goss-systemd.yaml @@ -30,6 +30,7 @@ file: contains: # Check file content for these patterns - "--add-host test:8.8.8.8" - "--volume /etc/localtime:/etc/localtime:ro" + - "--label fooLabel=barLabel" # Cover https://github.com/kibatic/docker-systemd/issues/3 /lib/systemd/system/nginx-host.service: exists: true diff --git a/tests/units/nginx.yml b/tests/units/nginx.yml index 5615479..9c5e1f2 100644 --- a/tests/units/nginx.yml +++ b/tests/units/nginx.yml @@ -20,3 +20,5 @@ systemd_units: network: host default_docker_options: '--add-host test:8.8.8.8' +default_docker_labels: + - fooLabel=barLabel From f4444acf8251f1f02c7ec0a45da37aa913157111 Mon Sep 17 00:00:00 2001 From: Elie CHARRA Date: Fri, 8 Dec 2017 11:17:39 +0100 Subject: [PATCH 2/3] Update tests --- tests/goss.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/goss.yaml b/tests/goss.yaml index bcafc40..552f4b4 100644 --- a/tests/goss.yaml +++ b/tests/goss.yaml @@ -17,5 +17,6 @@ command: # optional attributes stdout: - "\"test_label\": \"foo1234\"" + - "\"fooLabel\": \"barLabel\"" stderr: [] timeout: 10000 # in milliseconds From 860ddae87267ab8a486ca5f4d4ff4e1df2b3d859 Mon Sep 17 00:00:00 2001 From: Elie CHARRA Date: Fri, 8 Dec 2017 11:27:49 +0100 Subject: [PATCH 3/3] Update readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index baadc8a..61edbf3 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,8 @@ default_volumes: container_data_home: '/home/cloud/containers' # Default options passed to docker run default_docker_options: '' +# Default labels set on each container +default_docker_labels: [] # Default network name default_network_name: default_network ```