aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xkolla/common/config.py2
-rwxr-xr-xkolla/image/build.py15
-rw-r--r--kolla/tests/test_build.py7
-rw-r--r--releasenotes/notes/Add-work-dir-command-line-option-dd83aa934d5c9e3e.yaml6
4 files changed, 25 insertions, 5 deletions
diff --git a/kolla/common/config.py b/kolla/common/config.py
index 30f679880..c47c3c660 100755
--- a/kolla/common/config.py
+++ b/kolla/common/config.py
@@ -217,6 +217,8 @@ _CLI_OPTS = [
cfg.StrOpt('logs-dir', help='Path to logs directory'),
cfg.BoolOpt('pull', default=True,
help='Attempt to pull a newer version of the base image.'),
+ cfg.StrOpt('work-dir', help='Path to be used as working directory.'
+ 'By default, a temporary dir is created.'),
]
_BASE_OPTS = [
diff --git a/kolla/image/build.py b/kolla/image/build.py
index 133063513..a6736172e 100755
--- a/kolla/image/build.py
+++ b/kolla/image/build.py
@@ -633,10 +633,14 @@ class KollaWorker(object):
def setup_working_dir(self):
"""Creates a working directory for use while building"""
- ts = time.time()
- ts = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d_%H-%M-%S_')
- self.temp_dir = tempfile.mkdtemp(prefix='kolla-' + ts)
- self.working_dir = os.path.join(self.temp_dir, 'docker')
+ if self.conf.work_dir:
+ self.working_dir = os.path.join(self.conf.work_dir, 'docker')
+ else:
+ ts = time.time()
+ ts = datetime.datetime.fromtimestamp(ts).strftime(
+ '%Y-%m-%d_%H-%M-%S_')
+ self.temp_dir = tempfile.mkdtemp(prefix='kolla-' + ts)
+ self.working_dir = os.path.join(self.temp_dir, 'docker')
shutil.copytree(self.images_dir, self.working_dir)
self.copy_apt_files()
LOG.debug('Created working dir: %s', self.working_dir)
@@ -754,7 +758,8 @@ class KollaWorker(object):
def cleanup(self):
"""Remove temp files"""
- shutil.rmtree(self.temp_dir)
+ if not self.conf.work_dir:
+ shutil.rmtree(self.temp_dir)
def filter_images(self):
"""Filter which images to build"""
diff --git a/kolla/tests/test_build.py b/kolla/tests/test_build.py
index 1a1e019d5..7bcd2de7f 100644
--- a/kolla/tests/test_build.py
+++ b/kolla/tests/test_build.py
@@ -349,6 +349,13 @@ class KollaWorkerTest(base.TestCase):
results = kolla.summary()
self.assertEqual(None, results['failed'][0]['status'])
+ @mock.patch('shutil.copytree')
+ def test_work_dir(self, copytree_mock):
+ self.conf.set_override('work_dir', '/tmp/foo')
+ kolla = build.KollaWorker(self.conf)
+ kolla.setup_working_dir()
+ self.assertEqual('/tmp/foo/docker', kolla.working_dir)
+
class MainTest(base.TestCase):
diff --git a/releasenotes/notes/Add-work-dir-command-line-option-dd83aa934d5c9e3e.yaml b/releasenotes/notes/Add-work-dir-command-line-option-dd83aa934d5c9e3e.yaml
new file mode 100644
index 000000000..329fd4226
--- /dev/null
+++ b/releasenotes/notes/Add-work-dir-command-line-option-dd83aa934d5c9e3e.yaml
@@ -0,0 +1,6 @@
+---
+features:
+ - A new work-dir command-line option has been added to
+ the client, to allow the user to specify a directory
+ to be used as working dir, instead of the default
+ temp directory.