Skip to content

Commit

Permalink
Added --config-working-dir to specify WORKDIR of the image (#12)
Browse files Browse the repository at this point in the history

Signed-off-by: Paolo Di Tommaso <[email protected]>
Co-authored-by: Paolo Di Tommaso <[email protected]>
  • Loading branch information
munishchouhan and pditommaso authored Aug 12, 2023
1 parent 687f724 commit 5fd0224
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
11 changes: 10 additions & 1 deletion app/src/main/java/io/seqera/wavelit/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ public class App implements Runnable {
@Option(names = {"--config-entrypoint"}, paramLabel = "''", description = "Overwrite the default ENTRYPOINT of the image.")
private String entrypoint;

@Option(names = {"--config-working-dir"}, paramLabel = "''", description = "Overwrite the default WORKDIR of the image e.g. /some/work/dir.")
private String workingDir;

@Option(names = {"--conda-file"}, paramLabel = "''", description = "A Conda file used to build the container e.g. /some/path/conda.yaml.")
private String condaFile;

Expand Down Expand Up @@ -380,10 +383,16 @@ protected ContainerConfig prepareConfig() {

// add the command if specified
if( command != null ){
if( "".equals(command) ) throw new IllegalCliArgumentException("The specified command is an empty string");
if( "".equals(command.trim()) ) throw new IllegalCliArgumentException("The command cannot be an empty string");
result.cmd = List.of(command);
}

//add the working directory if specified
if( workingDir != null ){
if( "".equals(workingDir.trim()) ) throw new IllegalCliArgumentException("The working directory cannot be empty string");
result.workingDir = workingDir;
}

// add the layers to the resulting config if specified
if( layerDirs!=null ) for( String it : layerDirs ) {
final Path loc = Path.of(it);
Expand Down
30 changes: 30 additions & 0 deletions app/src/test/groovy/io/seqera/wavelit/AppTest.groovy
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.seqera.wavelit

import java.nio.file.Files
import java.time.Instant

import io.seqera.wave.api.ContainerConfig
Expand Down Expand Up @@ -86,6 +87,35 @@ class AppTest extends Specification {

}

def "test valid working directory"() {
given:
def app = new App()
String[] args = ["--config-working-dir", "/work/dir"]

when:
new CommandLine(app).parseArgs(args)
then:
app.@workingDir == "/work/dir"

when:
def config = app.prepareConfig()
then:
config == new ContainerConfig(workingDir: '/work/dir')
}

def "test invalid working directory"() {
given:
def app = new App()
String[] args = ["--config-working-dir", " "]

when:
new CommandLine(app).parseArgs(args)
app.prepareConfig()
then:
thrown(IllegalCliArgumentException)

}

def 'should dump response to yaml' () {
given:
def app = new App()
Expand Down

0 comments on commit 5fd0224

Please sign in to comment.