From 8e2056e723383c22e6324544062d944a401b8361 Mon Sep 17 00:00:00 2001 From: Paolo Di Tommaso Date: Fri, 13 Dec 2024 14:47:22 +0100 Subject: [PATCH] Improve inspect mode (#5605) Signed-off-by: Paolo Di Tommaso --- .../container/ContainerHandler.groovy | 6 +-- .../inspect/ContainerInspectMode.groovy | 13 +++-- .../inspect/ContainerInspectModeTest.groovy | 52 +++++++++++++++++++ .../io/seqera/wave/plugin/WaveClient.groovy | 4 +- .../seqera/wave/plugin/WaveClientTest.groovy | 2 +- 5 files changed, 68 insertions(+), 9 deletions(-) create mode 100644 modules/nextflow/src/test/groovy/nextflow/container/inspect/ContainerInspectModeTest.groovy diff --git a/modules/nextflow/src/main/groovy/nextflow/container/ContainerHandler.groovy b/modules/nextflow/src/main/groovy/nextflow/container/ContainerHandler.groovy index 0c2c6cc360..2dae5abbc5 100644 --- a/modules/nextflow/src/main/groovy/nextflow/container/ContainerHandler.groovy +++ b/modules/nextflow/src/main/groovy/nextflow/container/ContainerHandler.groovy @@ -70,7 +70,7 @@ class ContainerHandler { if( normalizedImageName.startsWith('docker://') && config.canRunOciImage() ) return normalizedImageName final requiresCaching = normalizedImageName =~ IMAGE_URL_PREFIX - if( ContainerInspectMode.active() && requiresCaching ) + if( ContainerInspectMode.dryRun() && requiresCaching ) return imageName final result = requiresCaching ? createSingularityCache(this.config, normalizedImageName) : normalizedImageName return Escape.path(result) @@ -82,7 +82,7 @@ class ContainerHandler { if( normalizedImageName.startsWith('docker://') && config.canRunOciImage() ) return normalizedImageName final requiresCaching = normalizedImageName =~ IMAGE_URL_PREFIX - if( ContainerInspectMode.active() && requiresCaching ) + if( ContainerInspectMode.dryRun() && requiresCaching ) return imageName final result = requiresCaching ? createApptainerCache(this.config, normalizedImageName) : normalizedImageName return Escape.path(result) @@ -94,7 +94,7 @@ class ContainerHandler { // if the imagename starts with '/' it's an absolute path // otherwise we assume it's in a remote registry and pull it from there final requiresCaching = !imageName.startsWith('/') - if( ContainerInspectMode.active() && requiresCaching ) + if( ContainerInspectMode.dryRun() && requiresCaching ) return imageName final result = requiresCaching ? createCharliecloudCache(this.config, normalizedImageName) : normalizedImageName return Escape.path(result) diff --git a/modules/nextflow/src/main/groovy/nextflow/container/inspect/ContainerInspectMode.groovy b/modules/nextflow/src/main/groovy/nextflow/container/inspect/ContainerInspectMode.groovy index 4b3904e5db..2415de0b26 100644 --- a/modules/nextflow/src/main/groovy/nextflow/container/inspect/ContainerInspectMode.groovy +++ b/modules/nextflow/src/main/groovy/nextflow/container/inspect/ContainerInspectMode.groovy @@ -26,10 +26,17 @@ import groovy.transform.CompileStatic @CompileStatic class ContainerInspectMode { - private static Boolean active + private static Boolean dryRun - static boolean active() { return active==true } + static boolean active() { return dryRun!=null } - static void activate(boolean value) { active = value } + static boolean dryRun() { return dryRun==true } + static void activate(boolean dryRun) { + this.dryRun = dryRun + } + + static void reset() { + dryRun = null + } } diff --git a/modules/nextflow/src/test/groovy/nextflow/container/inspect/ContainerInspectModeTest.groovy b/modules/nextflow/src/test/groovy/nextflow/container/inspect/ContainerInspectModeTest.groovy new file mode 100644 index 0000000000..85c164d076 --- /dev/null +++ b/modules/nextflow/src/test/groovy/nextflow/container/inspect/ContainerInspectModeTest.groovy @@ -0,0 +1,52 @@ +/* + * Copyright 2013-2024, 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 nextflow.container.inspect + +import spock.lang.Specification + +/** + * + * @author Paolo Di Tommaso + */ +class ContainerInspectModeTest extends Specification { + + def 'should validate activate and dry-run' () { + expect: + !ContainerInspectMode.active() + !ContainerInspectMode.dryRun() + + when: + ContainerInspectMode.activate(false) + then: + ContainerInspectMode.active() + !ContainerInspectMode.dryRun() + + when: + ContainerInspectMode.activate(true) + then: + ContainerInspectMode.active() + ContainerInspectMode.dryRun() + + when: + ContainerInspectMode.reset() + then: + !ContainerInspectMode.active() + !ContainerInspectMode.dryRun() + } + +} diff --git a/plugins/nf-wave/src/main/io/seqera/wave/plugin/WaveClient.groovy b/plugins/nf-wave/src/main/io/seqera/wave/plugin/WaveClient.groovy index c3640ce42d..f416c35712 100644 --- a/plugins/nf-wave/src/main/io/seqera/wave/plugin/WaveClient.groovy +++ b/plugins/nf-wave/src/main/io/seqera/wave/plugin/WaveClient.groovy @@ -222,7 +222,7 @@ class WaveClient { fingerprint: assets.fingerprint(), freeze: config.freezeMode(), format: assets.singularity ? 'sif' : null, - dryRun: ContainerInspectMode.active(), + dryRun: ContainerInspectMode.dryRun(), mirror: config.mirrorMode(), scanMode: config.scanMode(), scanLevels: config.scanAllowedLevels() @@ -249,7 +249,7 @@ class WaveClient { towerEndpoint: tower.endpoint, workflowId: tower.workflowId, freeze: config.freezeMode(), - dryRun: ContainerInspectMode.active(), + dryRun: ContainerInspectMode.dryRun(), mirror: config.mirrorMode(), scanMode: config.scanMode(), scanLevels: config.scanAllowedLevels() diff --git a/plugins/nf-wave/src/test/io/seqera/wave/plugin/WaveClientTest.groovy b/plugins/nf-wave/src/test/io/seqera/wave/plugin/WaveClientTest.groovy index 1f54b0a3d7..6f98c3eaea 100644 --- a/plugins/nf-wave/src/test/io/seqera/wave/plugin/WaveClientTest.groovy +++ b/plugins/nf-wave/src/test/io/seqera/wave/plugin/WaveClientTest.groovy @@ -306,7 +306,7 @@ class WaveClientTest extends Specification { req.timestamp instanceof String cleanup: - ContainerInspectMode.activate(false) + ContainerInspectMode.reset() } def 'should create request object and platform' () {