diff --git a/containers/jug/Dockerfile.dev b/containers/jug/Dockerfile.dev index 900c9dc4a8d87cce8d3b888e5f1941008977167e..1f8968c98772f9032a4f781551b22109ddee8476 100644 --- a/containers/jug/Dockerfile.dev +++ b/containers/jug/Dockerfile.dev @@ -143,6 +143,14 @@ RUN cd /opt/spack-environment \ >> /etc/profile.d/z10_spack_environment.sh \ && echo "export BINARY_TAG=x86_64-linux-gcc9-opt" \ >> /etc/profile.d/z10_spack_environment.sh \ + && echo "if [ ! -z \${ATHENA_PREFIX} ]; then" \ + >> /etc/profile.d/z10_spack_environment.sh \ + && echo "export LD_LIBRARY_PATH=\$ATHENA_PREFIX/lib:\$LD_LIBRARY_PATH" \ + >> /etc/profile.d/z10_spack_environment.sh \ + && echo "export PATH=\$ATHENA_PREFIX/bin:\$PATH" \ + >> /etc/profile.d/z10_spack_environment.sh \ + && echo "fi" \ + >> /etc/profile.d/z10_spack_environment.sh \ && cd /opt/spack-environment && spack env activate . \ && echo -n "" \ && echo "Installing additional python packages" \ diff --git a/install.py b/install.py index 671dce2282dfdb62a5bffcb17aa16f828b5bb3e5..89ba149daafc54fb588c8e941d4193866c5e9dda 100755 --- a/install.py +++ b/install.py @@ -17,12 +17,10 @@ import os import argparse import re import urllib.request -from install import make_launcher, make_modulefile -from install.util import smart_mkdir, project_version, InvalidArgumentError ## Gitlab group and project/program name. -DEFAULT_IMG='eic' -DEFAULT_VERSION='2.9.2' +DEFAULT_IMG='jug_xl' +DEFAULT_VERSION='3.0.0' SHORTCUTS = ['eic-shell'] @@ -53,6 +51,121 @@ class UnknownVersionError(Exception): pass class ContainerDownloadError(Exception): pass +class InvalidArgumentError(Exception): + pass + +def smart_mkdir(dir): + '''functions as mkdir -p, with a write-check. + + Raises an exception if the directory is not writeable. + ''' + if not os.path.exists(dir): + try: + os.makedirs(dir) + except Exception as e: + print('ERROR: unable to create directory', dir) + raise e + if not os.access(dir, os.W_OK): + print('ERROR: We do not have the write privileges to', dir) + raise InvalidArgumentError() + +## generic launcher bash script to launch the application +_LAUNCHER='''#!/usr/bin/env bash + +## Boilerplate to make pipes work +piped_args= +if [ -p /dev/stdin ]; then + # If we want to read the input line by line + while IFS= read line; do + if [ -z "$piped_args" ]; then + piped_args="${{line}}" + else + piped_args="${{piped_args}}\n${{line}}" + fi + done +fi + +## Fire off the application wrapper +if [ ${{piped_args}} ] ; then + echo -e ${{piped_args}} | singularity exec {bind} {container} {exe} $@ +else + singularity exec {bind} {container} {exe} $@ +fi +''' + +def _write_script(path, content): + print(' - creating', path) + with open(path, 'w') as file: + file.write(content) + os.system('chmod +x {}'.format(path)) + +def make_launcher(app, container, bindir, + bind='', exe=None): + '''Configure and install a launcher. + + Generic launcher script to launch applications in this container. + + The launcher script calls the desired executable from the singularity image. + As the new images have the environment properly setup, we can accomplish this + without using any wrapper scripts. + + Arguments: + - app: our application + - container: absolute path to container + - bindir: absolute launcher install path + Optional: + - bind: singularity bind directives + - exe: executable to be associated with app. + Default is app. + - env: environment directives to be added to the wrapper. + Multiline string. Default is nothing + ''' + if not exe: + exe = app + + ## paths + launcher_path = '{}/{}'.format(bindir, app) + + ## scripts --> use absolute path for wrapper path inside launcher + launcher = _LAUNCHER.format(container=container, + bind=bind, + exe=exe) + + ## write our scripts + _write_script(launcher_path, launcher) + +## Generic module file +_MODULEFILE='''#%Module1.0##################################################################### +## +## for {name} {version} +## +proc ModulesHelp {{ }} {{ + puts stderr "This module sets up the environment for the {name} container" +}} +module-whatis "{name} {version}" + +# For Tcl script use only +set version 4.1.4 + +prepend-path PATH {bindir} +''' + +def make_modulefile(project, version, moduledir, bindir): + '''Configure and install a modulefile for this project. + + Arguments: + - project: project name + - version: project version + - moduledir: root modulefile directory + - bindir: where executables for this project are located + ''' + + ## create our modulefile + content = _MODULEFILE.format(name=project, version=version, bindir=bindir) + fname = '{}/{}'.format(moduledir, version) + print(' - creating', fname) + with open(fname, 'w') as file: + file.write(content) if __name__ == "__main__": parser = argparse.ArgumentParser() diff --git a/install.sh b/install.sh new file mode 100755 index 0000000000000000000000000000000000000000..1cf72431114bd94c8673a18cf2ab06058b89614f --- /dev/null +++ b/install.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +CONTAINER=jug_xl +VERSION=nightly + +## Simple setup script that installs the container +## in your local environment under $PWD/local/lib +## and creates a simple top-level launcher script +## that launches the container for this working directory +## with the $ATHENA_PREFIX variable pointing +## to the $PWD/local directory + +## get the python installer and run the old-style install +#cp ../../current/eic_container/install.py . +wget https://eicweb.phy.anl.gov/containers/eic_container/-/raw/master/install.py +chmod +x install.py +./install.py -c $CONTAINER -v $VERSION $PWD/local +## Don't place eic-shell in local/bin as this may +## conflict with things we install inside the container +rm $PWD/local/bin/eic-shell +## Cleanup +rm -rf __pycache__ install.py + +## create a new top-level eic-shell launcher script +## that sets the ATHENA_PREFIX and then starts singularity +cat << EOF > eic-shell +#!/bin/bash +export ATHENA_PREFIX=$PWD/local +$PWD/local/lib/${CONTAINER}.sif.${VERSION} +EOF +chmod +x eic-shell diff --git a/install/__init__.py b/install/__init__.py deleted file mode 100644 index 7a9953f35778e4788ae78e8b86f4c238ddfdac6f..0000000000000000000000000000000000000000 --- a/install/__init__.py +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env python3 - -## eic_container: Argonne Universal EIC Container - -from install.util import smart_mkdir, project_version -from install.launcher import make_launcher -from install.modulefile import make_modulefile diff --git a/install/launcher.py b/install/launcher.py deleted file mode 100644 index 535ffcf6c59e6bb4d6396d42c0914a6ec4c110ed..0000000000000000000000000000000000000000 --- a/install/launcher.py +++ /dev/null @@ -1,75 +0,0 @@ -#!/usr/bin/env python3 - -''' -Generic launcher script to launch applications in this container. - -The launcher script calls the desired executable from the singularity image. -As the new images have the environment properly setup, we can accomplish this -without using any wrapper scripts. - -Authors: - - Whitney Armstrong <warmstrong@anl.gov> - - Sylvester Joosten <sjoosten@anl.gov> -''' - -import os - -## generic launcher bash script to launch the application -_LAUNCHER='''#!/usr/bin/env bash - -## Boilerplate to make pipes work -piped_args= -if [ -p /dev/stdin ]; then - # If we want to read the input line by line - while IFS= read line; do - if [ -z "$piped_args" ]; then - piped_args="${{line}}" - else - piped_args="${{piped_args}}\n${{line}}" - fi - done -fi - -## Fire off the application wrapper -if [ ${{piped_args}} ] ; then - echo -e ${{piped_args}} | singularity exec {bind} {container} {exe} $@ -else - singularity exec {bind} {container} {exe} $@ -fi -''' - -def _write_script(path, content): - print(' - creating', path) - with open(path, 'w') as file: - file.write(content) - os.system('chmod +x {}'.format(path)) - -def make_launcher(app, container, bindir, - bind='', exe=None): - '''Configure and install a launcher. - - Arguments: - - app: our application - - container: absolute path to container - - bindir: absolute launcher install path - Optional: - - bind: singularity bind directives - - exe: executable to be associated with app. - Default is app. - - env: environment directives to be added to the wrapper. - Multiline string. Default is nothing - ''' - if not exe: - exe = app - - - ## paths - launcher_path = '{}/{}'.format(bindir, app) - - ## scripts --> use absolute path for wrapper path inside launcher - launcher = _LAUNCHER.format(container=container, - bind=bind, - exe=exe) - - ## write our scripts - _write_script(launcher_path, launcher) diff --git a/install/modulefile.py b/install/modulefile.py deleted file mode 100644 index 0c222bf9639f22db60326e9961d55f4ace475405..0000000000000000000000000000000000000000 --- a/install/modulefile.py +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env python3 - -## eic_container: Argonne Universal EIC Container - -''' -Install modulefile for this container. - -Authors: - - Whitney Armstrong <warmstrong@anl.gov> - - Sylvester Joosten <sjoosten@anl.gov> -''' - -import os - -## Generic module file -_MODULEFILE='''#%Module1.0##################################################################### -## -## for {name} {version} -## -proc ModulesHelp {{ }} {{ - puts stderr "This module sets up the environment for the {name} container" -}} -module-whatis "{name} {version}" - -# For Tcl script use only -set version 4.1.4 - -prepend-path PATH {bindir} -''' - -def make_modulefile(project, version, moduledir, bindir): - '''Configure and install a modulefile for this project. - - Arguments: - - project: project name - - version: project version - - moduledir: root modulefile directory - - bindir: where executables for this project are located - ''' - - ## create our modulefile - content = _MODULEFILE.format(name=project, version=version, bindir=bindir) - fname = '{}/{}'.format(moduledir, version) - print(' - creating', fname) - with open(fname, 'w') as file: - file.write(content) diff --git a/install/util.py b/install/util.py deleted file mode 100644 index e3b2a86b5e86b459ef048b643fe2d3f0d442e798..0000000000000000000000000000000000000000 --- a/install/util.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python3 - -## eic_container: Argonne Universal EIC Container - -''' -Utility functions for this container - -Authors: - - Whitney Armstrong <warmstrong@anl.gov> - - Sylvester Joosten <sjoosten@anl.gov> -''' - -import os - -class InvalidArgumentError(Exception): - pass - -def smart_mkdir(dir): - '''functions as mkdir -p, with a write-check. - - Raises an exception if the directory is not writeable. - ''' - if not os.path.exists(dir): - try: - os.makedirs(dir) - except Exception as e: - print('ERROR: unable to create directory', dir) - raise e - if not os.access(dir, os.W_OK): - print('ERROR: We do not have the write privileges to', dir) - raise InvalidArgumentError() - -def project_version(): - '''Return the project version based on the current git branch/tag.''' - ## Shell command to get the current project version - version_cmd = 'cat VERSION' - ## Strip will remove the leading \n character - return os.popen(version_cmd).read().strip()