Skip to content

Commit 4d01f00

Browse files
committed
feat: Script to populate miniwdl_singularity_cache with image_manifest.txt. (#236)
1 parent 24c703d commit 4d01f00

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

docs/backend-hpc.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ See [the inputs section of the singleton README](./singleton.md#inputs) for more
4848
miniwdl run workflows/singleton.wdl --input <inputs_json_file>
4949
```
5050
51+
If your compute nodes cannot contact the internet, you can use the script at [`./scripts/populate_miniwdl_singularity_cache.sh`](../scripts/populate_miniwdl_singularity_cache.sh) with the image manifest at [`./image_manifest.txt`](../image_manifest.txt) to populate the miniwdl singularity cache with the required images from a login node with internet access.
52+
5153
#### Running via Cromwell
5254

5355
```bash
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env bash
2+
set -eo pipefail
3+
4+
USAGE="Given a manifest file with docker images, this script populates the Singularity cache with those images.
5+
Usage: $0 <image_manifest_file> <miniwdl_singularity_cache_dir>"
6+
7+
8+
# Check if the first argument is -h or --help
9+
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
10+
echo -e "${USAGE}"
11+
exit 0
12+
fi
13+
# Check if at least two arguments are provided
14+
if [ $# -lt 2 ]; then
15+
echo -e "${USAGE}"
16+
exit 1
17+
fi
18+
19+
image_manifest_file=$1
20+
miniwdl_singularity_cache_dir=$2
21+
# Check if the image manifest file exists and is readable, and if the cache directory exists and is writable
22+
[ -r "${image_manifest_file}" ] || (echo "${image_manifest_file} is not readable." >&2 && exit 1)
23+
if [ ! -d "${miniwdl_singularity_cache_dir}" ]; then
24+
echo "${miniwdl_singularity_cache_dir} does not exist. Creating it now..."
25+
mkdir -p "${miniwdl_singularity_cache_dir}" || (echo "Could not create ${miniwdl_singularity_cache_dir}/." >&2 && exit 1)
26+
fi
27+
[ -w "${miniwdl_singularity_cache_dir}" ] || (echo "${miniwdl_singularity_cache_dir}/ is not writable" >&2 && exit 1)
28+
singularity --version || (echo "singularity is not in path. Please install Singularity to use this script." >&2 && exit 1)
29+
30+
# manifest file should contain one image per line, with no empty lines
31+
# image lines should be in the format: <image_name>:<tag> or <image_name>@sha256:<digest>
32+
# e.g., google/deepvariant:1.9.0 or quay.io/pacbio/some_image@sha256:abc123...
33+
while read -r image; do
34+
if [[ -n "${image}" ]]; then
35+
image_url="docker://${image}"
36+
# miniwdl singularity backend replaces ':' and '/' with '_' in the SIF file name
37+
sif_path="${image_url//:/_}"
38+
sif_path="${sif_path//\//_}"
39+
sif_path="${miniwdl_singularity_cache_dir}/${sif_path}.sif"
40+
if [ -f "${sif_path}" ]; then
41+
echo "Singularity image already exists: ${sif_path}" >&2
42+
else
43+
echo "Pulling Singularity image: ${image_url}"
44+
singularity pull "${sif_path}" "${image_url}"
45+
fi
46+
fi
47+
done < "${image_manifest_file}"

0 commit comments

Comments
 (0)