summaryrefslogtreecommitdiff
path: root/share/spack/templates/container/singularity.def
blob: 7ba0a3ff1b0f0db30bf8a7d14b2563ad60b503f4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
Bootstrap: docker
From: {{ build.image }}:{{ build.tag }}
Stage: build

%post
  # Create the manifest file for the installation in /opt/spack-environment
  mkdir {{ paths.environment }} && cd {{ paths.environment }}
  cat << EOF > spack.yaml
{{ manifest }}
EOF

  # Install all the required software
  . /opt/spack/share/spack/setup-env.sh
  spack env activate .
  spack install
  spack gc -y
  spack env deactivate
  spack env activate --sh -d . >> {{ paths.environment }}/environment_modifications.sh
{% if strip %}

  # Strip the binaries to reduce the size of the image
  find -L {{ paths.view }}/* -type f -exec readlink -f '{}' \; | \
    xargs file -i | \
    grep 'charset=binary' | \
    grep 'x-executable\|x-archive\|x-sharedlib' | \
    awk -F: '{print $1}' | xargs strip -s
{% endif %}
{% if extra_instructions.build %}
{{ extra_instructions.build }}
{% endif %}


{% if apps %}
{% for application, help_text in apps.items() %}

%apprun {{ application }}
    exec /opt/view/bin/{{ application }} "$@"

%apphelp {{ application }}
    {{help_text }}
{% endfor %}
{% endif %}

Bootstrap: docker
From: {{ run.image }}
Stage: final

%files from build
  {{ paths.environment }} /opt
  {{ paths.store }} /opt
  {{ paths.view }} /opt
  {{ paths.environment }}/environment_modifications.sh {{ paths.environment }}/environment_modifications.sh

%post
{% if os_packages.list %}
  # Update, install and cleanup of system packages
  {{ os_packages.update }}
  {{ os_packages.install }} {{ os_packages.list | join | replace('\n', ' ') }}
  {{ os_packages.clean }}
{% endif %}
  # Modify the environment without relying on sourcing shell specific files at startup
  cat {{ paths.environment }}/environment_modifications.sh >> $SINGULARITY_ENVIRONMENT
{% if extra_instructions.final %}
{{ extra_instructions.final }}
{% endif %}

{% if runscript %}
%runscript
{{ runscript }}
{% endif %}

{% if startscript %}
%startscript
{{ startscript }}
{% endif %}

{% if test %}
%test
{{ test }}
{% endif %}

{% if help %}
%help
{{ help }}
{% endif %}

{% if labels %}
%labels
{% for label, value in labels.items() %}
  {{ label }} {{ value }}
{% endfor %}
{% endif %}