Skip to content

Commit

Permalink
Examples from README.MD added
Browse files Browse the repository at this point in the history
  • Loading branch information
munishchouhan committed Aug 18, 2023
1 parent 7a0cafa commit 98e5372
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/conf/resource-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
},
{
"pattern":"\\Qtemplates/spack/dockerfile-spack-file.txt\\E"
},
{
"pattern":"\\Qio/seqera/wavelit/examples.txt\\E"
}
]},
"bundles":[]
Expand Down
26 changes: 25 additions & 1 deletion app/src/main/java/io/seqera/wavelit/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.OffsetDateTime;
import java.util.Arrays;
import java.util.Base64;
Expand Down Expand Up @@ -57,7 +59,11 @@
/**
* Wavelit main class
*/
@Command(name = "wavelit", description = "Wave command line tool", mixinStandardHelpOptions = true, versionProvider = CliVersionProvider.class, usageHelpAutoWidth = true)
@Command(name = "wavelit",
description = "Wave command line tool",
mixinStandardHelpOptions = true,
versionProvider = CliVersionProvider.class,
usageHelpAutoWidth = true)
public class App implements Runnable {

private static final String DEFAULT_TOWER_ENDPOINT = "https://api.tower.nf";
Expand Down Expand Up @@ -156,6 +162,11 @@ public static void main(String[] args) {
try {
final App app = new App();
final CommandLine cli = new CommandLine(app);

// add examples in help
CommandLine.Model.UsageMessageSpec usageMessageSpec = cli.getCommandSpec().usageMessage();
usageMessageSpec.footer(loadExamples("examples.txt"));

final CommandLine.ParseResult result = cli.parseArgs(args);
if( result.matchedArgs().size()==0 || result.isUsageHelpRequested() ) {
cli.usage(System.out);
Expand All @@ -177,6 +188,19 @@ else if( result.isVersionHelpRequested() ) {
}
}

private static String loadExamples(String exampleFile) {
try(InputStream inputStream = App.class.getResourceAsStream(exampleFile)) {
if (inputStream != null) {
byte[] buffer = new byte[inputStream.available()];
inputStream.read(buffer);
return new String(buffer, StandardCharsets.UTF_8);
}
} catch (IOException e) {
return e.getMessage();
}
return "nothing";
}

protected void setLogLevel() {
if( !isEmpty(logLevel) ) {
Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
Expand Down
45 changes: 45 additions & 0 deletions app/src/main/resources/io/seqera/wavelit/examples.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
Examples

Augment a container image

1. Create a directory holding the files to be added to your container:

mkdir -p new-layer/usr/local/bin
printf 'echo Hello world!' > new-layer/usr/local/bin/hello.sh
chmod +x new-layer/usr/local/bin/hello.sh

2. Run the container via Wave

docker run $(wavelit -i alpine --layer new-layer) sh -c hello.sh

Build a container with Dockerfile

1. Create a Dockerfile for your container image:

cat << EOF > ./Dockerfile
FROM alpine
ADD hello.sh /usr/local/bin/
EOF

2. Create the build context directory:

mkdir -p build-context/
printf 'echo Hello world!' > build-context/hello.sh
chmod +x build-context/hello.sh

3. Build and run the container on the fly:

docker run $(wavelit -f Dockerfile --context build-context) sh -c hello.sh

Build a Conda multi-packages container

docker run $(wavelit --conda-package bamtools=2.5.2 --conda-package samtools=1.17) sh -c 'bamtools --version && samtools --version'

Build a Conda package container arm64 architecture

docker run --platform linux/arm64 $(wavelit --conda-package fastp --platform linux/arm64) sh -c 'fastp --version'

Build a Spack package container

docker run $(wavelit --spack-package cowsay) sh -c 'cowsay Hello world!'

0 comments on commit 98e5372

Please sign in to comment.