diff --git a/docs/primitives.md b/docs/primitives.md index efc40c61..b2ac6bc1 100644 --- a/docs/primitives.md +++ b/docs/primitives.md @@ -118,6 +118,9 @@ __Parameters__ identifier. This also causes the Singularity block to named `%appfiles` rather than `%files` (Singularity specific). +- ___chmod__: Set the permissions of the file(s) in the container image +(Docker specific). + - ___chown__: Set the ownership of the file(s) in the container image (Docker specific). diff --git a/hpccm/primitives/copy.py b/hpccm/primitives/copy.py index 3101cfef..10046fb7 100644 --- a/hpccm/primitives/copy.py +++ b/hpccm/primitives/copy.py @@ -39,6 +39,9 @@ class copy(object): identifier. This also causes the Singularity block to named `%appfiles` rather than `%files` (Singularity specific). + _chmod: Set the permissions of the file(s) in the container image + (Docker specific). + _chown: Set the ownership of the file(s) in the container image (Docker specific). @@ -88,6 +91,7 @@ def __init__(self, **kwargs): #super(copy, self).__init__() self._app = kwargs.get('_app', '') # Singularity specific + self.__chmod = kwargs.get('_chmod', '') # Docker specific self.__chown = kwargs.get('_chown', '') # Docker specific self.__dest = kwargs.get('dest', '') self.__files = kwargs.get('files', {}) @@ -138,6 +142,9 @@ def __str__(self): # COPY src3 dest3 base_inst = 'COPY ' + if self.__chmod: + base_inst = base_inst + '--chmod={} '.format(self.__chmod) + if self.__chown: base_inst = base_inst + '--chown={} '.format(self.__chown) diff --git a/test/test_copy.py b/test/test_copy.py index 73bb99b7..91aae145 100644 --- a/test/test_copy.py +++ b/test/test_copy.py @@ -231,6 +231,18 @@ def test_merge_mixed_singularity(self): b /B foo bar''') + @docker + def test_chmod_docker(self): + """Docker --chmod syntax""" + c = copy(_chmod='0755', src='foo', dest='bar') + self.assertEqual(str(c), 'COPY --chmod=0755 foo bar') + + @singularity + def test_chmod_singularity(self): + """Singularity --chmod syntax""" + c = copy(_chmod='0755', src='foo', dest='bar') + self.assertEqual(str(c), '%files\n foo bar') + @docker def test_chown_docker(self): """Docker --chown syntax"""