def test_defaults_centos(self): """Default cmake building block""" c = cmake() self.assertEqual( str(c), r'''# CMake version 3.12.3 RUN yum install -y \ wget && \ rm -rf /var/cache/yum/* RUN mkdir -p /var/tmp && wget -q -nc --no-check-certificate -P /var/tmp https://cmake.org/files/v3.12/cmake-3.12.3-Linux-x86_64.sh && \ /bin/sh /var/tmp/cmake-3.12.3-Linux-x86_64.sh --prefix=/usr/local && \ rm -rf /var/tmp/cmake-3.12.3-Linux-x86_64.sh''')
def test_eula(self): """Accept EULA""" c = cmake(eula=True) self.assertEqual( str(c), r'''# CMake version 3.11.1 RUN apt-get update -y && \ apt-get install -y --no-install-recommends \ wget && \ rm -rf /var/lib/apt/lists/* RUN mkdir -p /var/tmp && wget -q -nc --no-check-certificate -P /var/tmp https://cmake.org/files/v3.11/cmake-3.11.1-Linux-x86_64.sh && \ /bin/sh /var/tmp/cmake-3.11.1-Linux-x86_64.sh --prefix=/usr/local --skip-license && \ rm -rf /var/tmp/cmake-3.11.1-Linux-x86_64.sh''')
def test_version(self): """Version option""" c = cmake(eula=True, version='3.10.3') self.assertEqual( str(c), r'''# CMake version 3.10.3 RUN apt-get update -y && \ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ wget && \ rm -rf /var/lib/apt/lists/* RUN mkdir -p /var/tmp && wget -q -nc --no-check-certificate -P /var/tmp https://cmake.org/files/v3.10/cmake-3.10.3-Linux-x86_64.sh && \ /bin/sh /var/tmp/cmake-3.10.3-Linux-x86_64.sh --prefix=/usr/local --skip-license && \ rm -rf /var/tmp/cmake-3.10.3-Linux-x86_64.sh''')
def test_defaults_ubuntu(self): """Default cmake building block""" c = cmake() self.assertEqual( str(c), r'''# CMake version 3.12.3 RUN apt-get update -y && \ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ wget && \ rm -rf /var/lib/apt/lists/* RUN mkdir -p /var/tmp && wget -q -nc --no-check-certificate -P /var/tmp https://cmake.org/files/v3.12/cmake-3.12.3-Linux-x86_64.sh && \ /bin/sh /var/tmp/cmake-3.12.3-Linux-x86_64.sh --prefix=/usr/local && \ rm -rf /var/tmp/cmake-3.12.3-Linux-x86_64.sh''')
def test_defaults_centos(self): """Default cmake building block""" c = cmake() self.assertEqual(str(c), r'''# CMake version 3.22.2 RUN yum install -y \ make \ wget && \ rm -rf /var/cache/yum/* RUN mkdir -p /var/tmp && wget -q -nc --no-check-certificate -P /var/tmp https://github.com/Kitware/CMake/releases/download/v3.22.2/cmake-3.22.2-linux-x86_64.sh && \ mkdir -p /usr/local && \ /bin/sh /var/tmp/cmake-3.22.2-linux-x86_64.sh --prefix=/usr/local && \ rm -rf /var/tmp/cmake-3.22.2-linux-x86_64.sh ENV PATH=/usr/local/bin:$PATH''')
def test_eula(self): """3.20 binary naming""" c = cmake(version='3.20.0') self.assertEqual(str(c), r'''# CMake version 3.20.0 RUN apt-get update -y && \ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ make \ wget && \ rm -rf /var/lib/apt/lists/* RUN mkdir -p /var/tmp && wget -q -nc --no-check-certificate -P /var/tmp https://github.com/Kitware/CMake/releases/download/v3.20.0/cmake-3.20.0-linux-x86_64.sh && \ mkdir -p /usr/local && \ /bin/sh /var/tmp/cmake-3.20.0-linux-x86_64.sh --prefix=/usr/local && \ rm -rf /var/tmp/cmake-3.20.0-linux-x86_64.sh ENV PATH=/usr/local/bin:$PATH''')
def test_defaults_ubuntu(self): """Cmake building block for old 32-bit versions""" c = cmake(eula=True, version='3.0.0') self.assertEqual(str(c), r'''# CMake version 3.0.0 RUN yum install -y \ glibc.i686 \ make \ wget && \ rm -rf /var/cache/yum/* RUN mkdir -p /var/tmp && wget -q -nc --no-check-certificate -P /var/tmp https://github.com/Kitware/CMake/releases/download/v3.0.0/cmake-3.0.0-Linux-i386.sh && \ mkdir -p /usr/local && \ /bin/sh /var/tmp/cmake-3.0.0-Linux-i386.sh --prefix=/usr/local --skip-license && \ rm -rf /var/tmp/cmake-3.0.0-Linux-i386.sh ENV PATH=/usr/local/bin:$PATH''')
def test_version(self): """Version option""" c = cmake(eula=True, version='3.10.3') self.assertEqual(str(c), r'''# CMake version 3.10.3 RUN apt-get update -y && \ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ make \ wget && \ rm -rf /var/lib/apt/lists/* RUN mkdir -p /var/tmp && wget -q -nc --no-check-certificate -P /var/tmp https://github.com/Kitware/CMake/releases/download/v3.10.3/cmake-3.10.3-Linux-x86_64.sh && \ mkdir -p /usr/local && \ /bin/sh /var/tmp/cmake-3.10.3-Linux-x86_64.sh --prefix=/usr/local --skip-license && \ rm -rf /var/tmp/cmake-3.10.3-Linux-x86_64.sh ENV PATH=/usr/local/bin:$PATH''')
def test_eula(self): """Accept EULA""" c = cmake(eula=True) self.assertEqual( str(c), r'''# CMake version 3.14.5 RUN apt-get update -y && \ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ make \ wget && \ rm -rf /var/lib/apt/lists/* RUN mkdir -p /var/tmp && wget -q -nc --no-check-certificate -P /var/tmp https://cmake.org/files/v3.14/cmake-3.14.5-Linux-x86_64.sh && \ mkdir -p /usr/local && \ /bin/sh /var/tmp/cmake-3.14.5-Linux-x86_64.sh --prefix=/usr/local --skip-license && \ rm -rf /var/tmp/cmake-3.14.5-Linux-x86_64.sh ENV PATH=/usr/local/bin:$PATH''')
def test_aarch64(self): """Source option""" c = cmake(eula=True, version='3.14.5') self.assertEqual( str(c), r'''# CMake version 3.14.5 RUN yum install -y \ make \ wget && \ rm -rf /var/cache/yum/* RUN mkdir -p /var/tmp && wget -q -nc --no-check-certificate -P /var/tmp https://cmake.org/files/v3.14/cmake-3.14.5.tar.gz && \ mkdir -p /var/tmp && tar -x -f /var/tmp/cmake-3.14.5.tar.gz -C /var/tmp -z && \ cd /var/tmp/cmake-3.14.5 && ./bootstrap --prefix=/usr/local --parallel=$(nproc) && \ make -j$(nproc) && \ make install && \ rm -rf /var/tmp/cmake-3.14.5.tar.gz /var/tmp/cmake-3.14.5''')
def test_defaults_ubuntu(self): """Default cmake building block""" c = cmake() self.assertEqual( str(c), r'''# CMake version 3.18.3 RUN apt-get update -y && \ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ make \ wget && \ rm -rf /var/lib/apt/lists/* RUN mkdir -p /var/tmp && wget -q -nc --no-check-certificate -P /var/tmp https://github.com/Kitware/CMake/releases/download/v3.18.3/cmake-3.18.3-Linux-x86_64.sh && \ mkdir -p /usr/local && \ /bin/sh /var/tmp/cmake-3.18.3-Linux-x86_64.sh --prefix=/usr/local && \ rm -rf /var/tmp/cmake-3.18.3-Linux-x86_64.sh ENV PATH=/usr/local/bin:$PATH''')
def test_defaults_ubuntu(self): """Cmake building block for old 32-bit versions""" c = cmake(eula=True, version='3.0.0') self.assertEqual(str(c), r'''# CMake version 3.0.0 RUN apt-get update -y && \ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ libc6-i386 \ make \ wget && \ rm -rf /var/lib/apt/lists/* RUN mkdir -p /var/tmp && wget -q -nc --no-check-certificate -P /var/tmp https://github.com/Kitware/CMake/releases/download/v3.0.0/cmake-3.0.0-Linux-i386.sh && \ mkdir -p /usr/local && \ /bin/sh /var/tmp/cmake-3.0.0-Linux-i386.sh --prefix=/usr/local --skip-license && \ rm -rf /var/tmp/cmake-3.0.0-Linux-i386.sh ENV PATH=/usr/local/bin:$PATH''')
def test_aarch64(self): """Source option""" c = cmake(eula=True, version='3.14.5') self.assertEqual(str(c), r'''# CMake version 3.14.5 RUN yum install -y \ make \ openssl-devel \ wget && \ rm -rf /var/cache/yum/* RUN mkdir -p /var/tmp && wget -q -nc --no-check-certificate -P /var/tmp https://github.com/Kitware/CMake/releases/download/v3.14.5/cmake-3.14.5.tar.gz && \ mkdir -p /var/tmp && tar -x -f /var/tmp/cmake-3.14.5.tar.gz -C /var/tmp -z && \ cd /var/tmp/cmake-3.14.5 && ./bootstrap --prefix=/usr/local --parallel=$(nproc) && \ make -j$(nproc) && \ make install && \ rm -rf /var/tmp/cmake-3.14.5.tar.gz /var/tmp/cmake-3.14.5 ENV PATH=/usr/local/bin:$PATH''')
def main(): ############################################################################ # setup basics ############################################################################ hpccm.config.set_container_format('singularity') hpccm.config.set_singularity_version('3.3') stage0 = hpccm.Stage() stage0 += baseimage(image='ubuntu:bionic') stage0 += packages(ospackages=[ 'git', 'g++', 'wget', 'pkg-config', 'less', 'uuid-dev', 'gdb', 'locales', 'gpg-agent', 'gnupg2', 'locales-all', 'unzip' ]) # set language to en_US.UTF-8 to avoid some problems with the cling output system stage0 += shell( commands=['locale-gen en_US.UTF-8', 'update-locale LANG=en_US.UTF-8']) ############################################################################ # install clang/llvm ############################################################################ stage0 += llvm(version='9', extra_repository=True) ############################################################################ # install ninja build system ############################################################################ stage0 += shell(commands=[ 'cd /opt', 'wget --no-check-certificate ' + 'https://github.com/ninja-build/ninja/releases/download/v1.9.0/ninja-linux.zip', 'unzip ninja-linux.zip', 'mv ninja /usr/local/bin/', 'rm ninja-linux.zip', 'cd -' ]) ############################################################################ # install cmake ############################################################################ stage0 += cmake(eula=True, version='3.16.1') ############################################################################ # write recipe.def ############################################################################ with open('recipe.def', 'w') as filehandle: filehandle.write(stage0.__str__())
def get_stage(container): # generate baseimage hpccm.config.set_container_format(container) # version >3.2 is necessary for multi-stage build if container == 'singularity': hpccm.config.set_singularity_version('3.3') Stage0 = hpccm.Stage() Stage0 += baseimage(image='ubuntu:bionic') # copy project from outside in the container if container == 'singularity': Stage0 += copy(src='../hello_world_tool', dest='/opt/') else: # docker: cannot copy files from outsite the build context # so, we need to move the build context one level up Stage0 += copy(src='./hello_world_tool', dest='/opt/hello_world_tool') # install compiler tools Stage0 += cmake(eula=True, version='3.14.5') Stage0 += packages(ospackages=['g++', 'make', 'wget', 'build-essential']) # build and install project cmb = CMakeBuild() cm = [] cm.append(cmb.configure_step(build_directory='/opt/build_hello_world_tool', directory='/opt/hello_world_tool/')) cm.append(cmb.build_step(target='install')) Stage0 += shell(commands=cm) Stage0 += shell(commands=build_openssl(name='openssl-1.1.1c', build_dir='/opt/openssl_build')) # script that runs when # - singularity uses the run parameter or the image runs directly # - docker uses the run parameter without arguments Stage0 += runscript(commands=['hello_world_tool']) return Stage0
def add_alpaka_dep_layer(stage: hpccm.Stage, ubuntu_version: str, cuda_support: bool, extra_compiler: List[str], alpaka=False) -> bool: """Add all dependencies to an hpccm stage that are necessary to build and run Alpaka. :param stage: At least a baseimage :type stage: hpccm.Stage :param ubuntu_version: Ubuntu version number: '16.04' or '18.04' :type ubuntu_version: str :param cuda_support: Set True, if the Stage supports CUDA :type cuda_support: bool :param extra_compiler: List of compilers, which are installed additional to the system compiler. Supported are: gcc:[5-9], clang:[5.0-7.0, 8-9] :type extra_compiler: str :param alpaka: install alpaka in /usr/local :type alpaka: bool :returns: Returns True if function was successful :rtype: bool """ if ubuntu_version != '16.04' and ubuntu_version != '18.04': print('not supported Ubuntu version: ' + ubuntu_version, file=sys.stderr) print('supported are: 16.04, 18.04', file=sys.stderr) return False apt_package_list = [ 'gcc', 'g++', 'make', 'software-properties-common', 'wget', 'libc6-dev', 'libomp-dev', 'unzip', 'git' ] if ubuntu_version == '16.04': apt_package_list.append('gnupg-agent') if ubuntu_version == '18.04': apt_package_list.append('gpg-agent') stage += packages(ospackages=apt_package_list) stage += cmake(eula=True, version='3.16.0') # install extra compiler if extra_compiler is not None: for com in extra_compiler: if com.startswith('gcc'): stage += gnu(extra_repository=True, version=com[len('gcc:'):]) if com.startswith('clang'): add_clang(stage, ubuntu_version, version=com[len('clang:'):]) #install boost stage += shell( commands=['add-apt-repository -y ppa:mhier/libboost-latest']) stage += packages(ospackages=['boost1.67']) if cuda_support: stage += environment( variables={ 'LD_LIBRARY_PATH': '$LD_LIBRARY_PATH:/usr/local/cuda/lib64' }) # alpaka use a function direct from the cuda driver library # in the container, the cuda libraries are not at the default path stage += environment( variables={ 'LIBRARY_PATH': '$LIBRARY_PATH:/usr/local/cuda/lib64/stubs' }) stage += environment( variables={'CMAKE_PREFIX_PATH': '/usr/local/cuda/lib64/stubs/'}) if alpaka: git_alpaka = git() cmake_alpaka = CMakeBuild() alpaka_commands = [] alpaka_commands.append( git_alpaka.clone_step( repository='https://github.com/alpaka-group/alpaka.git', path='/opt')) alpaka_commands.append( cmake_alpaka.configure_step( build_directory='build', directory='/opt/alpaka', opts=['-Dalpaka_BUILD_EXAMPLES=OFF', '-DBUILD_TESTING=OFF'])) alpaka_commands.append(cmake_alpaka.build_step(target='install')) alpaka_commands.append('rm -rf /opt/alpaka') stage += shell(commands=alpaka_commands) return True
def get_stage(container): # generate baseimage hpccm.config.set_container_format(container) # version >3.2 is necessary for multi-stage build if container == 'singularity': hpccm.config.set_singularity_version('3.3') Stage0 = hpccm.Stage() # the stages need "names" so that they can reference each other Stage0 += baseimage(image='ubuntu:bionic', _as='Stage0') # copy project from outside in the container if container == 'singularity': Stage0 += copy(src='../hello_world_tool', dest='/opt/') else: # docker: cannot copy files from outsite the build context # so, we need to move the build context one level up Stage0 += copy(src='./hello_world_tool', dest='/opt/hello_world_tool') # install compiler tools Stage0 += cmake(eula=True, version='3.14.5') Stage0 += packages(ospackages=['g++', 'make', 'wget', 'build-essential']) # build and install project cmb = CMakeBuild(prefix="/opt/hello_install/") cm = [] cm.append( cmb.configure_step(build_directory='/opt/build_hello_world_tool', directory='/opt/hello_world_tool/', opts=['-DCMAKE_INSTALL_RPATH=/usr/local/lib/'])) cm.append(cmb.build_step(target='install')) Stage0 += shell(commands=cm) Stage0 += shell(commands=build_openssl(name='openssl-1.1.1c', build_dir='/opt/openssl_build')) # add release stage Stage1 = hpccm.Stage() Stage1 += baseimage(image='ubuntu:bionic', _as='Stage1') Stage1 += copy(_from='Stage0', src='/opt/hello_install/', dest='/usr/local/') Stage1 += copy(_from='Stage0', src='/opt/openssl_install/', dest='/usr/local/') # the commands merge the bin, lib ect. folders of hello_install and openssl_install # in the /usr/local folder if container == "singularity": Stage1 += shell(commands=[ 'cp -rl /usr/local/hello_install/* /usr/local/', 'cp -rl /usr/local/openssl_install/* /usr/local/', 'rm -r /usr/local/hello_install/', 'rm -r /usr/local/openssl_install/' ]) # script that runs when # - singularity uses the run parameter or the image runs directly # - docker uses the run parameter without arguments Stage1 += runscript(commands=['hello_world_tool']) return [Stage0, Stage1]