Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building Singularity image crashes with "not an empty directory" #552

Closed
andres-fr opened this issue Oct 26, 2023 · 1 comment
Closed

Building Singularity image crashes with "not an empty directory" #552

andres-fr opened this issue Oct 26, 2023 · 1 comment

Comments

@andres-fr
Copy link
Contributor

Description/Reproduction:

When following instructions given here to create Singularity/Apptainer image:

pip3 install spython
cd algorithmic-efficiency/docker
spython recipe Dockerfile &> Singularity.def
singularity build --fakeroot mlcommons.sif Singularity.def

The last command (i.e. building the Singularity image) crashes with the following error:

Setting up algorithmic_efficiency repo
+ branch=main
+ framework=both
+ git_url=https://github.com/mlcommons/algorithmic-efficiency.git
+ git clone https://github.com/mlcommons/algorithmic-efficiency.git
fatal: destination path 'algorithmic-efficiency' already exists and is not an empty directory.
+ cd /algorithmic-efficiency
+ git checkout main

Explanation:

Observe that the automatically generated .def includes the following line:

%files
scripts/startup.sh /algorithmic-efficiency/docker/scripts/startup.sh

When executed, this line copies the file from the first path (on host machine) into the second path (inside container). And for this, it recreates the full path, thus creating an algorithmic-efficiency directory.

Then, further down the line, git will crash when attempting to clone into that directory, since it already exists.

Fix:

Note how, if we were to git clone successfully, the startup.sh file would end up in the exact same place anyway. Further note that none of the in-between commands depends on that file in any way. Therefore, this issue should be fixed by either of the following:

  • Suppress the %files command by regex matching
  • Recursively delete algorithmic-efficiency prior to git clone
  • Tell the converter to not generate the %files command in the first place, in a programmatical way (cleanest)

To confirm this, manually suppressing the %files command indeed allowed compilation to continue. To pursue the cleanest fix, I created a Python script that mimics the spython command, with the only difference that it does not produce a %files comamnd. Using the created file allowed to continue the installation process without issues, so I'll propose a PR with the fix.

I'll copypaste the file in a commend for further reference.

@andres-fr
Copy link
Contributor Author

Alright, so PR #553 is the proposed fix.

For reference, the singularity_converter.py script (present in the PR) is:

"""
This script is a modification of the
``spython recipe Dockerfile &> Singularity.def`` command, implemented here:
github.com/singularityhub/singularity-cli/blob/master/spython/client/recipe.py
It converts the Docker recipy to Singularity, but suppressing any %files
command. Usage example:
python singularity_converter.py -i Dockerfile -o Singularity.def
"""


import argparse
#
import spython
from spython.main.parse.parsers import get_parser
from spython.main.parse.writers import get_writer

# globals
ENTRY_POINT = "/bin/bash"  # seems to be a good default
FORCE = False  # seems to be a good default
#
parser = argparse.ArgumentParser(description="Custom Singularity converter")
parser.add_argument('-i', '--input', type=str,
                    help="Docker input path", default="Dockerfile")
parser.add_argument('-o', '--output', type=str,
                    help="Singularity output path", default="Singularity.def")
args = parser.parse_args()
INPUT_DOCKERFILE_PATH = args.input
OUTPUT_SINGULARITY_PATH = args.output

# create Docker parser and Singularity writer
parser = get_parser("docker")
writer = get_writer("singularity")

# parse Dockerfile into Singularity and suppress %files commands
recipeParser = parser(INPUT_DOCKERFILE_PATH)
recipeWriter = writer(recipeParser.recipe)
key, = recipeParser.recipe.keys()
recipeWriter.recipe[key].files = []

# convert to string and save to output file
result = recipeWriter.convert(runscript=ENTRY_POINT, force=FORCE)
with open(OUTPUT_SINGULARITY_PATH, "w") as f:
    f.write(result)

priyakasimbeg added a commit that referenced this issue Dec 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant