-
Notifications
You must be signed in to change notification settings - Fork 218
Add container load scripts for Docker and Podman (#3634 follow up) #3706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
JulianFlesch
merged 22 commits into
nf-core:dev
from
ErikDanielsson:container-load-scripts
Aug 28, 2025
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
d201f0a
Add container load scripts for Docker and Podman
ErikDanielsson e6827ef
[automated] Update CHANGELOG.md
nf-core-bot 1d7f48e
Update tests
ErikDanielsson 488b7b4
Merge branch 'download-refactor-again' into container-load-scripts
ErikDanielsson 510f566
Create download test folder and move util tests
ErikDanielsson 1a765c4
Move singularity and docker tests
ErikDanielsson 29529ca
Move tests from utils to correct class
ErikDanielsson 7dede8a
Update comments
ErikDanielsson c7495de
Merge branch 'refactor-download-tests' into container-load-scripts
ErikDanielsson 6215f95
Fix typo
ErikDanielsson fd6a38f
Merge branch 'download-refactor-again' into refactor-download-tests
ErikDanielsson 44cc2b3
Merge branch 'refactor-download-tests' into container-load-scripts
ErikDanielsson 35a2ad1
Merge branch 'download-refactor-again' into refactor-download-tests
ErikDanielsson ff681f7
Fix test
ErikDanielsson e662c2c
Merge branch 'download-refactor-again' into refactor-download-tests
ErikDanielsson 3b187b4
Merge branch 'refactor-download-tests' into container-load-scripts
ErikDanielsson cb318b2
Merge branch 'dev' into container-load-scripts
JulianFlesch 441a5ec
fix: Remove use of 'jq' for REPO_TAG extraction, which may not be ins…
JulianFlesch 7702073
impr: Fail if docker daemon is not running
JulianFlesch 350555a
impr: Fail if no podman installation is found or no podman machine is…
JulianFlesch 239953e
impr: Fail if docker cmd not found
JulianFlesch 1fa9c0d
Merge branch 'dev' into container-load-scripts
JulianFlesch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail # Ensure that the script exits as early as possible | ||
|
|
||
| LOGFILE="podman-load.log" | ||
|
|
||
| # Clear log | ||
| > "$LOGFILE" | ||
|
|
||
| if ! command -v docker &> /dev/null | ||
| then | ||
| echo "Error: Docker is not installed. Please install it to continue." >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| if ! docker info &> /dev/null; then | ||
| echo "Error: Docker daemon is not running." >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Loading tar archives into docker" | ||
| for tarfile in $(ls -1 *.tar); do | ||
| if output=$(docker load -i $tarfile); then | ||
| echo "SUCCESS: $tarfile" | ||
| echo "SUCCESS: $tarfile" >> "$LOGFILE" | ||
| echo $output >> "$LOGFILE" | ||
| echo "----------------------------------------------------------------" >> "$LOGFILE" | ||
| else | ||
| echo "ERROR: $tarfile" | ||
| echo "ERROR: $tarfile" >> "$LOGFILE" | ||
| echo $output >> "$LOGFILE" | ||
| echo "----------------------------------------------------------------" >> "$LOGFILE" | ||
| fi | ||
| done | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail # Ensure that the script exits as early as possible | ||
|
|
||
| LOGFILE="podman-load.log" | ||
|
|
||
| # Clear log | ||
| > "$LOGFILE" | ||
|
|
||
JulianFlesch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if ! command -v podman &> /dev/null | ||
| then | ||
| echo "Error: Podman is not installed. Please install it to continue." >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| if ! podman info &> /dev/null; then | ||
| echo "Error: No Podman machine is ready. Make sure it's installed and configured." >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| PODMAN_LOAD_SINGLE_IMAGE() { | ||
| local TARFILE="$1" | ||
|
|
||
| # Look for the full image name in the mainfest.json | ||
| # inside the image tar archive. It is contained in | ||
| # this RepoTags field | ||
| REPO_TAG=$(tar -O -xf "$TARFILE" manifest.json | python -c 'import json, sys; print(json.load(sys.stdin)[0]["RepoTags"][0])') | ||
|
|
||
| if [[ -z "$REPO_TAG" || "$REPO_TAG" == "null" ]]; then | ||
| echo "Error: Could not find RepoTags in $TARFILE" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Load the tar archive into podman -- this will typically | ||
| # save it as localhost/..., which won't work if we want to | ||
| # use the images in the nf-core pipeline | ||
| PODMAN_LOAD_OUTPUT=$(podman load -i "$TARFILE" 2>&1) | ||
|
|
||
| # Extract the tag podman created for the image for later renaming | ||
| LOCAL_TAG=$(echo "$PODMAN_LOAD_OUTPUT" | sed -n 's/^Loaded image(s): \(.*\)$/\1/p') | ||
|
|
||
| if [[ -z "$LOCAL_TAG" ]]; then | ||
| echo "Error: Could not parse loaded image name from podman load output" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Tag the loaded image with the original remote name | ||
| podman tag "$LOCAL_TAG" "$REPO_TAG" | ||
|
|
||
| echo "Success, loaded and tagged: $REPO_TAG" | ||
| } | ||
|
|
||
| echo "Loading tar archives into podman" | ||
| for tarfile in $(ls -1 *.tar); do | ||
| if output=$(PODMAN_LOAD_SINGLE_IMAGE $tarfile); then | ||
| echo "SUCCESS: $tarfile" | ||
| echo "SUCCESS: $tarfile" >> "$LOGFILE" | ||
| echo $output >> "$LOGFILE" | ||
| echo "----------------------------------------------------------------" >> "$LOGFILE" | ||
| else | ||
| echo "ERROR: $tarfile" | ||
| echo "ERROR: $tarfile" >> "$LOGFILE" | ||
| echo $output >> "$LOGFILE" | ||
| echo "----------------------------------------------------------------" >> "$LOGFILE" | ||
| fi | ||
| done | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| """Tests for the download subcommand of nf-core tools""" | ||
|
|
||
| import unittest | ||
|
|
||
| import pytest | ||
| import rich.progress_bar | ||
| import rich.table | ||
| import rich.text | ||
|
|
||
| from nf_core.pipelines.download.container_fetcher import ContainerProgress | ||
|
|
||
|
|
||
| class ContainerProgressTest(unittest.TestCase): | ||
| @pytest.fixture(autouse=True) | ||
| def use_caplog(self, caplog): | ||
| self._caplog = caplog | ||
|
|
||
| # | ||
| # Test for 'utils..add/update_main_task' | ||
| # | ||
| def test_download_progress_main_task(self): | ||
| with ContainerProgress() as progress: | ||
| # No task initially | ||
| assert progress.tasks == [] | ||
|
|
||
| # Add a task, it should be there | ||
| task_id = progress.add_main_task(total=42) | ||
| assert task_id == 0 | ||
| assert len(progress.tasks) == 1 | ||
| assert progress.task_ids[0] == task_id | ||
| assert progress.tasks[0].total == 42 | ||
|
|
||
| # Add another task, there should now be two | ||
| other_task_id = progress.add_task("Another task", total=28) | ||
| assert other_task_id == 1 | ||
| assert len(progress.tasks) == 2 | ||
| assert progress.task_ids[1] == other_task_id | ||
| assert progress.tasks[1].total == 28 | ||
|
|
||
| progress.update_main_task(total=35) | ||
| assert progress.tasks[0].total == 35 | ||
| assert progress.tasks[1].total == 28 | ||
|
|
||
| # | ||
| # Test for 'utils.DownloadProgress.sub_task' | ||
| # | ||
| def test_download_progress_sub_task(self): | ||
| with ContainerProgress() as progress: | ||
| # No task initially | ||
| assert progress.tasks == [] | ||
|
|
||
| # Add a sub-task, it should be there | ||
| with progress.sub_task("Sub-task", total=42) as sub_task_id: | ||
| assert sub_task_id == 0 | ||
| assert len(progress.tasks) == 1 | ||
| assert progress.task_ids[0] == sub_task_id | ||
| assert progress.tasks[0].total == 42 | ||
|
|
||
| # The sub-task should be gone now | ||
| assert progress.tasks == [] | ||
|
|
||
| # Add another sub-task, this time that raises an exception | ||
| with pytest.raises(ValueError): | ||
| with progress.sub_task("Sub-task", total=28) as sub_task_id: | ||
| assert sub_task_id == 1 | ||
| assert len(progress.tasks) == 1 | ||
| assert progress.task_ids[0] == sub_task_id | ||
| assert progress.tasks[0].total == 28 | ||
| raise ValueError("This is a test error") | ||
|
|
||
| # The sub-task should also be gone now | ||
| assert progress.tasks == [] | ||
|
|
||
| # | ||
| # Test for 'utils.DownloadProgress.get_renderables' | ||
| # | ||
| def test_download_progress_renderables(self): | ||
| # Test the "summary" progress type | ||
| with ContainerProgress() as progress: | ||
| assert progress.tasks == [] | ||
| progress.add_task("Task 1", progress_type="summary", total=42, completed=11) | ||
| assert len(progress.tasks) == 1 | ||
|
|
||
| renderable = progress.get_renderable() | ||
| assert isinstance(renderable, rich.console.Group), type(renderable) | ||
|
|
||
| assert len(renderable.renderables) == 1 | ||
| table = renderable.renderables[0] | ||
| assert isinstance(table, rich.table.Table) | ||
|
|
||
| assert isinstance(table.columns[0]._cells[0], str) | ||
| assert table.columns[0]._cells[0] == "[magenta]Task 1" | ||
|
|
||
| assert isinstance(table.columns[1]._cells[0], rich.progress_bar.ProgressBar) | ||
| assert table.columns[1]._cells[0].completed == 11 | ||
| assert table.columns[1]._cells[0].total == 42 | ||
|
|
||
| assert isinstance(table.columns[2]._cells[0], str) | ||
| assert table.columns[2]._cells[0] == "[progress.percentage] 26%" | ||
|
|
||
| assert isinstance(table.columns[3]._cells[0], str) | ||
| assert table.columns[3]._cells[0] == "•" | ||
|
|
||
| assert isinstance(table.columns[4]._cells[0], str) | ||
| assert table.columns[4]._cells[0] == "[green]11/42 tasks completed" | ||
|
|
||
|
|
||
| class ContainerTest(unittest.TestCase): | ||
| @pytest.fixture(autouse=True) | ||
| def use_caplog(self, caplog): | ||
| self._caplog = caplog | ||
|
|
||
| @property | ||
| def logged_levels(self) -> list[str]: | ||
| return [record.levelname for record in self._caplog.records] | ||
|
|
||
| @property | ||
| def logged_messages(self) -> list[str]: | ||
| return [record.message for record in self._caplog.records] | ||
|
|
||
| def __contains__(self, item: str) -> bool: | ||
| """Allows to check for log messages easily using the in operator inside a test: | ||
| assert 'my log message' in self | ||
| """ | ||
| return any(record.message == item for record in self._caplog.records if self._caplog) | ||
|
|
||
| pass |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.