Esempio n. 1
0
 def test_merge_docker(self):
     """merge primitives"""
     r = []
     r.append(runscript(commands=['a', 'b']))
     r.append(runscript(commands=['c']))
     merged = r[0].merge(r)
     self.assertEqual(str(merged), 'ENTRYPOINT ["a"]')
Esempio n. 2
0
 def test_merge_singularity(self):
     """merge primitives"""
     r = []
     r.append(runscript(commands=['a', 'b']))
     r.append(runscript(commands=['c']))
     merged = r[0].merge(r)
     self.assertEqual(str(merged), '%runscript\n    a\n    b\n    exec c')
    def test_allsections_singularity(self):
        """One of each SCI-f section type"""
        s = scif(name='foo')
        s += copy(src='file', dest='/tmp/file')
        s += comment('My app')
        s += environment(variables={'ONE': '1'})
        s += label(metadata={'A': 'B'})
        s += runscript(commands=['default_program'])
        s += shell(commands=['build_cmds'])
        s += shell(commands=['test_program'], _test=True)
        self.assertEqual(
            str(s), r'''%appenv foo
    export ONE=1
%appfiles foo
    file /tmp/file
%apphelp foo
My app
%appinstall foo
    for f in /.singularity.d/env/*; do . $f; done
    build_cmds
%applabels foo
    A B
%apprun foo
    exec default_program "$@"
%apptest foo
    test_program''')
Esempio n. 4
0
    def __scif_recipe(self):
        """Generate the SCI-F recipe instructions, merging primitives of the
        same type because SCI-F does not support duplicate
        sections."""

        recipe = []

        if self.__appenv:
            appenv = self.__appenv[0].merge(self.__appenv, _app=self.__name)
            recipe.append(appenv)

        if self.__appfiles:
            appfiles = self.__appfiles[0].merge(self.__appfiles,
                                                _app=self.__name)
            recipe.append(appfiles)

        if self.__apphelp:
            apphelp = self.__apphelp[0].merge(self.__apphelp, _app=self.__name)
            recipe.append(apphelp)

        if self.__appinstall:
            _appenv = False
            if hpccm.config.g_ctype == container_type.SINGULARITY:
                # If the container type is Singularity, load the
                # general container environment
                _appenv = True
            appinstall = self.__appinstall[0].merge(self.__appinstall,
                                                    _app=self.__name,
                                                    _appenv=_appenv)
            recipe.append(appinstall)

        if self.__applabels:
            applabels = self.__applabels[0].merge(self.__applabels,
                                                  _app=self.__name)
            recipe.append(applabels)

        if self.__apprun:
            apprun = self.__apprun[0].merge(self.__apprun, _app=self.__name)
            recipe.append(apprun)
        else:
            # Shell one liner to run a command if specified,
            # otherwise start a shell
            recipe.append(
                runscript(commands=[
                    'eval "if [[ $# -eq 0 ]]; then exec /bin/bash; else exec $@; fi"'
                ],
                          _args=False,
                          _app=self.__name,
                          _exec=False))

        if self.__apptest:
            apptest = self.__apptest[0].merge(self.__apptest,
                                              _app=self.__name,
                                              _test=True)
            recipe.append(apptest)

        return recipe
Esempio n. 5
0
    def __instructions(self):
        self += comment('OpenGeoSys build from repo {0}, branch {1}'.format(
            self.__repo, self.__branch))
        self += packages(ospackages=self.__ospackages)
        self += shell(
            commands=self.__commands,
            _arguments='--mount=type=bind,target=/scif/apps/ogs/src,rw')
        self += runscript(commands=['ogs'])

        if self.__environment_variables:
            self += environment(variables=self.__environment_variables)
        if self.__labels:
            self += label(metadata=self.__labels)
    def test_allsections_docker(self):
        """One of each SCI-f section type"""
        # See comment in the test_defaults_docker test case
        scif_file = tempfile.NamedTemporaryFile(delete=False, suffix='.scif')
        s = scif(name='foo', file=scif_file.name)
        s += copy(src='file', dest='/tmp/file')
        s += comment('My app')
        s += environment(variables={'ONE': '1'})
        s += label(metadata={'A': 'B'})
        s += runscript(commands=['default_program'])
        s += shell(commands=['build_cmds'])
        s += shell(commands=['test_program'], _test=True)

        str(s)  # Force writing the SCI-F recipe file

        # slurp file content
        with open(scif_file.name) as f:
            content = f.read()
        try:
            os.unlink(scif_file.name)
        except WindowsError:
            # WindowsError: [Error 32] The process cannot access the file
            # because it is being used by another process
            pass

        self.assertEqual(
            content, r'''%appenv foo
    export ONE=1

%appfiles foo
    file /tmp/file

%apphelp foo
My app

%appinstall foo
    build_cmds

%applabels foo
    A B

%apprun foo
    exec default_program "$@"

%apptest foo
    test_program''')
Esempio n. 7
0
def build(container_format='singularity',
          os_release='ubuntu',
          os_version='20.04',
          conda_packages=['conda', 'numpy', 'scipy', 'pandas'],
          python_version='3.9.1',
          channels=['anaconda', 'defaults', 'conda-forge'],
          anaconda_version='4.9.2'):
    config.set_container_format(container_format)

    image = f'{os_release}:{os_version}'

    stage0 = Stage(name='stage0')
    stage0 += baseimage(image=image, _bootstrap='docker')
    stage0 += environment(variables={
        'LC_ALL': 'en_AU.UTF-8',
        'LANGUAGE': 'en_AU.UTF-8',
    })
    stage0 += label(metadata={
        'maintainer': 'Luhan Cheng',
        'email': '*****@*****.**'
    })
    stage0 += shell(commands=[
        'rm /usr/bin/sh', 'ln -s /usr/bin/bash /usr/bin/sh', '/usr/bin/bash'
    ])
    stage0 += packages(apt=[
        'wget', 'git', 'software-properties-common', 'build-essential',
        'locales'
    ])
    stage0 += shell(commands=['locale-gen en_AU.UTF-8'])
    stage0 += conda(eula=True,
                    packages=[f'python={python_version}'] + conda_packages,
                    channels=channels,
                    version=anaconda_version)
    stage0 += environment(variables=from_prefix('/usr/local/anaconda'))

    stage0 += runscript(commands=[
        'source /usr/local/anaconda/etc/profile.d/conda.sh',
        '/usr/local/anaconda/bin/python3 $*'
    ])

    return stage0
 def test_multiple_docker(self):
     """List of commands specified"""
     cmds = ['a', 'b', 'c']
     s = runscript(commands=cmds)
     self.assertEqual(str(s), 'ENTRYPOINT ["a"]')
Esempio n. 9
0
 def test_multiple_noexec_singularity(self):
     """exec option"""
     cmds = ['a', 'b', 'c']
     s = runscript(commands=cmds, _exec=False)
     self.assertEqual(str(s), '%runscript\n    a\n    b\n    c')
Esempio n. 10
0
 def test_empty(self):
     """No commands specified"""
     s = runscript()
     self.assertEqual(str(s), '')
Esempio n. 11
0
 def test_apprun_multiple_singularity(self):
     """List of commands specified"""
     cmds = ['a', 'b', 'c']
     s = runscript(commands=cmds, _app='foo')
     self.assertEqual(str(s), '%apprun foo\n    a\n    b\n    exec c')
Esempio n. 12
0
 def test_apprun_docker(self):
     """apprun not implemented in Docker"""
     cmds = ['a', 'b', 'c']
     s = runscript(commands=cmds, _app='foo')
     self.assertEqual(str(s), 'ENTRYPOINT ["a"]')
Esempio n. 13
0
 def test_multiple_singularity(self):
     """List of commands specified"""
     cmds = ['a arga', 'b argb', 'c']
     s = runscript(commands=cmds)
     self.assertEqual(str(s),
                      '%runscript\n    a arga\n    b argb\n    exec c')
Esempio n. 14
0
 def test_bash(self):
     """Single command specified"""
     cmd = ['z']
     s = runscript(commands=cmd)
     self.assertEqual(str(s), '')
Esempio n. 15
0
 def test_single_singularity(self):
     """Single command specified"""
     cmd = ['z']
     s = runscript(commands=cmd)
     self.assertEqual(str(s), '%runscript\n    exec z')
Esempio n. 16
0
 def test_single_docker(self):
     """Single command specified"""
     cmd = ['z arg1 arg2']
     s = runscript(commands=cmd)
     self.assertEqual(str(s), 'ENTRYPOINT ["z", "arg1", "arg2"]')
Esempio n. 17
0
 def test_invalid_ctype(self):
     """Invalid container type specified"""
     s = runscript(commands=['a'])
     with self.assertRaises(RuntimeError):
         str(s)