0

I am a beginner with Singularity.

What I want to achieve in the long run: I have a programming project with a long lists of dependencies, and I want to be able to give the program to other people in my company without there being bugs caused by missing dependencies, or wrong versions of dependencies.
The idea was now to use Singularity in order to easily provide a working environment.

In order to test this, I wrote a Hello World application which I now want to run in a container. I have a folder HelloWorld/ which contains the source code for a C++ Qt project. Then I wrote the following recipe file:

project.recipe

Bootstrap: docker
From: ubuntu:18.04

%setup
    cp -R <some_folder>/HelloWorld ${SINGULARITY_ROOTFS}/HelloWorld

%post
    apt update
    apt-get install -y qt5-default
    apt install -y g++
    apt-get install -y build-essential

    cd HelloWorld
    qmake
    make
    echo "after build:"
    ls

%runscript
    echo "before execution:"
    ls HelloWorld/

    ./HelloWorld/HelloWorld

where the echos and directory listings are for my current debugging process.

I can sucessfully build an image file using sudo singularity build --writable project.img project.recipe. (My debugging output shows me that the executable was build successfully.)

The problem is now that if I try to run it using ./project.img, or singularity run project.img, it won't find the executable.
Using my debugging output, I found out that the lines in %runscript use the folders outside of the container.
Tutorials like https://sylabs.io/guides/3.1/user-guide/build_a_container.html made it seem to me as if my recipe was the way to go, but apparently it isn't?

My questions:

  1. Is there some way for me to access my executable? Am I calling it wrong?
  2. Is the way I do it the way it is supposed to be done? Or would one normally do something like getting the executable outside of the container and then use the container to call that outside file? Or is there a different best practice?
  3. If the executable is to be copied outside of the container after compilation, how do I do that? How do I access outside folders when I'm within %post?
  4. Is this the best work process for what I want to achieve? Later on, my idea is that the big project is copied likewise in the container, dependencies are either installed or copied, then the project is compiled and finally its source being deleted. I also considered using a repository, but I can't have the project being in an open repository, and I don't want to store any passwords.
Aziuth
  • 3,652
  • 3
  • 18
  • 36

1 Answers1

1
  1. Firstly, use %files, don't use %setup. %setup is run as root and can directly modify the host server. You can very easily and accidentally break things without realizing it. You can get the same effect this way:
%files
    some_folder/HelloWorld /HelloWorld
  1. You are calling it wrong. In your %setup (and hopefully now in your %files) steps, you are copying the data to /HelloWorld. In your %runscript your are calling ./HelloWorld/HelloWorld which is the equivalent of $PWD/HelloWorld/HelloWorld. Since singularity automatically mounts in $PWD (as well as $HOME and some other directories), you are not calling what you're trying to call.

  2. You don't copy the executable outside of the container, you just need to make sure what you're executing is where you think it is.

  3. There is no access to the host filesystem in %post, you should have everything you need copied in via %files first.

  4. That's a reasonable workflow. Having a local private repo for the code is probably a good idea for tracking your changes, but that's your call.

tsnowlan
  • 3,472
  • 10
  • 15
  • Ah, I just needed to remove the dot. Thank you. Kind of counter intuitive to me. As for the folder thing, I did this because I read that %files wouldn't work with folders, but I did as you said and it works - is that a somewhat new feature? – Aziuth Aug 26 '20 at 09:42
  • As for point 4., how would you do that without openly storing the password in the recipe? Or are we rather talking about a workflow outside of the container? – Aziuth Aug 26 '20 at 09:44