-
Notifications
You must be signed in to change notification settings - Fork 599
/
WaveClientTest.groovy
1329 lines (1181 loc) · 47.8 KB
/
WaveClientTest.groovy
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2013-2023, Seqera Labs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package io.seqera.wave.plugin
import static java.nio.file.StandardOpenOption.*
import java.net.http.HttpRequest
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.attribute.BasicFileAttributes
import java.nio.file.attribute.FileTime
import com.sun.net.httpserver.HttpExchange
import com.sun.net.httpserver.HttpHandler
import com.sun.net.httpserver.HttpServer
import groovy.json.JsonOutput
import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j
import nextflow.Session
import nextflow.SysEnv
import nextflow.container.inspect.ContainerInspectMode
import nextflow.extension.FilesEx
import nextflow.file.FileHelper
import nextflow.processor.TaskRun
import nextflow.script.bundle.ResourcesBundle
import org.apache.commons.compress.archivers.ArchiveStreamFactory
import org.apache.commons.compress.archivers.tar.TarArchiveEntry
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream
import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream
import spock.lang.Shared
import spock.lang.Specification
import spock.lang.Unroll
/**
*
* @author Paolo Di Tommaso <paolo.ditommaso@gmail.com>
*/
@Slf4j
class WaveClientTest extends Specification {
@CompileStatic
private static List<Path> untar(final InputStream is, final Path outputDir) {
final untaredFiles = new LinkedList<Path>();
final debInputStream = (TarArchiveInputStream) new ArchiveStreamFactory().createArchiveInputStream("tar", is);
TarArchiveEntry entry = null;
while ((entry = (TarArchiveEntry)debInputStream.getNextEntry()) != null) {
final outputFile = outputDir.resolve(entry.getName())
if (entry.isDirectory()) {
if (!outputFile.exists()) {
if (!outputFile.mkdirs()) {
throw new IllegalStateException(String.format("Couldn't create directory %s.", outputFile));
}
outputFile.setPermissionsMode( entry.getMode() )
outputFile.setLastModified( entry.getLastModifiedDate().getTime() )
}
}
else {
println "outputFile=$outputFile; mode=${entry.mode}"
outputFile.parent.mkdirs()
final outputFileStream = Files.newOutputStream(outputFile, CREATE, APPEND)
debInputStream.transferTo(outputFileStream)
outputFileStream.close()
outputFile.setPermissionsMode(entry.getMode())
outputFile.setLastModified( entry.getLastModifiedDate().getTime() )
}
untaredFiles.add(outputFile);
}
debInputStream.close();
return untaredFiles
}
byte[] uncompress( byte[] bytes ) {
try (def stream = new GzipCompressorInputStream(new ByteArrayInputStream(bytes))) {
def buffer = new ByteArrayOutputStream()
stream.transferTo(buffer)
return buffer.toByteArray()
}
}
def 'should tar file' () {
given:
def LAST_MODIFIED = FileTime.fromMillis(1_000_000_000_000)
def sess = Mock(Session) { getConfig() >> [wave:[preserveFileTimestamp:true]]}
def folder = Files.createTempDirectory('test')
and:
def bundlePath = folder.resolve('bundle'); bundlePath.mkdir()
bundlePath.resolve('main.nf').text = "I'm the main file"
bundlePath.resolve('this/that').mkdirs()
Files.write(bundlePath.resolve('this/hola.txt'), "Hola".bytes)
Files.write(bundlePath.resolve('this/hello.txt'), "Hello".bytes)
Files.write(bundlePath.resolve('this/that/ciao.txt'), "Ciao".bytes)
and:
FileHelper.visitFiles([type:'any'], bundlePath, '**', {
Files.setLastModifiedTime(it, LAST_MODIFIED)
final mode = it.isDirectory() ? 0700 : 0600
FilesEx.setPermissionsMode(it, mode)
})
and:
def wave = new WaveClient(sess)
when:
def bundle = ResourcesBundle.scan(bundlePath)
def layer = wave.makeLayer(bundle)
then:
layer.tarDigest == 'sha256:81200f6ad32793567d8070375dc51312a1711fedf6a1c6f5e4a97fa3014f3491'
layer.gzipDigest == 'sha256:09a2deca4293245909223db505cf69affa1a8ff8acb745fe3cad38bc0b719110'
layer.gzipSize == 254
and:
def gzip = layer.location.replace('data:','').decodeBase64()
def tar = uncompress(gzip)
def result = folder.resolve('result')
untar( new ByteArrayInputStream(tar), result)
and:
result.resolve('main.nf').text == bundlePath.resolve('main.nf').text
result.resolve('this/hola.txt').text == bundlePath.resolve('this/hola.txt').text
result.resolve('this/hello.txt').text == bundlePath.resolve('this/hello.txt').text
result.resolve('this/that/ciao.txt').text == bundlePath.resolve('this/that/ciao.txt').text
and:
Files.readAttributes(result.resolve('main.nf'), BasicFileAttributes).lastModifiedTime() == LAST_MODIFIED
/*
* create a bundle using different base directory
*/
when:
bundle = ResourcesBundle.scan(bundlePath, [baseDirectory: 'usr/local'])
layer = wave.makeLayer(bundle)
then:
def gzip2 = layer.location.replace('data:','').decodeBase64()
def tar2 = uncompress(gzip2)
def result2 = folder.resolve('result2')
untar( new ByteArrayInputStream(tar2), result2)
and:
result2.resolve('usr/local/main.nf').text == bundlePath.resolve('main.nf').text
result2.resolve('usr/local/this/hola.txt').text == bundlePath.resolve('this/hola.txt').text
result2.resolve('usr/local/this/hello.txt').text == bundlePath.resolve('this/hello.txt').text
result2.resolve('usr/local/this/that/ciao.txt').text == bundlePath.resolve('this/that/ciao.txt').text
/*
* should create a bundle without preserving the file timestamps
*/
when:
def wave3 = new WaveClient(Mock(Session) { getConfig()>>[wave:[:]] })
def bundle3 = ResourcesBundle.scan(bundlePath)
def layer3 = wave3.makeLayer(bundle3)
then:
layer3.tarDigest == 'sha256:f556b94e9b6f5f72b86e44833614b465df9f65cb4210e3f4416292dca1618360'
layer3.gzipDigest == 'sha256:e58685a82452a11faa926843e7861c94bdb93e2c8f098b5c5354ec9b6fee2b68'
layer3.gzipSize == 251
and:
def gzip3 = layer3.location.replace('data:','').decodeBase64()
def tar3 = uncompress(gzip3)
def result3 = folder.resolve('result3')
untar( new ByteArrayInputStream(tar3), result3)
and:
result3.resolve('main.nf').text == bundlePath.resolve('main.nf').text
and:
Files.readAttributes(result3.resolve('main.nf'), BasicFileAttributes).lastModifiedTime() == FileTime.fromMillis(0)
cleanup:
folder?.deleteDir()
}
def 'should create request object' () {
given:
def session = Mock(Session) { getConfig() >> [:]}
def IMAGE = 'foo:latest'
def wave = new WaveClient(session)
when:
def req = wave.makeRequest(WaveAssets.fromImage(IMAGE))
then:
req.containerImage == IMAGE
!req.containerPlatform
!req.containerFile
!req.condaFile
!req.spackFile
!req.containerConfig.layers
!req.freeze
!req.dryRun
and:
req.fingerprint == 'bd2cb4b32df41f2d290ce2366609f2ad'
req.timestamp instanceof String
}
def 'should create request object with freeze mode' () {
given:
def session = Mock(Session) { getConfig() >> [wave:[freeze:true]]}
def IMAGE = 'foo:latest'
def wave = new WaveClient(session)
when:
def req = wave.makeRequest(WaveAssets.fromImage(IMAGE))
then:
req.containerImage == IMAGE
!req.containerPlatform
!req.containerFile
!req.condaFile
!req.spackFile
!req.containerConfig.layers
and:
req.freeze
and:
req.fingerprint == 'bd2cb4b32df41f2d290ce2366609f2ad'
req.timestamp instanceof String
}
def 'should create request object with dry-run mode' () {
given:
ContainerInspectMode.activate(true)
def session = Mock(Session) { getConfig() >> [:]}
def IMAGE = 'foo:latest'
def wave = new WaveClient(session)
when:
def req = wave.makeRequest(WaveAssets.fromImage(IMAGE))
then:
req.containerImage == IMAGE
!req.containerPlatform
!req.containerFile
!req.condaFile
!req.spackFile
!req.containerConfig.layers
and:
req.dryRun
and:
req.fingerprint == 'bd2cb4b32df41f2d290ce2366609f2ad'
req.timestamp instanceof String
cleanup:
ContainerInspectMode.activate(false)
}
def 'should create request object and platform' () {
given:
def session = Mock(Session) { getConfig() >> [:]}
def IMAGE = 'foo:latest'
def PLATFORM = 'amd64'
def wave = new WaveClient(session)
when:
def req = wave.makeRequest(WaveAssets.fromImage(IMAGE, PLATFORM))
then:
req.containerImage == IMAGE
req.containerPlatform == PLATFORM
and:
!req.containerFile
!req.condaFile
!req.spackFile
!req.containerConfig.layers
and:
req.fingerprint == 'd31044e6594126479585c0cdca15c15e'
req.timestamp instanceof String
}
def 'should create request object with dockerfile' () {
given:
def session = Mock(Session) { getConfig() >> [:]}
def DOCKERFILE = 'FROM foo:latest\nRUN something'
def wave = new WaveClient(session)
when:
def req = wave.makeRequest(WaveAssets.fromDockerfile(DOCKERFILE))
then:
!req.containerImage
new String(req.containerFile.decodeBase64()) == DOCKERFILE
!req.condaFile
!req.spackFile
!req.containerConfig.layers
}
def 'should create request object with singularityfile' () {
given:
def session = Mock(Session) { getConfig() >> [:]}
def SINGULARITY_FILE = 'From foo:latest'
def wave = new WaveClient(session)
and:
def assets = new WaveAssets(null,
'linux/amd64',
null,
null,
SINGULARITY_FILE,
null,
null,
null,
true)
when:
def req = wave.makeRequest(assets)
then:
!req.containerImage
new String(req.containerFile.decodeBase64()) == SINGULARITY_FILE
!req.condaFile
!req.spackFile
!req.containerConfig.layers
and:
req.format == 'sif'
}
def 'should create request object with build and cache repos' () {
given:
def session = Mock(Session) { getConfig() >> [wave:[build:[repository:'some/repo',cacheRepository:'some/cache']]]}
def DOCKERFILE = 'FROM foo:latest\nRUN something'
def wave = new WaveClient(session)
when:
def req = wave.makeRequest(WaveAssets.fromDockerfile(DOCKERFILE))
then:
req.buildRepository == 'some/repo'
req.cacheRepository == 'some/cache'
!req.containerImage
new String(req.containerFile.decodeBase64()) == DOCKERFILE
!req.condaFile
!req.spackFile
!req.containerConfig.layers
}
def 'should create request object with conda file' () {
given:
def folder = Files.createTempDirectory('test')
and:
def DOCKERFILE = 'from foo:latest'
def CONDAFILE = folder.resolve('conda.yml'); CONDAFILE.text = 'some conda recipe here'
and:
def session = Mock(Session) { getConfig() >> [:]}
def wave = new WaveClient(session)
when:
def req = wave.makeRequest(new WaveAssets(null, null, null, null, DOCKERFILE, CONDAFILE))
then:
!req.containerImage
new String(req.containerFile.decodeBase64()) == DOCKERFILE
new String(req.condaFile.decodeBase64()) == CONDAFILE.text
!req.containerConfig.layers
cleanup:
folder?.deleteDir()
}
def 'should create request object with spack file' () {
given:
def folder = Files.createTempDirectory('test')
and:
def DOCKERFILE = 'from foo:latest'
def SPACKFILE = folder.resolve('spack.yaml'); SPACKFILE.text = 'some spack recipe here'
and:
def session = Mock(Session) { getConfig() >> [:]}
def wave = new WaveClient(session)
when:
def req = wave.makeRequest(new WaveAssets(null, null, null, null, DOCKERFILE, null, SPACKFILE))
then:
!req.containerImage
new String(req.containerFile.decodeBase64()) == DOCKERFILE
new String(req.spackFile.decodeBase64()) == SPACKFILE.text
!req.containerConfig.layers
cleanup:
folder?.deleteDir()
}
def 'should create request with module resources' () {
given:
def MODULE_RES = Mock(ResourcesBundle) {hasEntries() >> true }
def MODULE_LAYER = Mock(ContainerLayer)
and:
def session = Mock(Session) { getConfig() >> [:]}
WaveClient wave = Spy(WaveClient, constructorArgs: [session])
when:
def assets = new WaveAssets('my:image', null, MODULE_RES)
def req = wave.makeRequest(assets)
then:
1 * wave.makeLayer(MODULE_RES) >> MODULE_LAYER
and:
req.containerImage == 'my:image'
req.containerConfig.layers.size()==1
req.containerConfig.layers[0] == MODULE_LAYER
}
def 'should create request with module and project resources' () {
given:
def MODULE_RES = Mock(ResourcesBundle) {hasEntries() >> true }
def MODULE_LAYER = Mock(ContainerLayer)
and:
def PROJECT_RES = Mock(ResourcesBundle) { hasEntries() >> true }
def PROJECT_LAYER = Mock(ContainerLayer)
and:
def session = Mock(Session) { getConfig() >> [:]}
WaveClient wave = Spy(WaveClient, constructorArgs: [session])
when:
def assets = new WaveAssets('my:image', null, MODULE_RES, null, null, null, null, PROJECT_RES)
def req = wave.makeRequest(assets)
then:
1 * wave.makeLayer(MODULE_RES) >> MODULE_LAYER
1 * wave.makeLayer(PROJECT_RES) >> PROJECT_LAYER
and:
req.containerImage == 'my:image'
req.containerConfig.layers.size()==2
req.containerConfig.layers[0] == PROJECT_LAYER
req.containerConfig.layers[1] == MODULE_LAYER
}
def 'should create asset with image' () {
given:
def session = Mock(Session) { getConfig() >> [:]}
def task = Mock(TaskRun) { getConfig() >> [arch:'amd64'] }
def IMAGE = 'foo:latest'
and:
def client = new WaveClient(session)
when:
def assets = client.resolveAssets(task, IMAGE, false)
then:
assets.containerImage == IMAGE
!assets.moduleResources
!assets.containerFile
!assets.containerConfig
!assets.condaFile
!assets.spackFile
!assets.projectResources
assets.containerPlatform == 'linux/amd64'
}
def 'should create asset with image and platform' () {
given:
def ARCH = 'linux/arm64'
def session = Mock(Session) { getConfig() >> [:] }
def task = Mock(TaskRun) { getConfig() >> [arch:ARCH.toString()] }
def IMAGE = 'foo:latest'
and:
def client = new WaveClient(session)
when:
def assets = client.resolveAssets(task, IMAGE, false)
then:
assets.containerImage == IMAGE
assets.containerPlatform == 'linux/arm64'
!assets.moduleResources
!assets.containerFile
!assets.containerConfig
!assets.condaFile
!assets.spackFile
!assets.projectResources
}
def 'should create asset with image and bundle' () {
given:
def IMAGE = 'foo:latest'
def BUNDLE = Mock(ResourcesBundle)
and:
def session = Mock(Session) { getConfig() >> [:]}
def task = Mock(TaskRun) { getConfig() >> [:]; getModuleBundle() >> BUNDLE }
and:
def client = new WaveClient(session)
when:
def assets = client.resolveAssets(task, IMAGE, false)
then:
assets.containerImage == IMAGE
assets.moduleResources == BUNDLE
!assets.containerFile
!assets.containerConfig
!assets.condaFile
!assets.spackFile
!assets.projectResources
}
def 'should create asset with image and bundle and container config' () {
given:
def IMAGE = 'foo:latest'
def BUNDLE = Mock(ResourcesBundle)
def ARCH = 'linux/arm64'
def CONTAINER_CONFIG = new ContainerConfig(entrypoint: ['entry.sh'], layers: [new ContainerLayer(location: 'http://somewhere')])
and:
def session = Mock(Session) { getConfig() >> [:]}
def task = Mock(TaskRun) { getConfig() >> [arch:ARCH.toString()]; getModuleBundle() >> BUNDLE }
and:
WaveClient client = Spy(WaveClient, constructorArgs:[session])
when:
def assets = client.resolveAssets(task, IMAGE, false)
then:
client.resolveContainerConfig(ARCH) >> CONTAINER_CONFIG
and:
assets.containerImage == IMAGE
assets.moduleResources == BUNDLE
assets.containerConfig == CONTAINER_CONFIG
and:
!assets.containerFile
!assets.condaFile
!assets.spackFile
!assets.projectResources
}
def 'should create asset with dockerfile' () {
given:
def folder = Files.createTempDirectory('test')
def session = Mock(Session) { getConfig() >> [:]}
and:
def DOCKERFILE = folder.resolve('Dockerfile')
DOCKERFILE.text = 'FROM foo\nRUN this/that'
and:
def BUNDLE = Mock(ResourcesBundle) { getDockerfile() >> DOCKERFILE }
and:
def task = Mock(TaskRun) {getModuleBundle() >> BUNDLE; getConfig() >> [:] }
and:
def client = new WaveClient(session)
when:
def assets = client.resolveAssets(task, null, false)
then:
assets.containerFile == 'FROM foo\nRUN this/that'
assets.moduleResources == BUNDLE
!assets.containerImage
!assets.containerConfig
!assets.condaFile
!assets.spackFile
!assets.projectResources
cleanup:
folder?.deleteDir()
}
def 'should create asset with conda recipe' () {
given:
def session = Mock(Session) { getConfig() >> [:]}
and:
def task = Mock(TaskRun) {getConfig() >> [conda:"bioconda::rseqc=3.0.1 'conda-forge::r-base>=3.5'"] }
and:
def client = new WaveClient(session)
when:
def assets = client.resolveAssets(task, null, false)
then:
assets.containerFile == '''\
FROM mambaorg/micromamba:1.5.5
COPY --chown=$MAMBA_USER:$MAMBA_USER conda.yml /tmp/conda.yml
RUN micromamba install -y -n base -f /tmp/conda.yml \\
&& micromamba install -y -n base conda-forge::procps-ng \\
&& micromamba clean -a -y
USER root
ENV PATH="$MAMBA_ROOT_PREFIX/bin:$PATH"
'''.stripIndent()
and:
!assets.moduleResources
!assets.containerImage
!assets.containerConfig
!assets.spackFile
!assets.projectResources
and:
assets.condaFile.text == '''\
channels:
- seqera
- conda-forge
- bioconda
- defaults
dependencies:
- bioconda::rseqc=3.0.1
- conda-forge::r-base>=3.5
'''.stripIndent(true)
}
def 'should create asset with conda lock file' () {
given:
def session = Mock(Session) { getConfig() >> [:]}
and:
def task = Mock(TaskRun) {getConfig() >> [conda:'https://host.com/conda-lock.yml'] }
and:
def client = new WaveClient(session)
when:
def assets = client.resolveAssets(task, null, false)
then:
assets.containerFile == '''\
FROM mambaorg/micromamba:1.5.5
RUN \\
micromamba install -y -n base -c seqera -c conda-forge -c bioconda -c defaults -f https://host.com/conda-lock.yml \\
&& micromamba install -y -n base conda-forge::procps-ng \\
&& micromamba clean -a -y
USER root
ENV PATH="$MAMBA_ROOT_PREFIX/bin:$PATH"
'''.stripIndent()
and:
!assets.moduleResources
!assets.containerImage
!assets.containerConfig
!assets.condaFile
!assets.spackFile
!assets.projectResources
}
def 'should create asset with spack recipe' () {
given:
def session = Mock(Session) { getConfig() >> [:]}
and:
def task = Mock(TaskRun) {getConfig() >> [spack:"rseqc@3.0.1 'rbase@3.5'", arch:"amd64"] }
and:
def client = new WaveClient(session)
when:
def assets = client.resolveAssets(task, null, false)
then:
assets.containerFile == '''\
# Runner image
FROM {{spack_runner_image}}
COPY --from=builder /opt/spack-env /opt/spack-env
COPY --from=builder /opt/software /opt/software
COPY --from=builder /opt/._view /opt/._view
# Entrypoint for Singularity
RUN mkdir -p /.singularity.d/env && \\
cp -p /opt/spack-env/z10_spack_environment.sh /.singularity.d/env/91-environment.sh
# Entrypoint for Docker
RUN echo "#!/usr/bin/env bash\\n\\nset -ef -o pipefail\\nsource /opt/spack-env/z10_spack_environment.sh\\nexec \\"\\\$@\\"" \\
>/opt/spack-env/spack_docker_entrypoint.sh && chmod a+x /opt/spack-env/spack_docker_entrypoint.sh
ENTRYPOINT [ "/opt/spack-env/spack_docker_entrypoint.sh" ]
CMD [ "/bin/bash" ]
'''.stripIndent()
and:
!assets.moduleResources
!assets.containerImage
!assets.containerConfig
!assets.condaFile
!assets.projectResources
and:
assets.spackFile.text == '''\
spack:
specs: [rseqc@3.0.1, rbase@3.5]
concretizer: {unify: true, reuse: false}
'''.stripIndent(true)
}
def 'should create asset with conda file' () {
given:
def folder = Files.createTempDirectory('test')
def condaFile = folder.resolve('conda.yml'); condaFile.text = 'the-conda-recipe-here'
and:
def session = Mock(Session) { getConfig() >> [:]}
def task = Mock(TaskRun) {getConfig() >> [conda:condaFile.toString()] }
and:
def client = new WaveClient(session)
when:
def assets = client.resolveAssets(task, null, false)
then:
assets.containerFile == '''\
FROM mambaorg/micromamba:1.5.5
COPY --chown=$MAMBA_USER:$MAMBA_USER conda.yml /tmp/conda.yml
RUN micromamba install -y -n base -f /tmp/conda.yml \\
&& micromamba install -y -n base conda-forge::procps-ng \\
&& micromamba clean -a -y
USER root
ENV PATH="$MAMBA_ROOT_PREFIX/bin:$PATH"
'''.stripIndent()
and:
assets.condaFile == condaFile
and:
!assets.moduleResources
!assets.containerImage
!assets.containerConfig
!assets.spackFile
!assets.projectResources
cleanup:
folder?.deleteDir()
}
def 'should create asset with spack file' () {
given:
def folder = Files.createTempDirectory('test')
def spackFile = folder.resolve('spack.yaml'); spackFile.text = 'the-spack-recipe-here'
and:
def session = Mock(Session) { getConfig() >> [:]}
def task = Mock(TaskRun) {getConfig() >> [spack:spackFile.toString(), arch: 'amd64'] }
and:
def client = new WaveClient(session)
when:
def assets = client.resolveAssets(task, null, false)
then:
assets.containerFile == '''\
# Runner image
FROM {{spack_runner_image}}
COPY --from=builder /opt/spack-env /opt/spack-env
COPY --from=builder /opt/software /opt/software
COPY --from=builder /opt/._view /opt/._view
# Entrypoint for Singularity
RUN mkdir -p /.singularity.d/env && \\
cp -p /opt/spack-env/z10_spack_environment.sh /.singularity.d/env/91-environment.sh
# Entrypoint for Docker
RUN echo "#!/usr/bin/env bash\\n\\nset -ef -o pipefail\\nsource /opt/spack-env/z10_spack_environment.sh\\nexec \\"\\\$@\\"" \\
>/opt/spack-env/spack_docker_entrypoint.sh && chmod a+x /opt/spack-env/spack_docker_entrypoint.sh
ENTRYPOINT [ "/opt/spack-env/spack_docker_entrypoint.sh" ]
CMD [ "/bin/bash" ]
'''.stripIndent()
and:
assets.spackFile == spackFile
and:
!assets.moduleResources
!assets.containerImage
!assets.containerConfig
!assets.condaFile
!assets.projectResources
cleanup:
folder?.deleteDir()
}
// ==== singularity native build + conda ====
def 'should create asset with conda recipe and singularity native build' () {
given:
def session = Mock(Session) { getConfig() >> [:]}
and:
def task = Mock(TaskRun) {getConfig() >> [conda:'salmon=1.2.3'] }
and:
def client = new WaveClient(session)
when:
def assets = client.resolveAssets(task, null, true)
then:
assets.containerFile == '''\
BootStrap: docker
From: mambaorg/micromamba:1.5.5
%files
{{wave_context_dir}}/conda.yml /scratch/conda.yml
%post
micromamba install -y -n base -f /scratch/conda.yml
micromamba install -y -n base conda-forge::procps-ng
micromamba clean -a -y
%environment
export PATH="$MAMBA_ROOT_PREFIX/bin:$PATH"
'''.stripIndent()
and:
assets.singularity
and:
!assets.moduleResources
!assets.containerImage
!assets.containerConfig
!assets.spackFile
!assets.projectResources
and:
assets.condaFile.text == '''\
channels:
- seqera
- conda-forge
- bioconda
- defaults
dependencies:
- salmon=1.2.3
'''.stripIndent(true)
}
def 'should create asset with conda remote lock file and singularity native build' () {
given:
def session = Mock(Session) { getConfig() >> [:]}
and:
def task = Mock(TaskRun) {getConfig() >> [conda:'https://host.com/lock-file.yaml'] }
and:
def client = new WaveClient(session)
when:
def assets = client.resolveAssets(task, null, true)
then:
assets.containerFile == '''\
BootStrap: docker
From: mambaorg/micromamba:1.5.5
%post
micromamba install -y -n base -c seqera -c conda-forge -c bioconda -c defaults -f https://host.com/lock-file.yaml
micromamba install -y -n base conda-forge::procps-ng
micromamba clean -a -y
%environment
export PATH="$MAMBA_ROOT_PREFIX/bin:$PATH"
'''.stripIndent()
and:
assets.singularity
and:
!assets.moduleResources
!assets.containerImage
!assets.containerConfig
!assets.condaFile
!assets.spackFile
!assets.projectResources
}
def 'should create asset with conda file and singularity native build' () {
given:
def folder = Files.createTempDirectory('test')
def condaFile = folder.resolve('conda.yml'); condaFile.text = 'the-conda-recipe-here'
and:
def session = Mock(Session) { getConfig() >> [:]}
def task = Mock(TaskRun) {getConfig() >> [conda:condaFile.toString()] }
and:
def client = new WaveClient(session)
when:
def assets = client.resolveAssets(task, null, true)
then:
assets.containerFile == '''\
BootStrap: docker
From: mambaorg/micromamba:1.5.5
%files
{{wave_context_dir}}/conda.yml /scratch/conda.yml
%post
micromamba install -y -n base -f /scratch/conda.yml
micromamba install -y -n base conda-forge::procps-ng
micromamba clean -a -y
%environment
export PATH="$MAMBA_ROOT_PREFIX/bin:$PATH"
'''.stripIndent()
and:
assets.condaFile == condaFile
assets.singularity
and:
!assets.moduleResources
!assets.containerImage
!assets.containerConfig
!assets.spackFile
!assets.projectResources
cleanup:
folder?.deleteDir()
}
def 'should create assets with spack recipe for singularity' () {
given:
def session = Mock(Session) { getConfig() >> [wave:[build:[spack:[commands: ['cmd-foo','cmd-bar']]]]]}
and:
def task = Mock(TaskRun) {getConfig() >> [spack:"rseqc@3.0.1 'rbase@3.5'", arch:"amd64"] }
and:
def client = new WaveClient(session)
when:
def assets = client.resolveAssets(task, null, true)
then:
assets.containerFile == '''\
Bootstrap: docker
From: {{spack_runner_image}}
stage: final
%files from build
/opt/spack-env /opt/spack-env
/opt/software /opt/software
/opt/._view /opt/._view
/opt/spack-env/z10_spack_environment.sh /.singularity.d/env/91-environment.sh
%post
cmd-foo
cmd-bar
'''.stripIndent()
and:
!assets.moduleResources
!assets.containerImage
!assets.containerConfig
!assets.condaFile
!assets.projectResources
and:
assets.spackFile.text == '''\
spack:
specs: [rseqc@3.0.1, rbase@3.5]
concretizer: {unify: true, reuse: false}
'''.stripIndent(true)
}
def 'should create asset with spack file for singularity' () {
given:
def folder = Files.createTempDirectory('test')
def spackFile = folder.resolve('spack.yml');
spackFile.text = '''\
spack:
specs: [rseqc@3.0.1, rbase@3.5]
concretizer: {unify: true, reuse: false}
'''.stripIndent(true)
and:
def session = Mock(Session) { getConfig() >> [wave:[build:[spack:[basePackages: 'nano@1.2.3']]]]}
def task = Mock(TaskRun) {getConfig() >> [spack:spackFile.toString()] }
and:
def client = new WaveClient(session)
when:
def assets = client.resolveAssets(task, null, true)
then:
assets.containerFile == '''\
Bootstrap: docker
From: {{spack_runner_image}}
stage: final
%files from build
/opt/spack-env /opt/spack-env
/opt/software /opt/software
/opt/._view /opt/._view
/opt/spack-env/z10_spack_environment.sh /.singularity.d/env/91-environment.sh
%post
'''.stripIndent()
and:
!assets.moduleResources
!assets.containerImage
!assets.containerConfig
!assets.projectResources
!assets.condaFile
and:
assets.spackFile.text == '''\
spack:
specs: [rseqc@3.0.1, rbase@3.5, nano@1.2.3]
concretizer: {unify: true, reuse: false}
'''.stripIndent(true)
cleanup:
folder?.deleteDir()
}
def 'should create assets with project resources' () {
given:
def MODULE_RES = Mock(ResourcesBundle)
def PROJECT_RES = Mock(ResourcesBundle)
def CONTAINER_CONFIG = Mock(ContainerConfig)
def BIN_DIR = Path.of('/something/bin')
def ARCH = 'linux/arm64'
and:
def task = Mock(TaskRun) {getModuleBundle() >> MODULE_RES; getConfig() >> [arch:ARCH.toString()] }
and:
def session = Mock(Session) {
getConfig() >> [wave: [bundleProjectResources: true]]
getBinDir() >> BIN_DIR
}
and:
WaveClient wave = Spy(WaveClient, constructorArgs: [session])
when:
def assets = wave.resolveAssets(task, 'image:latest', false)
then:
1 * wave.projectResources(BIN_DIR) >> PROJECT_RES
and:
1 * wave.resolveContainerConfig(ARCH) >> CONTAINER_CONFIG
and:
assets.moduleResources == MODULE_RES
assets.projectResources == PROJECT_RES
assets.containerImage == 'image:latest'
}
def 'should resolve conflicts' () {
given:
def session = Mock(Session) { getConfig() >> [:]}
and:
def client = new WaveClient(session)
when:
def result = client.resolveConflicts([:], [])
then:
result == [:]
when:
result = client.resolveConflicts([dockerfile:'x',conda:'y',container:'z'], ['conda'])
then:
result == [conda:'y']
when:
result = client.resolveConflicts([dockerfile:'x',conda:'y',container:'z'], ['conda','dockerfile'])
then:
result == [conda:'y']
when:
result = client.resolveConflicts([dockerfile:'x',container:'z'], ['conda','dockerfile'])
then:
result == [dockerfile:'x']
when:
result = client.resolveConflicts([spack:'x',container:'z'], ['conda','spack'])
then:
result == [spack:'x']
}