Skip to content

Commit a402257

Browse files
committed
πŸ“ docs: improve instructions for hello-containers
1 parent 11703a3 commit a402257

File tree

6 files changed

+88
-24
lines changed

6 files changed

+88
-24
lines changed

β€Ždocs/hello_nextflow/03_hello_containers.mdβ€Ž

Lines changed: 72 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,14 @@ Click on "+Add" and then "Get Container" to request a container image for the `q
180180
![Seqera Containers](img/seqera-containers-2.png)
181181

182182
If this is the first time a community container has been built for this package, it may take a few minutes to complete.
183-
Click to copy the URI (e.g. `community.wave.seqera.io/library/pip_quote:25b3982790125217`) of the container image that was created for you.
183+
Click to copy the URI (e.g. `community.wave.seqera.io/library/pip_quote:ae07804021465ee9`) of the container image that was created for you.
184184

185185
### 2.3. Use the container image
186186

187187
You can now use the container image to run the `quote` command and get a random saying from Grace Hopper.
188188

189189
```bash
190-
docker run --rm community.wave.seqera.io/library/pip_quote:25b3982790125217 quote "Albert Einstein"
190+
docker run --rm community.wave.seqera.io/library/pip_quote:ae07804021465ee9 quote "Grace Hopper"
191191
```
192192

193193
Output:
@@ -211,7 +211,7 @@ channels:
211211
dependencies:
212212
- pip
213213
- pip:
214-
- quote==2.0.4
214+
- quote==3.0.0
215215
```
216216

217217
```Dockerfile
@@ -293,6 +293,7 @@ nextflow run hello_containers.nf
293293
!!! NOTE
294294

295295
The `nextflow.config` in our current working directory contains `docker.enabled = true`, which tells Nextflow to use Docker to run processes.
296+
296297
Without that configuration we would have to specify the `-with-docker` flag when running the script.
297298

298299
### 3.3. Check the results
@@ -312,6 +313,47 @@ You should see a new directory called `containers/results` that contains the out
312313
|| ||
313314
```
314315

316+
### 3.4. Explore how Nextflow launched the containerized task
317+
318+
Let's take a look at the task directory for one of the cowsay tasks to see how Nextflow works with containers under the hood.
319+
320+
Check your the output form your `nextflow run` command to find the task ID for the `cowsay` process.
321+
Then checkout the task directory for that task.
322+
323+
```bash
324+
tree -a work/8c/738ac55b80e7b6170aa84a68412454
325+
work/8c/738ac55b80e7b6170aa84a68412454
326+
β”œβ”€β”€ .command.begin
327+
β”œβ”€β”€ .command.err
328+
β”œβ”€β”€ .command.log
329+
β”œβ”€β”€ .command.out
330+
β”œβ”€β”€ .command.run
331+
β”œβ”€β”€ .command.sh
332+
β”œβ”€β”€ .exitcode
333+
β”œβ”€β”€ cowsay-output-Bonjour.txt
334+
└── output-Bonjour.txt -> /workspace/gitpod/nf-training/hello-nextflow/work/0e/e96c123cb7ae9ff7b7bed1c5444009/output-Bonjour.txt
335+
336+
1 directory, 9 files
337+
```
338+
339+
Open the `.command.run` file which holds all the busywork that Nextflow does under the hood.
340+
341+
```bash
342+
code work/8c/738ac55b80e7b6170aa84a68412454/.command.run
343+
```
344+
345+
Search for `nxf_launch` and you should see something like this:
346+
347+
```bash
348+
nxf_launch() {
349+
docker run -i --cpu-shares 1024 -e "NXF_TASK_WORKDIR" -v /workspace/gitpod/nf-training/hello-nextflow/work:/workspace/gitpod/nf-training/hello-nextflow/work -w "$NXF_TASK_WORKDIR" --name $NXF_BOXID community.wave.seqera.io/library/pip_cowsay:131d6a1b707a8e65 /bin/bash -ue /workspace/gitpod/nf-training/hello-nextflow/work/8c/738ac55b80e7b6170aa84a68412454/.command.sh
350+
}
351+
```
352+
353+
As you can see, Nextflow is using the `docker run` command to launch the task.
354+
It also mounts the task's working directory into the container, sets the working directory inside the container to the task's working directory, and runs our templated bash script in the `.command.sh` file.
355+
All the hard work we learned about in the previous sections is done for us by Nextflow!
356+
315357
### Takeaway
316358

317359
You know how to use containers in Nextflow to run processes.
@@ -320,19 +362,41 @@ You know how to use containers in Nextflow to run processes.
320362

321363
An optional exercise to fetch quotes on computer/biology pioneers using the `quote` container and output them using the `cowsay` container.
322364

323-
## 4. OPTIONAL EXERCISE: Connect the `quote` container with the `cowsay` container
324-
325-
As an optional exercise, you can add a locally-built or Seqera Containers-built `quote` container to a getQuote process in the `hello_containers.nf` script and connect the output to the `cowsay` container.
365+
## 4. STRETCH EXERCISE: Connect the `quote` container with the `cowsay` container
366+
367+
This section contains some stretch exercises, to practice what you've learned so far.
368+
Doing these exercises are _not required_ to understand later parts of the training, but provide a fun way to reinforce your learnings by figuring out how to connect the `quote` container with the `cowsay` container.
369+
370+
```console title="cowsay-output-Grace-Hopper.txt"
371+
_________________________________________________
372+
/ \
373+
| Humans are allergic to change. They love to |
374+
| say, 'We've always done it this way.' I try to fi |
375+
| ght that. That's why I have a clock on my wall th |
376+
| at runs counter-clockwise. |
377+
| -Grace Hopper |
378+
\ /
379+
=================================================
380+
\
381+
\
382+
^__^
383+
(oo)\_______
384+
(__)\ )\/\
385+
||----w |
386+
|| ||
387+
```
326388

327389
### 4.1. Modify the `hello_containers.nf` script to use a getQuote process
328390

329391
We have a list of computer and biology pioneers in the `containers/data/pioneers.csv` file.
330392
At a high level, to complete this exercise you will need to:
331393

332-
- modify the `params.input_file` to point to the `pioneers.csv` file.
394+
- modify the default `params.input_file` to point to the `pioneers.csv` file.
333395
- Create a `getQuote` process that uses the `quote` container to fetch a quote for each input.
334396
- Connect the output of the `getQuote` process to the `cowsay` process to display the quote.
335397

398+
For the `quote` container image, you can either use the one you built yourself in the previous stretch exercise or use the one you got from Seqera Containers .
399+
336400
!!! Hint
337401

338402
A good choice for the `script` block of your getQuote process might be:
@@ -341,6 +405,7 @@ At a high level, to complete this exercise you will need to:
341405
def safe_author = author.tokenize(' ').join('-')
342406
"""
343407
quote "$author" > quote-${safe_author}.txt
408+
echo "-${author}" >> quote-${safe_author}.txt
344409
"""
345410
```
346411

β€Žhello-nextflow/hello-containers-3.nfβ€Ž renamed to β€Žhello-nextflow/containers/scripts/hello-containers-3.nfβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ process sayHello {
3030
}
3131

3232
/*
33-
* Use a text replace utility to convert the greeting to uppercase
33+
* Use a cow (or other character) to say some text
3434
*/
3535
process cowSay {
3636

β€Žhello-nextflow/hello-containers-4.1.nfβ€Ž renamed to β€Žhello-nextflow/containers/scripts/hello-containers-4.1.nfβ€Ž

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ process sayHello {
3030
}
3131

3232
/*
33-
* Use a text replace utility to convert the greeting to uppercase
33+
* Use a cow (or other character) to say some text
3434
*/
3535
process cowSay {
3636

@@ -48,10 +48,10 @@ process cowSay {
4848
"""
4949
}
5050

51-
process quote {
51+
process getQuote {
5252

5353
publishDir 'containers/results', mode: 'copy'
54-
container 'community.wave.seqera.io/library/pip_quote:25b3982790125217'
54+
container 'community.wave.seqera.io/library/pip_quote:ae07804021465ee9'
5555

5656
input:
5757
val author
@@ -63,10 +63,8 @@ process quote {
6363
// Replace the spaces in the author with hyphens for the output filename
6464
def safe_author = author.tokenize(' ').join('-')
6565
"""
66-
# The stdout and stderr of the quote command are swapped so we redirect them to the correct files
67-
# Pending fix: https://github.com/maxhumber/quote/issues/12
68-
# quote "$author" > quote-${safe_author}.txt
69-
quote "$author" > /dev/null 2> quote-${safe_author}.txt || true
66+
quote "$author" > quote-${safe_author}.txt
67+
echo "-${author}" >> quote-${safe_author}.txt
7068
"""
7169
}
7270

β€Žhello-nextflow/hello-containers-4.2.nfβ€Ž renamed to β€Žhello-nextflow/containers/scripts/hello-containers-4.2.nfβ€Ž

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ process sayHello {
3131
}
3232

3333
/*
34-
* Use a text replace utility to convert the greeting to uppercase
34+
* Use a cow (or other character) to say some text
3535
*/
3636
process cowSay {
3737

@@ -49,10 +49,13 @@ process cowSay {
4949
"""
5050
}
5151

52+
/*
53+
* Get a quote by author name from the goodreads API
54+
*/
5255
process getQuote {
5356

5457
publishDir 'containers/results', mode: 'copy'
55-
container 'community.wave.seqera.io/library/pip_quote:25b3982790125217'
58+
container 'community.wave.seqera.io/library/pip_quote:ae07804021465ee9'
5659

5760
input:
5861
val author
@@ -64,10 +67,8 @@ process getQuote {
6467
// Replace the spaces in the author with hyphens for the output filename
6568
def safe_author = author.tokenize(' ').join('-')
6669
"""
67-
# The stdout and stderr of the quote command are swapped so we redirect them to the correct files
68-
# Pending fix: https://github.com/maxhumber/quote/issues/12
69-
# quote "$author" > quote-${safe_author}.txt
70-
quote "$author" > /dev/null 2> quote-${safe_author}.txt || true
70+
quote "$author" > quote-${safe_author}.txt
71+
echo "-${author}" >> quote-${safe_author}.txt
7172
"""
7273
}
7374

@@ -80,8 +81,8 @@ workflow {
8081

8182
// create a channel for the text to be processed
8283
if (params.quote) {
83-
quote(input_ch)
84-
text_ch = quote.out
84+
getQuote(input_ch)
85+
text_ch = getQuote.out
8586
} else {
8687
sayHello(input_ch)
8788
text_ch = sayHello.out

β€Žhello-nextflow/hello-containers.nfβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ process sayHello {
3030
}
3131

3232
/*
33-
* Use a text replace utility to convert the greeting to uppercase
33+
* Use a cow (or other character) to say some text
3434
*/
3535
process cowSay {
3636

β€Žhello-nextflow/output.txtβ€Ž

Whitespace-only changes.

0 commit comments

Comments
Β (0)