From 0108ad789a087a9581c5cc4fbb3547f7aff45662 Mon Sep 17 00:00:00 2001 From: Alex Schultz Date: Fri, 13 Dec 2019 08:21:46 -0700 Subject: [PATCH] builder: include environment when running an exec Some container execs have an environment, let's make sure they are included when running exec. NOTE: This is for Rocky and below as docker was the only supported method in these versions. Additionally in Rocky and below, the environment was a list and not a dictionary so we only support a list version for the environment. Closes-Bug: #1855932 Change-Id: Ic2e2c2d50f5883f7db28768ba215e74bcbf9fd8b (cherry picked from commit b5be45067ac1e7d3b08458e2943e8de046aeee7b) --- paunch/builder/compose1.py | 4 ++++ paunch/tests/test_builder_compose1.py | 2 ++ 2 files changed, 6 insertions(+) diff --git a/paunch/builder/compose1.py b/paunch/builder/compose1.py index c3dceaf..450ef4d 100644 --- a/paunch/builder/compose1.py +++ b/paunch/builder/compose1.py @@ -281,6 +281,10 @@ class ComposeV1Builder(object): cmd.append('--privileged=%s' % str(cconfig['privileged']).lower()) if 'user' in cconfig: cmd.append('--user=%s' % cconfig['user']) + # TODO(sbaker): support the dict layout for this property + for v in cconfig.get('environment', []): + if v: + cmd.append('--env=%s' % v) command = self.command_argument(cconfig.get('command')) # for exec, the first argument is the container name, # make sure the correct one is used diff --git a/paunch/tests/test_builder_compose1.py b/paunch/tests/test_builder_compose1.py index 9858173..f57765c 100644 --- a/paunch/tests/test_builder_compose1.py +++ b/paunch/tests/test_builder_compose1.py @@ -563,6 +563,7 @@ three-12345678 three''', '', 0), 'one': { 'command': 'ls -l /foo', 'privileged': True, + 'environment': ['FOO=BAR'], 'user': 'bar' } } @@ -574,6 +575,7 @@ three-12345678 three''', '', 0), self.assertEqual( ['docker', 'exec', '--privileged=true', '--user=bar', + '--env=FOO=BAR', 'one-12345678', '-l', '/foo'], cmd )