-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a
batch-create
management command (#1509)
Signed-off-by: tdruez <[email protected]>
- Loading branch information
Showing
10 changed files
with
417 additions
and
29 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -57,6 +57,7 @@ ScanPipe's own commands are listed under the ``[scanpipe]`` section:: | |
add-input | ||
add-pipeline | ||
archive-project | ||
batch-create | ||
check-compliance | ||
create-project | ||
create-user | ||
|
@@ -83,7 +84,8 @@ For example:: | |
$ scanpipe create-project --help | ||
usage: scanpipe create-project [--input-file INPUTS_FILES] | ||
[--input-url INPUT_URLS] [--copy-codebase SOURCE_DIRECTORY] | ||
[--pipeline PIPELINES] [--execute] [--async] | ||
[--pipeline PIPELINES] [--label LABELS] [--notes NOTES] | ||
[--execute] [--async] | ||
name | ||
|
||
Create a ScanPipe project. | ||
|
@@ -124,6 +126,10 @@ Optional arguments: | |
- ``--copy-codebase SOURCE_DIRECTORY`` Copy the content of the provided source directory | ||
into the :guilabel:`codebase/` work directory. | ||
|
||
- ``--notes NOTES`` Optional notes about the project. | ||
|
||
- ``--label LABELS`` Optional labels for the project. | ||
|
||
- ``--execute`` Execute the pipelines right after project creation. | ||
|
||
- ``--async`` Add the pipeline run to the tasks queue for execution by a worker instead | ||
|
@@ -133,6 +139,90 @@ Optional arguments: | |
.. warning:: | ||
Pipelines are added and are executed in order. | ||
|
||
.. _cli_batch_create: | ||
|
||
`$ scanpipe batch-create [--input-directory INPUT_DIRECTORY] [--input-list FILENAME.csv]` | ||
----------------------------------------------------------------------------------------- | ||
|
||
Processes files from the specified ``INPUT_DIRECTORY`` or rows from ``FILENAME.csv``, | ||
creating a project for each file or row. | ||
|
||
- Use ``--input-directory`` to specify a local directory. Each file in the directory | ||
will result in a project, uniquely named using the filename and a timestamp. | ||
|
||
- Use ``--input-list`` to specify a ``FILENAME.csv``. Each row in the CSV will be used | ||
to create a project based on the data provided. | ||
|
||
Supports specifying pipelines and asynchronous execution. | ||
|
||
Required arguments (one of): | ||
|
||
- ``input-directory`` The path to the directory containing the input files to process. | ||
Ensure the directory exists and contains the files you want to use. | ||
|
||
- ``input-list`` Path to a CSV file with project names and input URLs. | ||
The first column must contain project names, and the second column should list | ||
comma-separated input URLs (e.g., Download URL, PURL, or Docker reference). | ||
|
||
**CSV content example**: | ||
|
||
+----------------+---------------------------------+ | ||
| project_name | input_urls | | ||
+================+=================================+ | ||
| project-1 | https://url.com/file.ext | | ||
+----------------+---------------------------------+ | ||
| project-2 | pkg:deb/debian/[email protected] | | ||
+----------------+---------------------------------+ | ||
|
||
Optional arguments: | ||
|
||
- ``--project-name-suffix`` Optional custom suffix to append to project names. | ||
If not provided, a timestamp (in the format [YYMMDD_HHMMSS]) will be used. | ||
|
||
- ``--pipeline PIPELINES`` Pipelines names to add on the project. | ||
|
||
- ``--notes NOTES`` Optional notes about the project. | ||
|
||
- ``--label LABELS`` Optional labels for the project. | ||
|
||
- ``--execute`` Execute the pipelines right after project creation. | ||
|
||
- ``--async`` Add the pipeline run to the tasks queue for execution by a worker instead | ||
of running in the current thread. | ||
Applies only when ``--execute`` is provided. | ||
|
||
Example: Processing Multiple Docker Images | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
Assume multiple Docker images are available in a directory named ``local-data/`` on | ||
the host machine. | ||
To process these images with the ``analyze_docker_image`` pipeline using asynchronous | ||
execution:: | ||
|
||
$ docker compose run --rm \ | ||
--volume local-data/:/input-data:ro \ | ||
web scanpipe batch-create input-data/ \ | ||
--pipeline analyze_docker_image \ | ||
--label "Docker" \ | ||
--execute --async | ||
|
||
**Explanation**: | ||
|
||
- ``local-data/``: A directory on the host machine containing the Docker images to | ||
process. | ||
- ``/input-data/``: The directory inside the container where ``local-data/`` is | ||
mounted (read-only). | ||
- ``--pipeline analyze_docker_image``: Specifies the ``analyze_docker_image`` | ||
pipeline for processing each Docker image. | ||
- ``--label "Docker"``: Tagging all the projects with the "Docker" label to enable | ||
easy search and filtering. | ||
- ``--execute``: Runs the pipeline immediately after creating a project for each | ||
image. | ||
- ``--async``: Adds the pipeline run to the worker queue for asynchronous execution. | ||
|
||
Each Docker image in the ``local-data/`` directory will result in the creation of a | ||
project with the specified pipeline (``analyze_docker_image``) executed by worker | ||
services. | ||
|
||
`$ scanpipe list-pipeline [--verbosity {0,1,2,3}]` | ||
-------------------------------------------------- | ||
|
This file contains 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 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
Oops, something went wrong.