Skip to content

Commit

Permalink
Add support for Spack packages to Singularity build
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Di Tommaso <[email protected]>
  • Loading branch information
pditommaso committed Sep 6, 2023
1 parent 5f3168b commit dfb5fc3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ repositories {

dependencies {
implementation 'io.seqera:wave-api:0.5.0'
implementation 'io.seqera:wave-utils:0.7.2'
implementation 'io.seqera:wave-utils:0.7.3'
implementation 'info.picocli:picocli:4.6.1'
implementation 'com.squareup.moshi:moshi:1.14.0'
implementation 'com.squareup.moshi:moshi-adapters:1.14.0'
Expand Down
2 changes: 2 additions & 0 deletions app/conf/resource-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
"pattern":"\\Qtemplates/conda/singularityfile-conda-packages.txt\\E"
}, {
"pattern":"\\Qtemplates/spack/dockerfile-spack-file.txt\\E"
}, {
"pattern":"\\Qtemplates/spack/singularityfile-spack-file.txt\\E"
}, {
"pattern":"java.base:\\Qjdk/internal/icu/impl/data/icudt72b/nfc.nrm\\E"
}, {
Expand Down
7 changes: 5 additions & 2 deletions app/src/main/java/io/seqera/wavelit/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import io.seqera.wave.api.SubmitContainerTokenResponse;
import io.seqera.wave.config.CondaOpts;
import io.seqera.wave.config.SpackOpts;
import io.seqera.wave.util.DockerHelper;
import io.seqera.wave.util.DockerIgnoreFilter;
import io.seqera.wave.util.Packer;
import io.seqera.wavelit.exception.BadClientResponseException;
Expand All @@ -57,6 +56,8 @@
import static io.seqera.wave.util.DockerHelper.condaFileToSingularityFile;
import static io.seqera.wave.util.DockerHelper.condaPackagesToDockerFile;
import static io.seqera.wave.util.DockerHelper.condaPackagesToSingularityFile;
import static io.seqera.wave.util.DockerHelper.spackFileToDockerFile;
import static io.seqera.wave.util.DockerHelper.spackFileToSingularityFile;
import static io.seqera.wave.util.DockerHelper.spackPackagesToSpackFile;
import static io.seqera.wavelit.util.Checkers.isEmpty;
import static io.seqera.wavelit.util.Checkers.isEnvVar;
Expand Down Expand Up @@ -530,7 +531,9 @@ protected String containerFileBase64() {

if( !isEmpty(spackFile) || spackPackages!=null ) {
final SpackOpts opts = new SpackOpts() .withCommands(spackRunCommands);
final String result = DockerHelper.spackFileToDockerFile(opts);
final String result = singularity
? spackFileToSingularityFile(opts)
: spackFileToDockerFile(opts);
return encodeStringBase64(result);
}

Expand Down
29 changes: 27 additions & 2 deletions app/src/test/groovy/io/seqera/wavelit/AppSpackOptsTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ class AppSpackOptsTest extends Specification {
and:
def req = app.createRequest()
then:
new String(req.containerFile.decodeBase64()).startsWith("# Runner image")
def spec = new String(req.containerFile.decodeBase64()).tokenize('\n')
spec[0] == '# Runner image'
spec[1] == 'FROM {{spack_runner_image}}'
spec[2] == 'COPY --from=builder /opt/spack-env /opt/spack-env'

and:
new String(req.spackFile.decodeBase64()) == '''\
Expand All @@ -146,7 +149,6 @@ class AppSpackOptsTest extends Specification {
"--spack-package", "bar",
"--spack-run-command", "RUN one",
"--spack-run-command", "RUN two",

]

when:
Expand All @@ -166,4 +168,27 @@ class AppSpackOptsTest extends Specification {
'''.stripIndent(true)
}

def 'should create container file from spack package with singularity' () {
given:
def app = new App()
String[] args = ["--spack-package", "foo", "--singularity"]

when:
new CommandLine(app).parseArgs(args)
and:
def req = app.createRequest()
then:
def spec = new String(req.containerFile.decodeBase64()).tokenize('\n')
spec[0] == 'Bootstrap: docker'
spec[1] == 'From: {{spack_runner_image}}'
spec[2] == 'stage: final'

and:
new String(req.spackFile.decodeBase64()) == '''\
spack:
specs: [foo]
concretizer: {unify: true, reuse: false}
'''.stripIndent(true)
}

}

0 comments on commit dfb5fc3

Please sign in to comment.