17
17
18
18
package io.seqera.wave.plugin
19
19
20
+ import static io.seqera.wave.util.DockerHelper.*
20
21
21
22
import java.net.http.HttpClient
22
23
import java.net.http.HttpRequest
@@ -54,12 +55,10 @@ import io.seqera.wave.plugin.packer.Packer
54
55
import nextflow.Session
55
56
import nextflow.SysEnv
56
57
import nextflow.container.resolver.ContainerInfo
57
- import nextflow.executor.BashTemplateEngine
58
58
import nextflow.fusion.FusionConfig
59
59
import nextflow.processor.Architecture
60
60
import nextflow.processor.TaskRun
61
61
import nextflow.script.bundle.ResourcesBundle
62
- import nextflow.util.MustacheTemplateEngine
63
62
import nextflow.util.SysHelper
64
63
import org.slf4j.Logger
65
64
import org.slf4j.LoggerFactory
@@ -380,10 +379,11 @@ class WaveClient {
380
379
// map the recipe to a dockerfile
381
380
if ( isCondaLocalFile(attrs. conda) ) {
382
381
condaFile = Path . of(attrs. conda)
383
- dockerScript = condaFileToDockerFile()
382
+ dockerScript = condaFileToDockerFile(config . condaOpts() )
384
383
}
384
+ // 'conda' attributes is resolved as the conda packages to be used
385
385
else {
386
- dockerScript = condaRecipeToDockerFile (attrs. conda)
386
+ dockerScript = condaPackagesToDockerFile (attrs. conda, condaChannels, config . condaOpts() )
387
387
}
388
388
}
389
389
@@ -399,10 +399,10 @@ class WaveClient {
399
399
// map the recipe to a dockerfile
400
400
if ( isSpackFile(attrs. spack) ) {
401
401
spackFile = Path . of(attrs. spack)
402
- dockerScript = spackFileToDockerFile(spackArch)
402
+ dockerScript = spackFileToDockerFile(spackArch, config . spackOpts() )
403
403
}
404
404
else {
405
- dockerScript = spackRecipeToDockerFile (attrs. spack, spackArch)
405
+ dockerScript = spackPackagesToDockerFile (attrs. spack, spackArch, config . spackOpts() )
406
406
}
407
407
}
408
408
@@ -464,105 +464,7 @@ class WaveClient {
464
464
}
465
465
}
466
466
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
- }
507
467
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
- }
566
468
567
469
static protected boolean isCondaLocalFile (String value ) {
568
470
if ( value. contains(' \n ' ) )
0 commit comments