From e379a5b79ed87cd87feddbd7899385c719daa5c0 Mon Sep 17 00:00:00 2001 From: Juan Antonio Osorio Robles Date: Thu, 5 Oct 2017 09:55:54 +0300 Subject: [PATCH] Add log_tag option to container definition This adds the --log-opt tag= to the docker run command, which can be quite useful depending on your logging needs. In the TripleO case, we use journald as the default logging driver, and this will get reflected in the logs by adding the tag to the CONTAINER_TAG key in the log metadata. bp logging-stdout-rsyslog Change-Id: I3bfb1a5ce2d6a6f95519f5272348eae18d649712 --- README.rst | 3 +++ paunch/builder/compose1.py | 2 ++ paunch/tests/test_builder_compose1.py | 3 ++- releasenotes/notes/Add-log-tag-option-f63140a497abf370.yaml | 5 +++++ 4 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/Add-log-tag-option-f63140a497abf370.yaml diff --git a/README.rst b/README.rst index 2701e29..687db93 100644 --- a/README.rst +++ b/README.rst @@ -287,3 +287,6 @@ volumes: volumes_from: List of strings. Mount volumes from the specified container(s). + +log_tag: + String. Set the log tag for the specified container. diff --git a/paunch/builder/compose1.py b/paunch/builder/compose1.py index eedf45b..f328295 100644 --- a/paunch/builder/compose1.py +++ b/paunch/builder/compose1.py @@ -173,6 +173,8 @@ class ComposeV1Builder(object): for v in cconfig.get('volumes_from', []): if v: cmd.append('--volumes-from=%s' % v) + if 'log_tag' in cconfig: + cmd.append('--log-opt=tag=%s' % cconfig['log_tag']) cmd.append(cconfig.get('image', '')) cmd.extend(self.command_argument(cconfig.get('command'))) diff --git a/paunch/tests/test_builder_compose1.py b/paunch/tests/test_builder_compose1.py index 90b6443..a295507 100644 --- a/paunch/tests/test_builder_compose1.py +++ b/paunch/tests/test_builder_compose1.py @@ -324,6 +324,7 @@ three-12345678 three''', '', 0), 'retries': 3 }, 'env_file': '/tmp/foo.env', + 'log_tag': '{{.ImageName}}/{{.Name}}/{{.ID}}' } } builder = compose1.ComposeV1Builder('foo', config, None) @@ -337,7 +338,7 @@ three-12345678 three''', '', 0), '--health-cmd=/bin/true', '--health-interval=30s', '--health-timeout=10s', '--health-retries=3', '--privileged=true', '--restart=always', '--user=bar', - 'centos:7'], + '--log-opt=tag={{.ImageName}}/{{.Name}}/{{.ID}}', 'centos:7'], cmd ) diff --git a/releasenotes/notes/Add-log-tag-option-f63140a497abf370.yaml b/releasenotes/notes/Add-log-tag-option-f63140a497abf370.yaml new file mode 100644 index 0000000..d660d98 --- /dev/null +++ b/releasenotes/notes/Add-log-tag-option-f63140a497abf370.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + the log_tag option was added to the container definition. This will make + paunch add the --log-opt tag= option to the run command.