Skip to content

Commit 679d8b6

Browse files
authored
Rewrite the CLI tutorials for a Docker-based installation #440 (#633)
* Add --print option to the output scanpipe command #440 Signed-off-by: Thomas Druez <tdruez@nexb.com> * Rewrite the Analyze Codebase CLI tutorial for a Docker setup #440 Signed-off-by: Thomas Druez <tdruez@nexb.com> * Rewrite the Analyze Docker Image CLI tutorial for a Docker setup #440 Signed-off-by: Thomas Druez <tdruez@nexb.com>
1 parent e6d4caf commit 679d8b6

15 files changed

Lines changed: 163 additions & 88 deletions

CHANGELOG.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ v33.0.0 (unreleased)
1818
integration in the documentation.
1919
https://github.com/nexB/scancode.io/issues/600
2020

21+
- Rewrite the CLI tutorials for a Docker-based installation.
22+
https://github.com/nexB/scancode.io/issues/440
23+
2124
- Use CodebaseResource ``path`` instead of ``id`` as slug_field in URL navigation.
2225
https://github.com/nexB/scancode.io/issues/242
2326

docs/installation.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ create an **environment file**, and **build the Docker image**::
5353

5454
.. note::
5555
You need to rebuild the image whenever ScanCode.io's source code has been
56-
modified or updated.
56+
modified or updated::
57+
58+
docker compose build
5759

5860
Run the App
5961
^^^^^^^^^^^
@@ -87,7 +89,7 @@ An overview of the web application usage is available at :ref:`user_interface`.
8789
and ``CSRF_TRUSTED_ORIGINS`` settings need to be provided in your ``.env`` file,
8890
for example::
8991

90-
ALLOWED_HOSTS=.your-domain.com,127.0.0.1
92+
ALLOWED_HOSTS=.your-domain.com,localhost,127.0.0.1
9193
CSRF_TRUSTED_ORIGINS=https://*.your-domain.com,http://127.0.0.1:8001
9294

9395
Refer to `ALLOWED_HOSTS settings <https://docs.djangoproject.com/
@@ -288,7 +290,7 @@ you can start the local webserver and access the app with::
288290

289291
make run
290292

291-
Then open your web browser and visit: http://127.0.0.1:8001/ to access the web
293+
Then open your web browser and visit: http://localhost:8001/ to access the web
292294
application.
293295

294296
.. warning::

docs/output-files.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ Output Files
55

66
Whether you use the command line or the web application to run your
77
scans, the generated results are available for review or export in
8-
**JSON** and **Excel (XLSX)** file formats.
8+
**JSON**, **Excel (XLSX)**, **SPDX**, and **CycloneDX** file formats.
99

1010
.. tip::
11-
Check our :ref:`data_model` section for more details about all fields included in the output files.
11+
Check our :ref:`data_model` section for more details about all fields included
12+
in the output files.
1213

1314
Creating Output Files
1415
---------------------
@@ -20,11 +21,11 @@ the output file format with the ``–-format`` option:
2021

2122
.. code-block:: console
2223
23-
$ scanpipe output --project PROJECT --format {json,xlsx}
24+
$ scanpipe output --project PROJECT --format {json,xlsx,spdx,cyclonedx}
2425
2526
.. note::
26-
The previous command will output the scan results in a JSON or XLSX file
27-
format – as specified – with the output files created in the
27+
The previous command will output the scan results in a file format
28+
– as specified – with the output files created in the
2829
``PROJECT``'s :guilabel:`output/` directory. By default, JSON output
2930
files are created when no file format is given.
3031

docs/rest-api.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ REST API
44
========
55

66
To get started with the REST API, visit the **projects' API endpoint** at
7-
http://localhost/api/projects/ or http://127.0.0.1:8001/api/projects/ if you run on a
7+
http://localhost/api/projects/ or http://localhost:8001/api/projects/ if you run on a
88
local development setup.
99

1010
.. _rest_api_authentication:
@@ -316,7 +316,7 @@ the :guilabel:`input/` directory.
316316
Errors
317317
^^^^^^
318318

319-
This action lists all errors that were logged during any pipeline(s) execution
319+
This action lists all errors that were logged during any pipeline execution
320320
on a given ``project``.
321321

322322
``GET /api/projects/6461408c-726c-4b70-aa7a-c9cc9d1c9685/errors/``
@@ -423,11 +423,11 @@ The run details view returns all information available about a pipeline run.
423423
.. code-block:: json
424424
425425
{
426-
"url": "http://127.0.0.1:8001/api/runs/8d5c3962-5fca-47d7-b8c8-47a19247714e/",
426+
"url": "http://localhost/api/runs/8d5c3962-5fca-47d7-b8c8-47a19247714e/",
427427
"pipeline_name": "scan_package",
428428
"status": "success",
429429
"description": "A pipeline to scan a single package archive with ScanCode-toolkit.",
430-
"project": "http://127.0.0.1:8001/api/projects/cd5b0459-303f-4e92-99c4-ea6d0a70193e/",
430+
"project": "http://localhost/api/projects/cd5b0459-303f-4e92-99c4-ea6d0a70193e/",
431431
"uuid": "8d5c3962-5fca-47d7-b8c8-47a19247714e",
432432
"created_date": "2021-10-01T08:44:05.174487+02:00",
433433
"task_exitcode": 0,

docs/tutorial_api_analyze_package_archive.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Using cURL
4040
curl -X POST "$api_url" -H "$content_type" -d "$data"
4141
4242
.. note::
43-
You have to set the api_url to http://127.0.0.1:8001/api/projects/ if you run on a
43+
You have to set the api_url to http://localhost:8001/api/projects/ if you run on a
4444
local development setup.
4545

4646
.. tip::

docs/tutorial_cli_analyze_codebase.rst

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,41 @@ The focus of this tutorial is to guide you through scanning a codebase package
77
using ScanCode.io.
88

99
.. note::
10-
This tutorial assumes you have a current version of ScanCode.io installed
11-
locally on your machine. If you do not have it installed,
12-
see our :ref:`installation` guide for instructions.
10+
This tutorial assumes you have a recent version of ScanCode.io installed
11+
locally on your machine and **running with Docker**.
12+
If you do not have it installed, see our :ref:`installation` guide for instructions.
1313

1414
Requirements
1515
------------
16+
1617
Before you follow the instructions in this tutorial, you need to:
1718

1819
- Install **ScanCode.io** locally
19-
- Download the following **package archive** and save it to your home directory: `asgiref-3.3.0-py3-none-any.whl <https://files.pythonhosted.org/packages/c0/e8/578887011652048c2d273bf98839a11020891917f3aa638a0bc9ac04d653/asgiref-3.3.0-py3-none-any.whl>`_
2020
- Have **Shell access** on the machine where ScanCode.io is installed
2121

2222
Instructions
2323
------------
2424

25-
- Open a shell in the ScanCode.io installation directory and activate the
26-
virtual environment - **virtualenv**:
25+
- Create a new directory in your home directory that will be used to put the input code
26+
to be scanned.
27+
28+
.. code-block:: console
29+
30+
$ mkdir -p ~/codedrop/
31+
32+
- Download the following **package archive** and save it to the :guilabel:`~/codedrop/`
33+
directory: `asgiref-3.3.0-py3-none-any.whl <https://files.pythonhosted.org/packages/c0/e8/578887011652048c2d273bf98839a11020891917f3aa638a0bc9ac04d653/asgiref-3.3.0-py3-none-any.whl>`_
2734

2835
.. code-block:: console
2936
30-
$ source bin/activate
37+
$ curl https://files.pythonhosted.org/packages/c0/e8/578887011652048c2d273bf98839a11020891917f3aa638a0bc9ac04d653/asgiref-3.3.0-py3-none-any.whl --output ~/codedrop/asgiref-3.3.0-py3-none-any.whl
38+
39+
- Create an alias to the ``scanpipe`` command executed through the
40+
``docker compose`` command line interface with:
3141

3242
.. code-block:: console
3343
34-
>> (scancodeio) $
44+
$ alias scanpipe="docker compose -f ${PWD}/docker-compose.yml run --volume ~/codedrop/:/codedrop:ro web scanpipe"
3545
3646
- Create a new project named ``asgiref``:
3747

@@ -41,18 +51,18 @@ Instructions
4151
4252
.. code-block:: console
4353
44-
>> Project asgiref created with work directory projects/asgiref-072c89db
54+
>> Project asgiref created with work directory /var/scancodeio/workspace/projects/asgiref-35519104
4555
4656
- Add the package archive to the project workspace's :guilabel:`input/`
4757
directory:
4858

4959
.. code-block:: bash
5060
51-
$ scanpipe add-input --project asgiref --input-file ~/asgiref-3.3.0-py3-none-any.whl
61+
$ scanpipe add-input --project asgiref --input-file /codedrop/asgiref-3.3.0-py3-none-any.whl
5262
5363
.. code-block:: console
5464
55-
>> File(s) copied to the project inputs directory:
65+
>> File copied to the project inputs directory:
5666
- asgiref-3.3.0-py3-none-any.whl
5767
5868
- Add the ``scan_codebase`` pipeline to your project:
@@ -63,7 +73,7 @@ Instructions
6373
6474
.. code-block:: console
6575
66-
>> Pipeline(s) added to the project
76+
>> Pipeline scan_codebase added to the project
6777
6878
.. note::
6979
The content of the :guilabel:`input/` directory will be copied in the
@@ -83,26 +93,38 @@ Instructions
8393
.. code-block:: console
8494
8595
>> Pipeline scan_codebase run in progress..
86-
2021-07-12 17:45:53.85 Pipeline [scan_codebase] starting
87-
2021-07-12 17:45:53.85 Step [copy_inputs_to_codebase_directory] starting
88-
2021-07-12 17:45:53.86 Step [copy_inputs_to_codebase_directory] completed in 0.00 seconds
89-
2021-07-12 17:45:53.86 Step [extract_archives] starting
96+
Pipeline [scan_codebase] starting
97+
Step [copy_inputs_to_codebase_directory] starting
98+
Step [copy_inputs_to_codebase_directory] completed in 0.00 seconds
99+
Step [extract_archives] starting
90100
[...]
91-
2021-07-12 17:46:01.61 Pipeline completed
101+
Pipeline completed
102+
scan_codebase successfully executed on project asgiref
92103
93-
- Finally, you can view your scan results in JSON or CSV file formats inside
94-
the project's :guilabel:`output/` directory.
104+
- Finally, export the scan results as JSON format::
105+
106+
$ scanpipe output --project asgiref --format json --print > asgiref-3.3.0_results.json
95107

96108
.. tip::
97109
The ``inputs`` and ``pipelines`` can be provided at the same time when
98110
calling the ``create-project`` command. For instance, the following command
99-
will create a new project named ``asgiref``, add the package archive as the
111+
will create a new project named ``asgiref2``, add the package archive as the
100112
project input, add the ``scan_codebase`` pipeline to the project, and
101113
execute it:
102114

103115
.. code-block:: bash
104116
105-
$ scanpipe create-project asgiref \
106-
--input-file ~/asgiref-3.3.0-py3-none-any.whl \
117+
$ scanpipe create-project asgiref2 \
118+
--input-file /codedrop/asgiref-3.3.0-py3-none-any.whl \
107119
--pipeline scan_codebase \
108120
--execute
121+
122+
.. code-block:: console
123+
124+
>> Project asgiref2 created with work directory /var/scancodeio/workspace/projects/asgiref2-bea7a5e9
125+
File copied to the project inputs directory:
126+
- asgiref-3.3.0-py3-none-any.whl
127+
Start the scan_codebase pipeline execution...
128+
[...]
129+
Pipeline completed
130+
scan_codebase successfully executed on project asgiref2

docs/tutorial_cli_analyze_docker_image.rst

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,42 @@ a test Docker image by following the steps below and, along the way,
88
learn some of the ScanCode.io basic commands.
99

1010
.. note::
11-
This tutorial assumes you have a current version of ScanCode.io installed
12-
locally on your machine. If you do not have it installed,
13-
see our :ref:`installation` guide for instructions.
11+
This tutorial assumes you have a recent version of ScanCode.io installed
12+
locally on your machine and **running with Docker**.
13+
If you do not have it installed, see our :ref:`installation` guide for instructions.
1414

1515
Requirements
1616
------------
1717

1818
To successfully complete this tutorial, you first need to:
1919

2020
- Install **ScanCode.io** locally
21-
- Download the following **test Docker image** and save it to your home directory: `30-alpine-nickolashkraus-staticbox-latest.tar <https://github.com/nexB/scancode.io-tutorial/releases/download/sample-images/30-alpine-nickolashkraus-staticbox-latest.tar>`_
2221
- Have **Shell access** on the machine where ScanCode.io is installed
2322

2423
Instructions
2524
------------
2625

27-
- Open a shell in the ScanCode.io installation directory and activate the
28-
virtual environment - **virtualenv**:
26+
- Create a new directory in your home directory that will be used to put the input code
27+
to be scanned.
2928

3029
.. code-block:: console
3130
32-
$ source bin/activate
31+
$ mkdir -p ~/codedrop/
32+
33+
- Download the following **test Docker image** and save it to the :guilabel:`~/codedrop/`
34+
directory: `30-alpine-nickolashkraus-staticbox-latest.tar
35+
<https://github.com/nexB/scancode.io-tutorial/releases/download/sample-images/30-alpine-nickolashkraus-staticbox-latest.tar>`_
36+
37+
.. code-block:: console
38+
39+
$ curl https://github.com/nexB/scancode.io-tutorial/releases/download/sample-images/30-alpine-nickolashkraus-staticbox-latest.tar --output ~/codedrop/30-alpine-nickolashkraus-staticbox-latest.tar
40+
41+
- Create an alias to the ``scanpipe`` command executed through the
42+
``docker compose`` command line interface with:
3343

3444
.. code-block:: console
3545
36-
>> (scancodeio) $
46+
$ alias scanpipe="docker compose -f ${PWD}/docker-compose.yml run --volume ~/codedrop/:/codedrop:ro web scanpipe"
3747
3848
- Create a new project named ``staticbox``:
3949

@@ -43,30 +53,29 @@ Instructions
4353
4454
.. code-block:: console
4555
46-
>> Project staticbox created with work directory projects/staticbox-d4ed9405
56+
>> Project staticbox created with work directory /var/scancodeio/workspace/projects/staticbox-d4ed9405
4757
4858
.. note::
4959
New projects work directory are created inside the location defined in
5060
:ref:`scancodeio_settings_workspace_location` setting.
51-
Default to a :guilabel:`var/` directory in the local ScanCode.io codebase.
61+
Default to the :guilabel:`/var/scancodeio/workspace/` directory.
5262

5363
- Add the test Docker image tarball to the project workspace's :guilabel:`input/`
5464
directory:
5565

5666
.. code-block:: bash
5767
5868
$ scanpipe add-input --project staticbox \
59-
--input-file ~/30-alpine-nickolashkraus-staticbox-latest.tar
69+
--input-file /codedrop/30-alpine-nickolashkraus-staticbox-latest.tar
6070
6171
.. code-block:: console
6272
63-
>> File(s) copied to the project inputs directory:
73+
>> File copied to the project inputs directory:
6474
- 30-alpine-nickolashkraus-staticbox-latest.tar
6575
6676
.. note::
6777
The command output will let you know that the Docker image file was
6878
copied to the project's :guilabel:`input/` directory.
69-
You can also navigate to this directory and confirm your file is there.
7079
Alternatively, you can copy files manually to the :guilabel:`input/`
7180
directory to include entire directories.
7281

@@ -78,7 +87,7 @@ Instructions
7887
7988
.. code-block:: console
8089
81-
>> Pipeline(s) added to the project
90+
>> Pipeline docker added to the project
8291
8392
- Check the status of the pipeline added to your project:
8493

@@ -107,12 +116,13 @@ Instructions
107116
.. code-block:: console
108117
109118
>> Pipeline docker run in progress...
110-
2021-07-07 10:39:26.49 Pipeline [docker] starting
111-
2021-07-07 10:39:26.53 Step [extract_images] starting
112-
2021-07-07 10:39:26.71 Step [extract_images] completed in 0.18 seconds
113-
2021-07-07 10:39:26.71 Step [extract_layers] starting
119+
Pipeline [docker] starting
120+
Step [extract_images] starting
121+
Step [extract_images] completed in 0.18 seconds
122+
Step [extract_layers] starting
114123
[...]
115-
2021-07-07 10:39:31.39 Pipeline completed
124+
Pipeline completed
125+
docker successfully executed on project staticbox
116126
117127
- Executing the ``show-pipeline`` command again will also confirm the success
118128
of the pipeline execution - **"[SUCCESS] docker"** status:
@@ -129,14 +139,10 @@ Instructions
129139

130140
.. code-block:: console
131141
132-
$ scanpipe output --project staticbox --format json
133-
134-
.. code-block:: console
135-
136-
>> projects/staticbox-d4ed9405/output/results-2021-07-07-08-54-02.json
142+
$ scanpipe output --project staticbox --format json --print > staticbox_results.json
137143
138-
- Finally, open the ``output/results-<timestamp>.json`` file in your preferred
139-
text editor/file viewer.
144+
- Finally, open the ``staticbox_results.json`` file in your preferred text
145+
editor/file viewer.
140146

141147
.. note::
142148
To understand the output of the pipeline execution, see our :ref:`output_files`
@@ -145,15 +151,15 @@ Instructions
145151
.. tip::
146152
The ``inputs`` and ``pipelines`` can be provided directly at once when
147153
calling the ``create-project`` command.
148-
An ``execute`` option is also available to start the pipeline execution right
154+
The ``--execute`` option is also available to start the pipeline execution right
149155
after the project creation.
150156
For example, the following command will create a project named ``staticbox2``,
151157
download the test Docker image to the project's :guilabel:`input/`
152158
directory, add the docker pipeline, and execute the pipeline in one operation:
153159

154160
.. code-block:: bash
155161
156-
$ scanpipe create-project staticbox2 \
157-
--input-url https://github.com/nexB/scancode.io-tutorial/releases/download/sample-images/30-alpine-nickolashkraus-staticbox-latest.tar \
158-
--pipeline docker \
159-
--execute
162+
$ scanpipe create-project staticbox2 \
163+
--input-url https://github.com/nexB/scancode.io-tutorial/releases/download/sample-images/30-alpine-nickolashkraus-staticbox-latest.tar \
164+
--pipeline docker \
165+
--execute

docs/tutorial_vulnerablecode_integration.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,3 @@ Open any of your existing projects containing a few detected packages.
6060
- Click red bug icon to reach the vulnerability details for this package:
6161

6262
.. image:: images/tutorial-find-vulnerabilities-extra-data.png
63-
64-
.. tip::
65-
Refer to the complementary :ref:`tutorial_web_ui_review_scan_results` page, to
66-
understand this tutorial's scan results/output.

0 commit comments

Comments
 (0)