Skip to content

Commit d7c3852

Browse files
committed
Moved check_docker_command to utils.py and update the pipelines.rst #1767
Signed-off-by: Chin Yeung Li <tli@nexb.com>
1 parent 016765c commit d7c3852

3 files changed

Lines changed: 26 additions & 4 deletions

File tree

docs/built-in-pipelines.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,12 @@ Scan Maven Package
273273
:members:
274274
:member-order: bysource
275275

276+
Scan Rust Package
277+
-------------------
278+
.. autoclass:: scanpipe.pipelines.scan_rust_package.ScanRustPackage()
279+
:members:
280+
:member-order: bysource
281+
276282
Fetch Scores (addon)
277283
--------------------
278284
.. warning::

scanpipe/pipelines/scan_rust_package.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
# ScanCode.io is a free software code scanning tool from nexB Inc. and others.
2121
# Visit https://github.com/aboutcode-org/scancode.io for support and download.
2222

23-
import shutil
2423
import tempfile
2524
from pathlib import Path
2625

@@ -87,9 +86,11 @@ def collect_input_info(self):
8786
self.collect_input_information()
8887

8988
def check_docker_command(self):
90-
"""Check if the Docker command is available."""
9189
self.have_docker = False
92-
if shutil.which("docker"):
90+
"""Check if the Docker command is available."""
91+
if not utils.check_docker_command():
92+
raise Exception("Docker is required and its daemon must be running.")
93+
else:
9394
self.have_docker = True
9495

9596
def get_cargo_toml(self):

scanpipe/pipes/utils.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@
2323
import hashlib
2424
import logging
2525
import os
26+
import requests
27+
import shutil
28+
import subprocess
29+
2630
from fnmatch import fnmatch
2731
from pathlib import Path
2832
from urllib.parse import urlparse
2933

30-
import requests
3134
from license_expression import Licensing
3235
from packageurl import PackageURL
3336
from packageurl.contrib.purl2url import get_repo_download_url_by_package_type
@@ -519,3 +522,15 @@ def fetch_path(purl):
519522
except (ValueError, requests.RequestException) as e:
520523
logger.warning("Failed to fetch package: %s - %s", purl, e)
521524
return None
525+
526+
def check_docker_command():
527+
"""Check if the Docker command is available and the daemon is running."""
528+
docker_path = shutil.which("docker")
529+
if not docker_path:
530+
return False
531+
532+
try:
533+
subprocess.run([docker_path, "info"], capture_output=True, check=True) # noqa: S603
534+
return True
535+
except (subprocess.SubprocessError, FileNotFoundError):
536+
return False

0 commit comments

Comments
 (0)