How to use the hpccm.common.container_type function in hpccm

To help you get started, we’ve selected a few hpccm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NVIDIA / hpc-container-maker / test / helpers.py View on Github external
def wrapper(*args, **kwargs):
        hpccm.config.g_ctype = container_type.SINGULARITY
        hpccm.config.g_singularity_version = StrictVersion('3.2')
        return function(*args, **kwargs)
github NVIDIA / hpc-container-maker / hpccm / templates / downloader.py View on Github external
branch=self.branch, commit=self.commit, path=wd,
                recursive=recursive, repository=self.repository))

            # Set directory where to find source
            self.src_directory = posixpath.join(wd, posixpath.splitext(
                posixpath.basename(self.repository))[0])

            # Add annotations
            if callable(annotate):
                self.add_annotation('repository', self.repository)
                if self.branch:
                    self.add_annotation('branch', self.branch)
                if self.commit:
                    self.add_annotation('commit', self.commit)

        if hpccm.config.g_ctype == container_type.DOCKER:
            return ' && \\\n    '.join(commands)
        elif hpccm.config.g_ctype == container_type.SINGULARITY:
            return '\n    '.join(commands)
        elif hpccm.config.g_ctype == container_type.BASH:
            return '\n'.join(commands)
        else:
            raise RuntimeError('Unknown container type')
github NVIDIA / hpc-container-maker / hpccm / primitives / workdir.py View on Github external
def __str__(self):
        """String representation of the primitive"""
        if self.directory:
            if hpccm.config.g_ctype == container_type.DOCKER:
                return 'WORKDIR {}'.format(self.directory)
            elif hpccm.config.g_ctype == container_type.SINGULARITY:
                s = shell(commands=['mkdir -p {}'.format(self.directory),
                                    'cd {}'.format(self.directory)])
                return str(s)
            elif hpccm.config.g_ctype == container_type.BASH:
                logging.warning('workdir primitive does not map into bash')
                return ''
            else:
                raise RuntimeError('Unknown container type')
        else:
            logging.error('No directory specified')
            return ''
github NVIDIA / hpc-container-maker / hpccm / primitives / raw.py View on Github external
def __str__(self):
        """String representation of the primitive"""
        if hpccm.config.g_ctype == container_type.DOCKER:
            return str(self.__docker)
        elif hpccm.config.g_ctype == container_type.SINGULARITY:
            return str(self.__singularity)
        elif hpccm.config.g_ctype == container_type.BASH:
            return ''
        else:
            raise RuntimeError('Unknown container type')
github NVIDIA / hpc-container-maker / hpccm / primitives / user.py View on Github external
def __str__(self):
        """String representation of the primitive"""
        if self.user:
            if hpccm.config.g_ctype == container_type.DOCKER:
                return 'USER {}'.format(self.user)
            elif hpccm.config.g_ctype == container_type.SINGULARITY:
                return ''
            elif hpccm.config.g_ctype == container_type.BASH:
                return ''
            else:
                raise RuntimeError('Unknown container type')
        else:
            logging.error('No user specified')
            return ''
github NVIDIA / hpc-container-maker / hpccm / primitives / comment.py View on Github external
def __str__(self):
        """String representation of the primitive"""
        if self.__string:
            # Comments are universal (so far...)
            if (self._app and
                hpccm.config.g_ctype == container_type.SINGULARITY):
                return '%apphelp {0}\n{1}'.format(self._app,
                                                  self.__string)

            if self.__reformat:
                # Wrap comments
                return textwrap.fill(self.__string, initial_indent='# ',
                                     subsequent_indent='# ', width=70)
            else:
                # Just prepend but otherwise apply no formatting
                return re.sub('^', '# ', self.__string, flags=re.MULTILINE)
        else:
            return ''
github NVIDIA / hpc-container-maker / hpccm / templates / downloader.py View on Github external
# Set directory where to find source
            self.src_directory = posixpath.join(wd, posixpath.splitext(
                posixpath.basename(self.repository))[0])

            # Add annotations
            if callable(annotate):
                self.add_annotation('repository', self.repository)
                if self.branch:
                    self.add_annotation('branch', self.branch)
                if self.commit:
                    self.add_annotation('commit', self.commit)

        if hpccm.config.g_ctype == container_type.DOCKER:
            return ' && \\\n    '.join(commands)
        elif hpccm.config.g_ctype == container_type.SINGULARITY:
            return '\n    '.join(commands)
        elif hpccm.config.g_ctype == container_type.BASH:
            return '\n'.join(commands)
        else:
            raise RuntimeError('Unknown container type')
github NVIDIA / hpc-container-maker / hpccm / config.py View on Github external
def set_container_format(ctype):
  """Set the container format

  # Arguments

  ctype (string): 'docker' to specify the Dockerfile format, or
  'singularity' to specify the Singularity definition file format

  # Raises

  RuntimeError: invalid container type argument
  """

  this = sys.modules[__name__]
  if ctype == 'docker':
    this.g_ctype = container_type.DOCKER
  elif ctype == 'singularity':
    this.g_ctype = container_type.SINGULARITY
  else:
    raise RuntimeError('Unrecognized container format: {}'.format(ctype))
github NVIDIA / hpc-container-maker / hpccm / primitives / label.py View on Github external
def __str__(self):
        """String representation of the primitive"""

        if self.__metadata:
            if hpccm.config.g_ctype == container_type.DOCKER:
                if self._app:
                    logging.warning('The Singularity specific %app.. syntax '
                                    'was requested. Docker does not have an '
                                    'equivalent: using regular LABEL!')

                # Format:
                # LABEL K1=V1 \
                #     K2=V2 \
                #     K3=V3
                keyvals = []
                for key, val in sorted(self.__metadata.items()):
                    keyvals.append('{0}={1}'.format(key, val))

                l = ['LABEL {}'.format(keyvals[0])]
                l.extend(['    {}'.format(x) for x in keyvals[1:]])
                return ' \\\n'.join(l)
github NVIDIA / hpc-container-maker / hpccm / Stage.py View on Github external
Stage0 += ofed()
        Stage0 += openmpi()
        ...
        Stage1 += baseimage(image='nvidia/cuda:9.0-base')
        Stage1 += Stage0.runtime(exclude=['boost'])
        ```

        """

        # If the name of the stage is not explicitly specified, use
        # the name of the Stage if available, otherwise 0 (Docker's
        # default)
        if not _from and self.name:
            _from = self.name
        elif not _from:
            if hpccm.config.g_ctype == container_type.SINGULARITY:
                logging.warning('Multi-stage Singularity containers require a named first stage')
            _from = '0'

        instructions = []
        for layer in self.__layers:
            runtime = getattr(layer, 'runtime', None)
            if callable(runtime) and layer.__class__.__name__ not in exclude:
                inst = layer.runtime(_from=_from)
                if inst:
                    instructions.append(inst)

        return self.__separator.join(instructions)