Skip to content

Commit

Permalink
Report when attempting to copy files to a temporary directory when us…
Browse files Browse the repository at this point in the history
…ing Singularity (NVIDIA#353)
  • Loading branch information
samcmill authored and gonzalobg committed May 11, 2021
1 parent 0c6cf35 commit 6b08afb
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 5 deletions.
2 changes: 1 addition & 1 deletion hpccm/building_blocks/apt_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def __init__(self, **kwargs):
self.__download = kwargs.get('download', False)
self.__download_directory = kwargs.get(
'download_directory',
posixpath.join(hpccm.config.g_wd, '/var/tmp/apt_get_download'))
posixpath.join(hpccm.config.g_wd, 'apt_get_download'))
self.__extra_opts = kwargs.get('extra_opts', [])
self.__extract = kwargs.get('extract', None)
self.__keys = kwargs.get('keys', [])
Expand Down
2 changes: 1 addition & 1 deletion hpccm/building_blocks/yum.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def __init__(self, **kwargs):
self.__download_args = kwargs.get('download_args', '')
self.__download_directory = kwargs.get(
'download_directory',
posixpath.join(hpccm.config.g_wd, '/var/tmp/yum_download'))
posixpath.join(hpccm.config.g_wd, 'yum_download'))
self.__epel = kwargs.get('epel', False)
self.__extra_opts = kwargs.get('extra_opts', [])
self.__extract = kwargs.get('extract', None)
Expand Down
12 changes: 12 additions & 0 deletions hpccm/primitives/copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,18 @@ def __str__(self):
return '\n'.join(instructions)

elif hpccm.config.g_ctype == container_type.SINGULARITY:
# If any of the files are being staged in /tmp or /var/tmp,
# issue a warning or error depending on the Singularity
# version.
# https://github.com/NVIDIA/hpc-container-maker/issues/345
if (not self.__from and
any(f['dest'].startswith(('/var/tmp', '/tmp')) for f in files)):
msg = 'Singularity 3.6 and later no longer allow a temporary directory to be used to stage files into the container image. Modify the recipe or, in many cases, use --working-directory or hpccm.config.set_working_directory() to specify another location.'
if hpccm.config.g_singularity_version >= StrictVersion('3.6'):
raise RuntimeError(msg)
else:
logging.warning(msg)

# Format:
# %files
# src1 dest
Expand Down
2 changes: 1 addition & 1 deletion hpccm/templates/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(self, **kwargs):
super(downloader, self).__init__(**kwargs)

def download_step(self, allow_unknown_filetype=True, recursive=False,
unpack=True, wd='/var/tmp'):
unpack=True, wd=hpccm.config.g_wd):
"""Get source code"""

if not self.repository and not self.package and not self.url:
Expand Down
9 changes: 9 additions & 0 deletions test/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ def wrapper(*args, **kwargs):

return wrapper

def singularity37(function):
"""Decorator to set the global singularity version"""
def wrapper(*args, **kwargs):
hpccm.config.g_ctype = container_type.SINGULARITY
hpccm.config.g_singularity_version = StrictVersion('3.7')
return function(*args, **kwargs)

return wrapper

def ubuntu(function):
"""Decorator to set the Linux distribution to Ubuntu 16.04"""
def wrapper(*args, **kwargs):
Expand Down
17 changes: 15 additions & 2 deletions test/test_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import logging # pylint: disable=unused-import
import unittest

from helpers import bash, docker, invalid_ctype, singularity, singularity26, singularity32
from helpers import bash, docker, invalid_ctype, singularity, singularity26, singularity32, singularity37

from hpccm.primitives.copy import copy

Expand Down Expand Up @@ -239,6 +239,19 @@ def test_chown_docker(self):

@singularity
def test_chown_singularity(self):
"""Docker --chown syntax"""
"""Singularity --chown syntax"""
c = copy(_chown='alice:alice', src='foo', dest='bar')
self.assertEqual(str(c), '%files\n foo bar')

@singularity37
def test_temp_staging(self):
"""Singularity staged files through tmp"""
c = copy(src='foo', dest='/var/tmp/foo')
with self.assertRaises(RuntimeError):
str(c)

@singularity37
def test_from_temp_staging(self):
"""Singularity files from previous stage in tmp"""
c = copy(_from='base', src='foo', dest='/var/tmp/foo')
self.assertEqual(str(c), '%files from base\n foo /var/tmp/foo')

0 comments on commit 6b08afb

Please sign in to comment.