Skip to content
Snippets Groups Projects
Commit 5d689912 authored by Sylvester Joosten's avatar Sylvester Joosten
Browse files

Merge branch '55-add-simple-curl-deploy' into 'master'

Resolve "Add simple curl deploy"

Closes #55

See merge request !47
parents cb98f578 68c19949
Branches
No related tags found
1 merge request!47Resolve "Add simple curl deploy"
...@@ -143,6 +143,14 @@ RUN cd /opt/spack-environment \ ...@@ -143,6 +143,14 @@ RUN cd /opt/spack-environment \
>> /etc/profile.d/z10_spack_environment.sh \ >> /etc/profile.d/z10_spack_environment.sh \
&& echo "export BINARY_TAG=x86_64-linux-gcc9-opt" \ && echo "export BINARY_TAG=x86_64-linux-gcc9-opt" \
>> /etc/profile.d/z10_spack_environment.sh \ >> /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 . \ && cd /opt/spack-environment && spack env activate . \
&& echo -n "" \ && echo -n "" \
&& echo "Installing additional python packages" \ && echo "Installing additional python packages" \
......
...@@ -17,12 +17,10 @@ import os ...@@ -17,12 +17,10 @@ import os
import argparse import argparse
import re import re
import urllib.request 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. ## Gitlab group and project/program name.
DEFAULT_IMG='eic' DEFAULT_IMG='jug_xl'
DEFAULT_VERSION='2.9.2' DEFAULT_VERSION='3.0.0'
SHORTCUTS = ['eic-shell'] SHORTCUTS = ['eic-shell']
...@@ -53,6 +51,121 @@ class UnknownVersionError(Exception): ...@@ -53,6 +51,121 @@ class UnknownVersionError(Exception):
pass pass
class ContainerDownloadError(Exception): class ContainerDownloadError(Exception):
pass 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__": if __name__ == "__main__":
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
......
#!/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
#!/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
#!/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)
#!/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)
#!/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()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment