Hey Vanessa,
first of - many thanks for your quick, detailed and elaborate reply!
Singularity is the first software project I encounter with such a quick response time ;-).
> %setup shouldn't be needed for much, as files are (as of recent versions) added to the container prior to post. If you need to make directories for the files that don't exist, you would want to add them in %setup:
Thanks for the explanation and example!
> The good news (if you want a service) is that Singularity Hub (2.0) that will be released after Singularity 2.4 is going to support this structure. The standard is to find (recursively) any file called "Singularity" and build if it's been updated.
This indeed is good news. However, for now, we will start off with an internal git repository and some build scaffolding in form of shell scripts.
There are several reasons at the moment (e.g. pre-2.0 shub still requests non-acceptable permissions for the github account), but that for sure is an option for the future!
>> Now I would like to:
>> - Be able to call "singularity bootstrap" from anywhere, i.e. not caring about the actual working directory of the "singularity" bootstrapping process.
>
> I'm not sure I totally follow here - Singularity needs minimally a definition file (Singularity) and path to an image -
> the build context is important. Docker is the same - when you build it looks for the Dockerfile and local context.
> What would make sense is to have some standard organization of the build directory, and then have a common bootstrap file (adding files from the same folder, finding the definition) sort of automatically.
> Another idea is to have a wrapper around singularity that keeps a record of build bases (directories) associated with recipe or uri names, and then when you call to bootstrap /build with the uri, it changes directories appropriately, etc.
Up to now, the context is not (yet) important for me, since I can do e.g.:
export TMPDIR=$(mktemp -d)
mount -t tmpfs -o size=80% none ${TMPDIR}
export SINGULARTIY_REPO_CHECKOUT=/singularity/singularity_build
singularity bootstrap ${TMPDIR} ${SINGULARTIY_REPO_CHECKOUT}/recipes/SL6/default.def
And there is no need at all to take care of what the current working directory is. The issue arises as soon as I want to include files from the host.
For docker (please correct me if I am wrong), the build context is enforced to be the place where the Dockerfile is placed, so again it does not matter where I call the actual "docker build" binary.
If singularity really uses the working directory where the binary is started as build context, I consider this a portability and reproducibility issue,
since a user always has to enter the directory where the singularity recipe is placed in to achieve reproducible behaviour on his / her machine.
Otherwise, it could happen that he/she accidentally includes files or directories from a totally different place.
Let's visualize with a security-relevant, but not unrealistic example. Let's assume my recipe contains:
%files
.ssh/id_rsa /home/user/.ssh/id_rsa
.ssh/id_rsa.pub /home/user/.ssh/id_rsa.pub
If the user checks out my repo and now executes, in his / her home:
singularity bootstrap someimage.img ~/my_git_repo_checkout/recipes/SL6/Singularity
the container will be built successfully, but the result would contain the ssh-keys of the building user(!) taken from the home directory instead of those which reside in
~/my_git_repo_checkout/recipes/SL6/.ssh/
No error would be thrown. If the user now pushes this build to a public registry, he / she has a huge problem and is not even aware of it
(and likely not even aware of it if he / she read the recipe beforehand!).
In my eyes, that's at least a portability / reproducibility issue, if not a security issue, since the executable working directory matters for the build result -
while for docker this is not the case as far as I know, it uses a fixed base (the one of the Dockerfile).
> Another idea is to have a wrapper around singularity that keeps a record of build bases (directories) associated with recipe or uri names, and then when you call to bootstrap /build with the uri, it changes directories appropriately, etc.
I already have such a wrapper (which for example can build .tar.gz containers using the intermediate tmpfs-ramdisk - really fast!), so I can implement that easily ;-).
> If you could better define what exactly isn't reasonable about relative paths from some base, I can offer suggestions.
I actually think relative paths are fine - but I'm not happy with the base ;-).
I would prefer the base to be similar to how it is handled in Docker (by default at least),
and / or to be able to specify it from outside e.g. via a command line parameter, which would allow for example:
singularity bootstrap --buildroot /my_cloned_repo/resource_set_1/ SL6_with_resource_set_1.img /my_cloned_repo/recipes/SL6.def
singularity bootstrap --buildroot /my_cloned_repo/resource_set_2/ SL6_with_resource_set_2.img /my_cloned_repo/recipes/SL6.def
This can be pretty useful if I have to build a series of containers which are all the same, but just have a different set of resources.
As it is now, everybody building a singularity container seems to have to change manually (or via wrapper) to the directory of the build recipe before bootstrapping to ensure things work out.
This is something I dislike, and it's not even documented (I think) that the build context is the working directory.
I actually looked at this project shortly before deciding for the shell-script-solution.
What we are doing here is to build containers for our HPC cluster, and we directly deploy them to CVMFS, to have them readily available on all worker nodes, and take advantage of the
superior caching mechanics of CVMFS (we put extracted images there, not image files).
So there is no push / pull infrastructure required, and our users have access to our local CVMFS repository (to "read" containers).
Of course, a registry has quite some more nice features, but for us the overhead (Webserver, database, worker etc.) was too large for the requirements at hand.
It might be very useful if also users should be able to modify container recipes, but right now only we admins are taking care to prepare that ;-).
So all in all, my suggestion would be to re-think the build context concept to follow the more safe and reproducible concept from Docker,
and at least document what the build context is (as Docker does).
As a bonus, the "--buildroot" parameter (or whatever name is preferred) would be a nice-to-have.
For now, however, I think I will solve my issue at hand by just extending the wrapper to explicitly enter the directory in which the build recipe is contained,
and (sym)link all common resources that should be used for all containers that should use them, so they will be found right next / in a directory below the build recipe.
Many thanks for the elaborate reply (and for making singularity the successful project it already is!) :-),
Oliver
> *> - relative to the working directory of the "singularity bootstrap" process? That would be very much against portability.
> *> - relative to the location of the build recipe? Then I could probably use "../../resources/profile/setupATLAS.sh /etc/profile.d/setupATLAS.sh" in my "%files" section.
>
> It's relative to where you are calling it. I don't think this breaks portability, if you think about the ways that people share containers and recipes. For containers, the work is done and the recipes are inside - this is what we care most about. For portability of the predecessor to the container (recipe, files) we use version control (eg Github) and we don't care about absolute paths. It's portable because someone else can download my repo, and build my container.
>
>>
>> Maybe it's even possible to pass it in, i.e. use something like
>> %files
>> ${resourcedir:-../../resources}/profile/setupATLAS.sh
>> inside the recipe, and use "${resourcedir}" from the bootstraping host's environment if it is set?
>
> I think it would be unlikely for most to have one researcher's special environment variable, but I could be wrong.
>
>
>> This is not really clear to me from the documentation, but maybe I just missed it ;-).
>
> If you could better define what exactly isn't reasonable about relative paths from some base, I can offer suggestions. If you are looking for a local image manager to make it easy to push your own containers (and find them later) check out Singularity Registry
https://singularityhub.github.io/sregistry/
>
>> All the best and many thanks for your help!
>> Oliver
>>
>> --
>> You received this message because you are subscribed to the Google Groups "singularity" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to
singularity...@lbl.gov <mailto:
singularity%2Bunsu...@lbl.gov>.
>
> --
> Vanessa Villamia Sochat
> Stanford University
>
> --
> You received this message because you are subscribed to the Google Groups "singularity" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
singularity...@lbl.gov <mailto:
singularity...@lbl.gov>.