1717
1818package io.seqera.wave.plugin
1919
20+ import static io.seqera.wave.util.DockerHelper.*
2021
2122import java.net.http.HttpClient
2223import java.net.http.HttpRequest
@@ -54,12 +55,10 @@ import io.seqera.wave.plugin.packer.Packer
5455import nextflow.Session
5556import nextflow.SysEnv
5657import nextflow.container.resolver.ContainerInfo
57- import nextflow.executor.BashTemplateEngine
5858import nextflow.fusion.FusionConfig
5959import nextflow.processor.Architecture
6060import nextflow.processor.TaskRun
6161import nextflow.script.bundle.ResourcesBundle
62- import nextflow.util.MustacheTemplateEngine
6362import nextflow.util.SysHelper
6463import org.slf4j.Logger
6564import org.slf4j.LoggerFactory
@@ -380,10 +379,11 @@ class WaveClient {
380379 // map the recipe to a dockerfile
381380 if ( isCondaLocalFile(attrs. conda) ) {
382381 condaFile = Path . of(attrs. conda)
383- dockerScript = condaFileToDockerFile()
382+ dockerScript = condaFileToDockerFile(config . condaOpts() )
384383 }
384+ // 'conda' attributes is resolved as the conda packages to be used
385385 else {
386- dockerScript = condaRecipeToDockerFile (attrs. conda)
386+ dockerScript = condaPackagesToDockerFile (attrs. conda, condaChannels, config . condaOpts() )
387387 }
388388 }
389389
@@ -399,10 +399,10 @@ class WaveClient {
399399 // map the recipe to a dockerfile
400400 if ( isSpackFile(attrs. spack) ) {
401401 spackFile = Path . of(attrs. spack)
402- dockerScript = spackFileToDockerFile(spackArch)
402+ dockerScript = spackFileToDockerFile(spackArch, config . spackOpts() )
403403 }
404404 else {
405- dockerScript = spackRecipeToDockerFile (attrs. spack, spackArch)
405+ dockerScript = spackPackagesToDockerFile (attrs. spack, spackArch, config . spackOpts() )
406406 }
407407 }
408408
@@ -464,105 +464,7 @@ class WaveClient {
464464 }
465465 }
466466
467- protected String condaFileToDockerFile () {
468- final template = """ \
469- FROM {{base_image}}
470- COPY --chown=\$ MAMBA_USER:\$ MAMBA_USER conda.yml /tmp/conda.yml
471- RUN micromamba install -y -n base -f /tmp/conda.yml && \\
472- {{base_packages}}
473- micromamba clean -a -y
474- """ . stripIndent(true )
475- final image = config. condaOpts(). mambaImage
476-
477- final basePackage = config. condaOpts(). basePackages ? " micromamba install -y -n base ${ config.condaOpts().basePackages} && \\ " . toString() : null
478- final binding = [' base_image' : image, ' base_packages' : basePackage]
479- final result = new MustacheTemplateEngine (). render(template, binding)
480-
481- return addCommands(result)
482- }
483-
484- // Dockerfile template adpated from the Spack package manager
485- // https://github.com/spack/spack/blob/develop/share/spack/templates/container/Dockerfile
486- // LICENSE APACHE 2.0
487- protected String spackFileToDockerFile (String spackArch ) {
488-
489- String cmd_template = ' '
490- final binding = [
491- ' builder_image' : config. spackOpts(). builderImage,
492- ' c_flags' : config. spackOpts(). cFlags,
493- ' cxx_flags' : config. spackOpts(). cxxFlags,
494- ' f_flags' : config. spackOpts(). fFlags,
495- ' spack_arch' : spackArch,
496- ' checksum_string' : config. spackOpts(). checksum ? ' ' : ' -n ' ,
497- ' runner_image' : config. spackOpts(). runnerImage,
498- ' os_packages' : config. spackOpts(). osPackages,
499- ' add_commands' : addCommands(cmd_template),
500- ]
501- final template = WaveClient . class. getResource(' /templates/spack/dockerfile-spack-file.txt' )
502- try (final reader = template. newReader()) {
503- final result = new BashTemplateEngine (). render(reader, binding)
504- return result
505- }
506- }
507467
508- protected String addCommands (String result ) {
509- if ( config. condaOpts(). commands )
510- for ( String cmd : config. condaOpts(). commands ) {
511- result + = cmd + " \n "
512- }
513- if ( config. spackOpts(). commands )
514- for ( String cmd : config. spackOpts(). commands ) {
515- result + = cmd + " \n "
516- }
517- return result
518- }
519-
520- protected String condaRecipeToDockerFile (String recipe ) {
521- final template = """ \
522- FROM {{base_image}}
523- RUN \\
524- micromamba install -y -n base {{channel_opts}} \\
525- {{target}} \\
526- {{base_packages}}
527- && micromamba clean -a -y
528- """ . stripIndent(true )
529-
530- final channelsOpts = condaChannels. collect(it -> " -c $it " ). join(' ' )
531- final image = config. condaOpts(). mambaImage
532- final target = recipe. startsWith(' http://' ) || recipe. startsWith(' https://' )
533- ? " -f $recipe " . toString()
534- : recipe
535- final basePackage = config. condaOpts(). basePackages ? " && micromamba install -y -n base ${ config.condaOpts().basePackages} \\ " . toString() : null
536- final binding = [base_image : image, channel_opts : channelsOpts, target :target, base_packages : basePackage]
537- final result = new MustacheTemplateEngine (). render(template, binding)
538- return addCommands(result)
539- }
540-
541- // Dockerfile template adpated from the Spack package manager
542- // https://github.com/spack/spack/blob/develop/share/spack/templates/container/Dockerfile
543- // LICENSE APACHE 2.0
544- protected String spackRecipeToDockerFile (String recipe , String spackArch ) {
545-
546- String cmd_template = ' '
547- final binding = [
548- ' recipe' : recipe,
549- ' builder_image' : config. spackOpts(). builderImage,
550- ' c_flags' : config. spackOpts(). cFlags,
551- ' cxx_flags' : config. spackOpts(). cxxFlags,
552- ' f_flags' : config. spackOpts(). fFlags,
553- ' spack_arch' : spackArch,
554- ' checksum_string' : config. spackOpts(). checksum ? ' ' : ' -n ' ,
555- ' runner_image' : config. spackOpts(). runnerImage,
556- ' os_packages' : config. spackOpts(). osPackages,
557- ' add_commands' : addCommands(cmd_template),
558- ]
559- final template = WaveClient . class. getResource(' /templates/spack/dockerfile-spack-recipe.txt' )
560-
561- try (final reader = template. newReader()) {
562- final result = new BashTemplateEngine (). render(reader, binding)
563- return result
564- }
565- }
566468
567469 static protected boolean isCondaLocalFile (String value ) {
568470 if ( value. contains(' \n ' ) )
0 commit comments