Skip to content

Commit 54b9bf3

Browse files
authored
add: nextflow module (#416)
1 parent cb990bb commit 54b9bf3

File tree

4 files changed

+183
-0
lines changed

4 files changed

+183
-0
lines changed

.icons/nextflow.svg

Lines changed: 6 additions & 0 deletions
Loading
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
display_name: Nextflow
3+
description: A module that adds Nextflow to your Coder template.
4+
icon: ../../../../.icons/nextflow.svg
5+
verified: true
6+
tags: [nextflow, workflow, hpc, bioinformatics]
7+
---
8+
9+
# Nextflow
10+
11+
A module that adds Nextflow to your Coder template.
12+
13+
![Nextflow](../../.images/nextflow.png)
14+
15+
```tf
16+
module "nextflow" {
17+
count = data.coder_workspace.me.start_count
18+
source = "registry.coder.com/coder-labs/nextflow/coder"
19+
version = "0.9.0"
20+
agent_id = coder_agent.example.id
21+
}
22+
```
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
terraform {
2+
required_version = ">= 1.0"
3+
4+
required_providers {
5+
coder = {
6+
source = "coder/coder"
7+
version = ">= 2.5"
8+
}
9+
}
10+
}
11+
12+
# Add required variables for your modules and remove any unneeded variables
13+
variable "agent_id" {
14+
type = string
15+
description = "The ID of a Coder agent."
16+
}
17+
18+
variable "nextflow_version" {
19+
type = string
20+
description = "Nextflow version"
21+
default = "25.04.7"
22+
}
23+
24+
variable "project_path" {
25+
type = string
26+
description = "The path to Nextflow project, it will be mounted in the container."
27+
}
28+
29+
variable "http_server_port" {
30+
type = number
31+
description = "The port to run HTTP server on."
32+
default = 9876
33+
}
34+
35+
variable "http_server_reports_dir" {
36+
type = string
37+
description = "Subdirectory for HTTP server reports, relative to the project path."
38+
default = "reports"
39+
}
40+
41+
variable "http_server_log_path" {
42+
type = string
43+
description = "HTTP server logs"
44+
default = "/tmp/nextflow_reports.log"
45+
}
46+
47+
variable "stub_run" {
48+
type = bool
49+
description = "Execute a stub run?"
50+
default = false
51+
}
52+
53+
variable "stub_run_command" {
54+
type = string
55+
description = "Nextflow command to be executed in the stub run."
56+
default = "run rnaseq-nf -with-report reports/report.html -with-trace reports/trace.txt -with-timeline reports/timeline.html -with-dag reports/flowchart.png"
57+
}
58+
59+
variable "order" {
60+
type = number
61+
description = "The order determines the position of app in the UI presentation. The lowest order is shown first and apps with equal order are sorted by name (ascending order)."
62+
default = null
63+
}
64+
65+
variable "share" {
66+
type = string
67+
default = "owner"
68+
validation {
69+
condition = var.share == "owner" || var.share == "authenticated" || var.share == "public"
70+
error_message = "Incorrect value. Please set either 'owner', 'authenticated', or 'public'."
71+
}
72+
}
73+
74+
variable "group" {
75+
type = string
76+
description = "The name of a group that this app belongs to."
77+
default = null
78+
}
79+
80+
resource "coder_script" "nextflow" {
81+
agent_id = var.agent_id
82+
display_name = "nextflow"
83+
icon = "/icon/nextflow.svg"
84+
script = templatefile("${path.module}/run.sh", {
85+
NEXTFLOW_VERSION : var.nextflow_version,
86+
PROJECT_PATH : var.project_path,
87+
HTTP_SERVER_PORT : var.http_server_port,
88+
HTTP_SERVER_REPORTS_DIR : var.http_server_reports_dir,
89+
HTTP_SERVER_LOG_PATH : var.http_server_log_path,
90+
STUB_RUN : var.stub_run,
91+
STUB_RUN_COMMAND : var.stub_run_command,
92+
})
93+
run_on_start = true
94+
}
95+
96+
resource "coder_app" "nextflow" {
97+
agent_id = var.agent_id
98+
slug = "nextflow-reports"
99+
display_name = "Nextflow Reports"
100+
url = "http://localhost:${var.http_server_port}"
101+
icon = "/icon/nextflow.svg"
102+
subdomain = true
103+
share = var.share
104+
order = var.order
105+
group = var.group
106+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env sh
2+
3+
set -eu
4+
5+
BOLD='\033[0;1m'
6+
RESET='\033[0m'
7+
8+
printf "$${BOLD}Starting Nextflow...$${RESET}\n"
9+
10+
if ! command -v nextflow > /dev/null 2>&1; then
11+
# Update system dependencies
12+
sudo apt update
13+
sudo apt install openjdk-21-jdk graphviz salmon fastqc multiqc -y
14+
15+
# Install nextflow
16+
export NXF_VER=${NEXTFLOW_VERSION}
17+
curl -s https://get.nextflow.io | bash
18+
sudo mv nextflow /usr/local/bin/
19+
sudo chmod +x /usr/local/bin/nextflow
20+
21+
# Verify installation
22+
tmp_verify=$(mktemp -d coder-nextflow-XXXXXX)
23+
nextflow run hello \
24+
-with-report "$${tmp_verify}/report.html" \
25+
-with-trace "$${tmp_verify}/trace.txt" \
26+
-with-timeline "$${tmp_verify}/timeline.html" \
27+
-with-dag "$${tmp_verify}/flowchart.png"
28+
rm -r "$${tmp_verify}"
29+
else
30+
echo "Nextflow is already installed\n\n"
31+
fi
32+
33+
if [ ! -z ${PROJECT_PATH} ]; then
34+
# Project is located at PROJECT_PATH
35+
echo "Change directory: ${PROJECT_PATH}"
36+
cd ${PROJECT_PATH}
37+
fi
38+
39+
# Start a web server to preview reports
40+
mkdir -p ${HTTP_SERVER_REPORTS_DIR}
41+
echo "Starting HTTP server in background, check logs: ${HTTP_SERVER_LOG_PATH}"
42+
python3 -m http.server --directory ${HTTP_SERVER_REPORTS_DIR} ${HTTP_SERVER_PORT} > "${HTTP_SERVER_LOG_PATH}" 2>&1 &
43+
44+
# Stub run?
45+
if [ "${STUB_RUN}" = "true" ]; then
46+
nextflow ${STUB_RUN_COMMAND} -stub-run
47+
fi
48+
49+
printf "\n$${BOLD}Nextflow ${NEXTFLOW_VERSION} is ready. HTTP server is listening on port ${HTTP_SERVER_PORT}$${RESET}\n"

0 commit comments

Comments
 (0)