Skip to content

Commit 79f49d8

Browse files
committed
Address review comments
Signed-off-by: Tushar Goel <tushar.goel.dav@gmail.com>
1 parent 28c40ea commit 79f49d8

File tree

3 files changed

+176
-233
lines changed

3 files changed

+176
-233
lines changed

etc/scripts/d2d/README.rst

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
Run ScanCode.io Mapping Script
2+
================================
3+
4+
This script executes the ``map_deploy_to_develop`` mapping workflow from
5+
ScanCode.io inside a Docker container. It optionally spins up a temporary
6+
PostgreSQL instance when needed. The script copies the specified input files to
7+
a working directory, runs the mapping, writes the output to a file, and cleans
8+
up afterward.
9+
10+
Usage
11+
-----
12+
13+
.. code-block:: bash
14+
15+
./run_mapping.sh <from-path> <to-path> [options] <output-file> <spin-db> [db-port]
16+
17+
Arguments
18+
---------
19+
20+
+-----------------+-------------------------------------------------------------+
21+
| Argument | Description |
22+
+=================+=============================================================+
23+
| ``from-path`` | Path to the base deployment/scan file |
24+
+-----------------+-------------------------------------------------------------+
25+
| ``to-path`` | Path to the target deployment/scan file |
26+
+-----------------+-------------------------------------------------------------+
27+
| ``options`` | D2D pipeline parameters (can be empty ``""``) |
28+
+-----------------+-------------------------------------------------------------+
29+
| ``output-file`` | File where ScanCode.io output will be written |
30+
+-----------------+-------------------------------------------------------------+
31+
| ``spin-db`` | ``true`` = spin temp DB container, ``false`` = skip |
32+
+-----------------+-------------------------------------------------------------+
33+
| ``db-port`` | Port to bind Postgres (default: ``5432``) |
34+
+-----------------+-------------------------------------------------------------+
35+
36+
37+
Example
38+
-------
39+
40+
Run mapping without database:
41+
42+
.. code-block:: bash
43+
44+
./run_mapping.sh ./from.tar.gz ./to.whl "" results.txt false
45+
46+
Run mapping with database on a custom port:
47+
48+
.. code-block:: bash
49+
50+
./run_mapping.sh ./from.tar.gz ./to.whl "Python,Java" output.txt true 5555
51+
52+
Script Actions
53+
--------------
54+
55+
1. Validates required arguments
56+
2. Starts PostgreSQL in Docker (if ``spin-db=true``)
57+
3. Creates a temporary working directory: ``./d2d``
58+
4. Copies input files into working directory
59+
5. Runs ScanCode.io mapping step:
60+
61+
.. code-block:: text
62+
63+
run map_deploy_to_develop:<D2D_OPTIONS> \
64+
"/code/<from-file>:from,/code/<to-file>:to"
65+
66+
6. Writes mapping output into ``output-file``
67+
7. Cleans up temp directory
68+
8. Stops DB container if it was started
69+
70+
Dependencies
71+
------------
72+
73+
* Bash
74+
* Docker
75+
* Local filesystem permissions for creating ``./d2d`` and writing output
76+
77+
78+
Before running the script:
79+
----------------------------------
80+
81+
Ensure the script has execute permissions:
82+
83+
.. code-block:: bash
84+
85+
sudo su -
86+
chmod +x run_d2d.sh
87+
88+
Then execute:
89+
90+
.. code-block:: bash
91+
92+
./run_d2d.sh ...

etc/scripts/d2d/run_d2d.sh

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/bin/bash
2+
set -e
3+
4+
FROM_PATH="$1"
5+
TO_PATH="$2"
6+
D2D_OPTIONS="$3"
7+
OUTPUT_FILE="$4"
8+
SPIN_DB="$5"
9+
DB_PORT="$6"
10+
11+
if [ -z "$FROM_PATH" ] || [ -z "$TO_PATH" ] || [ -z "$OUTPUT_FILE" ]; then
12+
echo "Missing required arguments!"
13+
echo "Usage: $0 <from-path> <to-path> [options] <output-file> <spin-db(true|false)> [db-port]"
14+
exit 1
15+
fi
16+
17+
if [ -z "$DB_PORT" ]; then
18+
DB_PORT=5432
19+
fi
20+
21+
echo "Arguments:"
22+
echo "FROM_PATH: $FROM_PATH"
23+
echo "TO_PATH: $TO_PATH"
24+
echo "D2D_OPTIONS: $D2D_OPTIONS"
25+
echo "OUTPUT_FILE: $OUTPUT_FILE"
26+
echo "SPIN_DB: $SPIN_DB"
27+
echo "DB_PORT: $DB_PORT"
28+
29+
DB_STARTED=false
30+
31+
if [ "$SPIN_DB" = "true" ]; then
32+
echo "Starting Postgres container on port $DB_PORT..."
33+
34+
docker run -d \
35+
--name scancodeio-run-db \
36+
-e POSTGRES_DB=scancodeio \
37+
-e POSTGRES_USER=scancodeio \
38+
-e POSTGRES_PASSWORD=scancodeio \
39+
-e POSTGRES_INITDB_ARGS="--encoding=UTF-8 --lc-collate=en_US.UTF-8 --lc-ctype=en_US.UTF-8" \
40+
-v scancodeio_pgdata:/var/lib/postgresql/data \
41+
-p "${DB_PORT}:5432" \
42+
postgres:17 || {
43+
echo "Failed to start DB container. Cleaning up…"
44+
docker rm -f scancodeio-run-db >/dev/null 2>&1 || true
45+
exit 1
46+
}
47+
48+
DB_STARTED=true
49+
echo "DB container started"
50+
fi
51+
52+
WORKDIR="d2d"
53+
mkdir -p "$WORKDIR"
54+
55+
cp "$FROM_PATH" "$WORKDIR/"
56+
cp "$TO_PATH" "$WORKDIR/"
57+
58+
FROM_FILENAME=$(basename "$FROM_PATH")
59+
TO_FILENAME=$(basename "$TO_PATH")
60+
61+
echo "Running ScanCode.io mapping..."
62+
63+
docker run --rm \
64+
-v "$(pwd)/$WORKDIR":/code \
65+
--network host \
66+
-e SCANCODEIO_NO_AUTO_DB=1 \
67+
ghcr.io/aboutcode-org/scancode.io:latest \
68+
run map_deploy_to_develop:"$D2D_OPTIONS" \
69+
"/code/${FROM_FILENAME}:from,/code/${TO_FILENAME}:to" \
70+
> "$OUTPUT_FILE"
71+
72+
echo "Output saved to $OUTPUT_FILE"
73+
74+
75+
rm -rf "$WORKDIR"
76+
echo "Temporary directory cleaned up"
77+
78+
if [ "$DB_STARTED" = true ]; then
79+
echo "Stopping DB container..."
80+
docker rm -f scancodeio-run-db >/dev/null 2>&1 || true
81+
echo "DB container removed"
82+
fi
83+
84+
echo "Done!"

0 commit comments

Comments
 (0)