Skip to content

Commit e3a497e

Browse files
authored
Merge pull request #81 from chrisburr/add-apptainer
Add apptainer to DIRACOS2
2 parents cb629b4 + ed9a0d9 commit e3a497e

3 files changed

Lines changed: 54 additions & 1 deletion

File tree

construct.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ specs:
9292
- requests >=2.9.1
9393
- rrdtool # [not (osx and arm64)]
9494
- singularity >=3.7 # [not osx]
95+
- apptainer # [not osx]
9596
- six
9697
- subprocess32
9798
- suds >=1.0

tests/test_cli.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ if ! singularity version; then
4848
echo "singularity version not working";
4949
rc=1;
5050
fi
51-
if ! singularity build --sandbox lolcow docker://godlovedc/lolcow; then
51+
if ! singularity build --force --sandbox lolcow docker://godlovedc/lolcow; then
5252
echo "singularity build not working";
5353
rc=1;
5454
fi
@@ -57,6 +57,20 @@ if ! (singularity --verbose --debug run -u lolcow || (singularity --verbose --de
5757
rc=1;
5858
fi
5959

60+
# For apptainer
61+
if ! apptainer version; then
62+
echo "apptainer version not working";
63+
rc=1;
64+
fi
65+
if ! apptainer build --force --sandbox lolcow docker://godlovedc/lolcow; then
66+
echo "apptainer build not working";
67+
rc=1;
68+
fi
69+
if ! (apptainer --verbose --debug run -u lolcow || (apptainer --verbose --debug run -u lolcow 2>&1 | grep -E 'Failed to create user namespace: (Operation not permitted|Invalid argument)')); then
70+
echo "apptainer run not working";
71+
rc=1;
72+
fi
73+
6074
# For HTCondor
6175
if ! condor_submit -help; then
6276
echo "condor_submit -help not working";

tests/test_singularity.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from subprocess import run
2+
3+
import pytest
4+
5+
IMPLEMENTATIONS_TO_TRY = ["apptainer", "singularity"]
6+
7+
8+
@pytest.mark.parametrize("implementation", IMPLEMENTATIONS_TO_TRY)
9+
def test_oci(implementation):
10+
cmd = [implementation, "exec", "docker://centos:7"]
11+
cmd += ["bash", "-c", "echo Hello world $(( 1+1 ))!"]
12+
proc = run(cmd, capture_output=True, check=True, text=True)
13+
assert proc.stdout == "Hello world 2!\n"
14+
15+
16+
@pytest.mark.parametrize("implementation", IMPLEMENTATIONS_TO_TRY)
17+
def test_build_image(implementation, tmp_path):
18+
cmd = [implementation, "build", "--fix-perms", "--sandbox"]
19+
cmd += [tmp_path / "container", "docker://centos:7"]
20+
run(cmd, capture_output=True, check=True, text=True)
21+
assert (tmp_path / "container" / "bin").is_dir()
22+
assert (tmp_path / "container" / "bin" / "bash").is_file()
23+
24+
25+
@pytest.mark.parametrize("implementation", IMPLEMENTATIONS_TO_TRY)
26+
def test_singularity_ce(implementation, tmp_path):
27+
test_build_image(implementation, tmp_path)
28+
29+
(tmp_path / "work").mkdir()
30+
(tmp_path / "home").mkdir()
31+
(tmp_path / "cvmfs").mkdir()
32+
33+
cmd = [implementation, "exec", "--contain", "--ipc", "--pid", "--userns"]
34+
cmd += ["--workdir", tmp_path / "work", "--home", tmp_path / "home"]
35+
cmd += ["--bind", tmp_path / "cvmfs", tmp_path / "container"]
36+
cmd += ["bash", "-c", "echo Hello world $(( 1+1+1 ))!"]
37+
proc = run(cmd, capture_output=True, check=True, text=True)
38+
assert proc.stdout == "Hello world 3!\n"

0 commit comments

Comments
 (0)