Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Docker COPY --chmod #451

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/primitives.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down
7 changes: 7 additions & 0 deletions hpccm/primitives/copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down Expand Up @@ -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', {})
Expand Down Expand Up @@ -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)

Expand Down
12 changes: 12 additions & 0 deletions test/test_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down