Skip to content

Commit 2ad4d82

Browse files
authored
add apptainer workflow scripts (#25)
* add apptainer workflow scripts * temp add branch to build container workflow * add space * add apptainer profiler and bump pipeline version * remove temp branch after initial container build * test if adding matplotlib resolves gubbins no locator issue * specify version of gubbins with numba issue fixed - see issue #396 on nickjcroucher/gubbins * update gubbins to v3.4.3 to fix suspected numba issue - see #397 on nickjcroucher/gubbins * test different gubbins version * test gubbins v3.3.5 * test downgrading python env * revert env changes and pin gubbins to current version used in production * revert all environment testing changes * update container environment path and add fix for gubbins numba runtime no locator issue
1 parent 87ba9a9 commit 2ad4d82

File tree

6 files changed

+145
-1
lines changed

6 files changed

+145
-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: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Build and Push Container Images
2+
3+
on:
4+
push:
5+
branches:
6+
- add-apptainer-support
7+
tags:
8+
- v*
9+
workflow_dispatch:
10+
11+
env:
12+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
13+
GHCR_USERNAME: ${{ secrets.GHCR_USERNAME }}
14+
15+
jobs:
16+
build_and_push:
17+
runs-on: ubuntu-latest
18+
permissions:
19+
packages: write
20+
contents: read
21+
steps:
22+
- uses: actions/checkout@v4
23+
- name: Install Apptainer
24+
run: |
25+
.github/scripts/install_apptainer.sh
26+
- name: Check Apptainer installation
27+
run: apptainer --version
28+
- name: Install Wave CLI
29+
run: |
30+
.github/scripts/install_wave-cli.sh
31+
- name: Check wave installation
32+
run: wave --version
33+
- name: Build images
34+
run: |
35+
.github/scripts/build_container_images_wave.sh
36+
- name: Push images
37+
run: |
38+
echo ${GITHUB_TOKEN} | apptainer registry login -u ${GHCR_USERNAME} --password-stdin oras://ghcr.io
39+
.github/scripts/push_container_images_wave.py --wave-jsons-dir wave_images --images-dir wave_images

nextflow.config

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ manifest {
22
name = "BCCDC-PHL/snippy-core-phylogenomics"
33
mainScript = 'main.nf'
44
nextflowVersion = '>=20.01.0'
5-
version= '0.1.3'
5+
version= '0.1.4'
66
}
77

88
params {
@@ -20,6 +20,19 @@ profiles {
2020
conda.cacheDir = params.cache
2121
}
2222
}
23+
24+
apptainer {
25+
apptainer.enabled = true
26+
process.container = "oras://ghcr.io/bccdc-phl/snippy-core-phylogenomics:de9ad98e64844f89"
27+
if (params.cache){
28+
apptainer.cacheDir = params.cache
29+
}
30+
}
31+
}
32+
33+
env {
34+
// solution for following gubbins/numba container issue: https://github.com/DOH-JDJ0303/bigbacter-nf/issues/7
35+
NXF_APPTAINER_HOME_MOUNT = 'true'
2336
}
2437

2538
process {

0 commit comments

Comments
 (0)