Skip to content

Commit af54c6c

Browse files
authored
add apptainer workflow scripts (#43)
* add apptainer workflow scripts * temporarily build container on test branch * remove running workflow on test branch once container has been built * add apptainer profile and bump version * correct container reference * add missing parentheses around profile
1 parent b5951ed commit af54c6c

File tree

6 files changed

+139
-1
lines changed

6 files changed

+139
-1
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
mkdir -p artifacts
3+
mkdir -p wave_images
4+
5+
for env_yaml in environments/*.yml; do
6+
image_name=$(head -n 1 $env_yaml | cut -d ' ' -f 2)
7+
echo "building image ${image_name} from file ${env_yaml}..."
8+
wave \
9+
--conda-file ${env_yaml} \
10+
--singularity \
11+
--freeze \
12+
--await \
13+
--output json \
14+
| python -m json.tool \
15+
| tee wave_images/${image_name}.json
16+
echo "done building image ${image_name}"
17+
cp wave_images/${image_name}.json artifacts/
18+
done
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
set -eo pipefail
3+
wget https://raw.githubusercontent.com/apptainer/apptainer/main/tools/install-unprivileged.sh
4+
chmod +x install-unprivileged.sh
5+
mkdir -p /opt/apptainer
6+
./install-unprivileged.sh /opt/apptainer
7+
echo "/opt/apptainer/bin" >> $GITHUB_PATH
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
set -eo pipefail
3+
wget https://github.com/seqeralabs/wave-cli/releases/download/v1.4.1/wave-1.4.1-linux-x86_64
4+
mv wave-1.4.1-linux-x86_64 wave
5+
chmod +x wave
6+
mkdir -p /opt/wave/bin
7+
mv wave /opt/wave/bin
8+
echo "/opt/wave/bin" >> $GITHUB_PATH
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env python
2+
3+
import argparse
4+
import glob
5+
import json
6+
import os
7+
import subprocess
8+
9+
10+
def pull_image(image_url, destination_image_file):
11+
"""
12+
Pull the image file from external server
13+
"""
14+
apptainer_pull_cmd = [
15+
"apptainer",
16+
"pull",
17+
destination_image_file,
18+
image_url,
19+
]
20+
subprocess.run(apptainer_pull_cmd)
21+
22+
23+
def push_image(source_image_file, image_url):
24+
"""
25+
Push apptainer image to destination image repository
26+
"""
27+
28+
apptainer_push_cmd = [
29+
"apptainer",
30+
"push",
31+
source_image_file,
32+
image_url,
33+
]
34+
subprocess.run(apptainer_push_cmd)
35+
36+
37+
def main(args):
38+
repo_owner = os.environ['GITHUB_REPOSITORY_OWNER'].lower()
39+
40+
wave_jsons = glob.glob(os.path.join(args.wave_jsons_dir, "*.json"))
41+
for wave_json in wave_jsons:
42+
with open(wave_json, 'r') as f:
43+
w = json.load(f)
44+
pull_image_url = w['containerImage']
45+
image_name_with_version = pull_image_url.split('/')[-1]
46+
image_name, image_version = image_name_with_version.split(':')
47+
pull_destination = os.path.join(args.images_dir, f"{image_name}--{image_version}.img")
48+
pull_image(pull_image_url, pull_destination)
49+
50+
push_image_url = f"oras://ghcr.io/{repo_owner}/{image_name}:{image_version}"
51+
push_image(pull_destination, push_image_url)
52+
53+
54+
if __name__ == '__main__':
55+
parser = argparse.ArgumentParser()
56+
parser.add_argument('--wave-jsons-dir')
57+
parser.add_argument('--images-dir')
58+
args = parser.parse_args()
59+
main(args)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Build and Push Container Images
2+
3+
on:
4+
push:
5+
tags:
6+
- v*
7+
workflow_dispatch:
8+
9+
env:
10+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
11+
GHCR_USERNAME: ${{ secrets.GHCR_USERNAME }}
12+
13+
jobs:
14+
build_and_push:
15+
runs-on: ubuntu-latest
16+
permissions:
17+
packages: write
18+
contents: read
19+
steps:
20+
- uses: actions/checkout@v4
21+
- name: Install Apptainer
22+
run: |
23+
.github/scripts/install_apptainer.sh
24+
- name: Check Apptainer installation
25+
run: apptainer --version
26+
- name: Install Wave CLI
27+
run: |
28+
.github/scripts/install_wave-cli.sh
29+
- name: Check wave installation
30+
run: wave --version
31+
- name: Build images
32+
run: |
33+
.github/scripts/build_container_images_wave.sh
34+
- name: Push images
35+
run: |
36+
echo ${GITHUB_TOKEN} | apptainer registry login -u ${GHCR_USERNAME} --password-stdin oras://ghcr.io
37+
.github/scripts/push_container_images_wave.py --wave-jsons-dir wave_images --images-dir wave_images

nextflow.config

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ manifest {
44
description = 'Alignment and variant calling pipeline'
55
mainScript = 'main.nf'
66
nextflowVersion = '>=20.01.0'
7-
version = '0.1.13'
7+
version = '0.1.14'
88
}
99

1010
params {
@@ -72,6 +72,14 @@ profiles {
7272
conda.cacheDir = params.cache
7373
}
7474
}
75+
76+
apptainer {
77+
apptainer.enabled = true
78+
process.container = "oras://ghcr.io/bccdc-phl/alignment-variants:775751a430ea765a"
79+
if (params.cache){
80+
apptainer.cacheDir = params.cache
81+
}
82+
}
7583
}
7684

7785
process {
@@ -87,5 +95,6 @@ process {
8795
}
8896
withName: plot_coverage {
8997
conda = "$baseDir/environments/plot_coverage.yml"
98+
container = "oras://ghcr.io/bccdc-phl/alignment-variants-plot-coverage:e9de1da959e4e7e7"
9099
}
91100
}

0 commit comments

Comments
 (0)