Skip to content

Commit

Permalink
Improve inspect mode (#5605)
Browse files Browse the repository at this point in the history

Signed-off-by: Paolo Di Tommaso <[email protected]>
  • Loading branch information
pditommaso authored Dec 13, 2024
1 parent 0aa76af commit 8e2056e
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
*/
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()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' () {
Expand Down

0 comments on commit 8e2056e

Please sign in to comment.