Skip to content

Commit 76777db

Browse files
authored
feat: use the pre-built docker image in place of a pip install (#41)
Signed-off-by: tdruez <tdruez@aboutcode.org>
1 parent 6e900c9 commit 76777db

4 files changed

Lines changed: 77 additions & 75 deletions

File tree

.github/workflows/find-vulnerabilities.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ jobs:
2828
- uses: ./
2929
with:
3030
pipelines: "scan_codebase,find_vulnerabilities"
31-
scancodeio-repo-branch: "main"
3231
check-compliance: true
3332
compliance-fail-on-vulnerabilities: true
3433
env:

.github/workflows/multi-runs.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,10 @@ jobs:
3535
project-name: "scan-2"
3636
pipelines: "scan_codebase"
3737

38-
- name: Verify scanpipe and scancode commands availability
38+
- name: Verify scanpipe command availability
3939
shell: bash
4040
run: |
41-
echo "Checking ScanCode CLI availability..."
41+
echo "Checking scanpipe CLI availability..."
4242
which scanpipe || { echo "scanpipe not found in PATH"; exit 1; }
43-
which scancode || { echo "scancode not found in PATH"; exit 1; }
4443
echo "Versions:"
45-
scanpipe shell -c "import scancodeio; from scancode_config import __version__ as scancode_version;print(f'ScanCode.io version: {scancodeio.__version__}');print(f'ScanCode-toolkit version: v{scancode_version}')"
44+
scanpipe --version

.github/workflows/run-android-deploy-to-develop.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ jobs:
2020
sparse-checkout-cone-mode: false
2121
persist-credentials: false
2222

23-
- uses: ./
24-
with:
25-
scancodeio-repo-branch: "main"
26-
scancodeio-extras: "android_analysis"
27-
pipelines: "android_d2d"
28-
input-urls:
29-
https://github.com/aboutcode-org/scancode.io/raw/main/scanpipe/tests/data/d2d/jars/from-flume-ng-node-1.9.0.zip#from
30-
https://github.com/aboutcode-org/scancode.io/raw/main/scanpipe/tests/data/d2d/jars/to-flume-ng-node-1.9.0.zip#to
23+
# scancodeio-extras: "android_analysis" not available with the Docker image for now
24+
# - uses: ./
25+
# with:
26+
# scancodeio-extras: "android_analysis"
27+
# pipelines: "android_d2d"
28+
# input-urls:
29+
# https://github.com/aboutcode-org/scancode.io/raw/main/scanpipe/tests/data/d2d/jars/from-flume-ng-node-1.9.0.zip#from
30+
# https://github.com/aboutcode-org/scancode.io/raw/main/scanpipe/tests/data/d2d/jars/to-flume-ng-node-1.9.0.zip#to

action.yml

Lines changed: 66 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -37,88 +37,90 @@ inputs:
3737
packages and dependencies.
3838
required: false
3939
default: "false"
40-
python-version:
41-
description: "Python version."
42-
default: "3.13"
43-
scancodeio-repo-branch:
44-
description: "Branch to install ScanCode.io from the GitHub repository (optional)"
45-
required: false
46-
default: ""
47-
scancodeio-extras:
48-
description: "ScanCode.io optional dependencies (comma-separated) (optional)."
49-
required: false
50-
default: ""
40+
scancodeio-image:
41+
description: "ScanCode.io Docker image to use."
42+
default: "ghcr.io/aboutcode-org/scancode.io@sha256:6fc8023bc588602ef2ec2b699c2503d8771fe5ef16470475fe64b641f0955f5b" # v37.1.0
5143

5244
runs:
5345
using: "composite"
5446
steps:
55-
- name: Set up Python
56-
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
57-
with:
58-
python-version: ${{ inputs.python-version }}
59-
60-
- name: Set up environment
47+
- name: Validate inputs
6148
shell: bash
6249
env:
50+
INPUT_IMAGE: ${{ inputs.scancodeio-image }}
6351
INPUT_PROJECT_NAME: ${{ inputs.project-name }}
52+
INPUT_FAIL_LEVEL: ${{ inputs.compliance-fail-level }}
53+
INPUT_PIPELINES: ${{ inputs.pipelines }}
6454
run: |
65-
echo "SECRET_KEY=$(openssl rand -base64 32)" >> "$GITHUB_ENV"
66-
echo "SCANCODEIO_DB_NAME=scancodeio" >> "$GITHUB_ENV"
67-
echo "SCANCODEIO_DB_USER=scancodeio" >> "$GITHUB_ENV"
68-
echo "SCANCODEIO_DB_PASSWORD=scancodeio" >> "$GITHUB_ENV"
69-
# Sanitize project name for artifact usage
70-
SAFE_PROJECT_NAME="${INPUT_PROJECT_NAME//[^a-zA-Z0-9._-]/_}"
71-
echo "SAFE_PROJECT_NAME=$SAFE_PROJECT_NAME" >> "$GITHUB_ENV"
55+
# Docker image ref: registry/name:tag or registry/name@sha256:digest
56+
if [[ ! "$INPUT_IMAGE" =~ ^[a-zA-Z0-9./_:@-]+$ ]]; then
57+
echo "::error::Invalid image name: $INPUT_IMAGE"
58+
exit 1
59+
fi
7260
73-
- name: Detect if ScanCode.io is already installed
74-
shell: bash
75-
run: |
76-
if command -v scanpipe &> /dev/null; then
77-
echo "ScanCode.io already installed."
78-
echo "SCANCODEIO_IS_INSTALLED=true" >> "$GITHUB_ENV"
79-
else
80-
echo "ScanCode.io not found."
81-
echo "SCANCODEIO_IS_INSTALLED=false" >> "$GITHUB_ENV"
61+
# Project name: alphanumeric, spaces, hyphens, underscores, dots
62+
if [[ ! "$INPUT_PROJECT_NAME" =~ ^[a-zA-Z0-9[:space:]._-]+$ ]]; then
63+
echo "::error::Invalid project name: $INPUT_PROJECT_NAME"
64+
exit 1
8265
fi
8366
84-
- name: Start and setup the PostgreSQL service
85-
if: env.SCANCODEIO_IS_INSTALLED != 'true'
67+
# Fail level: only known values
68+
if [[ ! "$INPUT_FAIL_LEVEL" =~ ^(ERROR|WARNING|MISSING)$ ]]; then
69+
echo "::error::Invalid compliance-fail-level: $INPUT_FAIL_LEVEL"
70+
exit 1
71+
fi
72+
73+
# Pipeline names: alphanumeric, underscores, commas, colons
74+
if [[ ! "$INPUT_PIPELINES" =~ ^[a-zA-Z0-9_,:[:space:]]+$ ]]; then
75+
echo "::error::Invalid pipelines value: $INPUT_PIPELINES"
76+
exit 1
77+
fi
78+
79+
- name: Set up environment
8680
shell: bash
81+
env:
82+
INPUT_PROJECT_NAME: ${{ inputs.project-name }}
83+
INPUT_IMAGE: ${{ inputs.scancodeio-image }}
8784
run: |
88-
sudo systemctl start postgresql.service
89-
sudo -u postgres createuser --no-createrole --no-superuser --login --inherit --createdb "$SCANCODEIO_DB_USER"
90-
sudo -u postgres psql -c "ALTER USER $SCANCODEIO_DB_USER WITH ENCRYPTED PASSWORD '$SCANCODEIO_DB_PASSWORD'"
91-
sudo -u postgres createdb --owner=scancodeio --encoding=UTF-8 "$SCANCODEIO_DB_NAME"
85+
echo "SECRET_KEY=$(openssl rand -base64 32)" >> "$GITHUB_ENV"
86+
# Workspace location mounted into the container, so outputs are directly accessible
87+
echo "SCANCODEIO_WORKSPACE_LOCATION=/workspace/.scancodeio" >> "$GITHUB_ENV"
88+
echo "SCANCODEIO_IMAGE=$INPUT_IMAGE" >> "$GITHUB_ENV"
89+
# Sanitize project name for artifact usage
90+
echo "SAFE_PROJECT_NAME=${INPUT_PROJECT_NAME//[^a-zA-Z0-9._-]/_}" >> "$GITHUB_ENV"
9291
93-
- name: Generate scancodeio pip install argument
94-
if: env.SCANCODEIO_IS_INSTALLED != 'true'
92+
- name: Start and setup the PostgreSQL service
9593
shell: bash
96-
env:
97-
INPUT_EXTRAS: ${{ inputs.scancodeio-extras }}
9894
run: |
99-
SCANCODEIO_PIP_PACKAGE_ARG="scancodeio"
100-
TRIMMED_EXTRAS="$(echo "$INPUT_EXTRAS" | tr -d '[:space:]')"
101-
if [ -n "$TRIMMED_EXTRAS" ]; then
102-
SCANCODEIO_PIP_PACKAGE_ARG+="[$TRIMMED_EXTRAS]"
95+
if ! sudo systemctl is-active --quiet postgresql; then
96+
sudo systemctl start postgresql.service
97+
sudo -u postgres psql -c "CREATE USER scancodeio WITH CREATEDB ENCRYPTED PASSWORD 'scancodeio';"
98+
sudo -u postgres createdb --owner=scancodeio --encoding=UTF-8 scancodeio
10399
fi
104-
echo "SCANCODEIO_PIP_PACKAGE_ARG=${SCANCODEIO_PIP_PACKAGE_ARG}" >> "$GITHUB_ENV"
105100
106-
- name: Install ScanCode.io (only if not already installed)
107-
if: env.SCANCODEIO_IS_INSTALLED != 'true'
101+
- name: Write scanpipe wrapper script
108102
shell: bash
109-
env:
110-
INPUT_REPO_BRANCH: ${{ inputs.scancodeio-repo-branch }}
111103
run: |
112-
if [ -z "$INPUT_REPO_BRANCH" ]; then
113-
echo "Installing the latest ${SCANCODEIO_PIP_PACKAGE_ARG} release from PyPI"
114-
pip install --upgrade "$SCANCODEIO_PIP_PACKAGE_ARG"
115-
else
116-
echo "Installing ${SCANCODEIO_PIP_PACKAGE_ARG} from the GitHub branch: $INPUT_REPO_BRANCH"
117-
pip install "${SCANCODEIO_PIP_PACKAGE_ARG} @ git+https://github.com/aboutcode-org/scancode.io.git@${INPUT_REPO_BRANCH}"
118-
fi
104+
if [ -f "$RUNNER_TEMP/scanpipe" ]; then exit 0; fi
105+
cat > "$RUNNER_TEMP/scanpipe" << 'EOF'
106+
#!/usr/bin/env bash
107+
set -euo pipefail
108+
exec docker run --rm \
109+
--network host \
110+
--user "$(id -u):$(id -g)" \
111+
--cap-drop ALL \
112+
--security-opt no-new-privileges \
113+
-e SECRET_KEY \
114+
-e SCANCODEIO_WORKSPACE_LOCATION \
115+
-e HOME=/workspace/.home \
116+
-v "$GITHUB_WORKSPACE:/workspace" \
117+
"$SCANCODEIO_IMAGE" \
118+
scanpipe "$@"
119+
EOF
120+
chmod +x "$RUNNER_TEMP/scanpipe"
121+
echo "$RUNNER_TEMP" >> "$GITHUB_PATH"
119122
120123
- name: Run migrations to prepare the database
121-
if: env.SCANCODEIO_IS_INSTALLED != 'true'
122124
shell: bash
123125
run: scanpipe migrate --verbosity 0
124126

@@ -130,6 +132,7 @@ runs:
130132
IFS=',' read -ra PIPELINES <<< "$INPUT_PIPELINES"
131133
PIPELINE_CLI_ARGS=""
132134
for pipeline in "${PIPELINES[@]}"; do
135+
pipeline="$(echo "$pipeline" | tr -d '[:space:]')"
133136
PIPELINE_CLI_ARGS+=" --pipeline $pipeline"
134137
done
135138
echo "PIPELINE_CLI_ARGS=${PIPELINE_CLI_ARGS}" >> "$GITHUB_ENV"
@@ -164,8 +167,9 @@ runs:
164167
INPUT_PROJECT_NAME: ${{ inputs.project-name }}
165168
run: |
166169
project_status=$(scanpipe status --project "$INPUT_PROJECT_NAME")
167-
work_directory=$(echo "$project_status" | grep -oP 'Work directory:\s*\K[^\n]+')
168-
echo "PROJECT_WORK_DIRECTORY=$work_directory" >> "$GITHUB_ENV"
170+
container_work_dir=$(echo "$project_status" | grep -oP 'Work directory:\s*\K[^\n]+')
171+
host_work_dir="$GITHUB_WORKSPACE${container_work_dir#/workspace}"
172+
echo "PROJECT_WORK_DIRECTORY=$host_work_dir" >> "$GITHUB_ENV"
169173
170174
- name: Copy input files to project work directory
171175
if: ${{ !inputs.input-urls }}

0 commit comments

Comments
 (0)