Skip to content

Commit 0c08540

Browse files
start-example: Running Vulnscout as a user should not require NPM on the host
NPM is only required for devleopment! A user don't need it to run vulnscout. *Changed start-example to start VS with examples with only docker-compose *Changed the yaml examples to not mount the source code (required with NPM) if NPM is not used *Added "docker-npm-overrde.yaml" to mount the source code for NPM dev use. Handled by start-example.sh with "npm-dev" or "npm-build"
1 parent 46ae60f commit 0c08540

File tree

4 files changed

+88
-62
lines changed

4 files changed

+88
-62
lines changed

.vulnscout/docker-npm-override.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# ONLY development with NPM
2+
services:
3+
vulnscout:
4+
volumes:
5+
# You need to mount the source code on actual source code path with "../../src:/scan/src:Z"
6+
- ../../src:/scan/src:Z

.vulnscout/example-spdx3/docker-example-spdx3.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ services:
1010
# Put .spdx.json files in /scan/inputs/spdx
1111
# Put .cdx.json and .cdx.xml files in /scan/inputs/cdx
1212
# Put .json generated from yocto cve-check in /scan/inputs/yocto_cve_check
13-
- ../../src:/scan/src:Z # Mount the source code on actual source code path. Only needed for development if you want to test changes in the source code.
1413
- ../cache:/cache/vulnscout:Z # Cache directory for VulnScout to store the DB EPSS and NVD
1514
- ./output:/scan/outputs:Z
1615
- ./input/core-image-minimal-qemux86-64.rootfs.json:/scan/inputs/yocto_cve_check/core-image-minimal-qemux86-64.rootfs.json:ro,Z

.vulnscout/example/docker-example.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ services:
1111
# Put .cdx.json and .cdx.xml files in /scan/inputs/cdx
1212
# Put .json generated from yocto cve-check in /scan/inputs/yocto_cve_check
1313
# Also accepted .tar, .tar.gz, .tar.zst for all inputs
14-
- ../../src:/scan/src:Z # Mount the source code on actual source code path. Only needed for development if you want to test changes in the source code.
1514
- ../cache:/cache/vulnscout:Z # Cache directory for VulnScout to store the DB EPSS and NVD
1615
- ./output:/scan/outputs:Z
17-
# - ./tmp:/scan/tmp # Debug only
1816
- ./input/example.rootfs.json:/scan/inputs/yocto_cve_check/example.rootfs.json:ro,Z
1917
- ./input/example.rootfs.spdx.tar.zst:/scan/inputs/spdx/example.rootfs.spdx.tar.zst:ro,Z
2018
- ./input/cyclonedx-export:/scan/inputs/cdx:ro,Z

start-example.sh

Lines changed: 82 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,90 @@
44
set -e
55

66
show_help() {
7-
echo "Usage: ./start-example.sh [--dev | --help]"
7+
echo "Usage: ./start-example.sh [--npm-build | --npm-dev] [--spdx3] [--help]"
88
echo ""
99
echo "Options:"
10-
echo " --dev Start frontend in development mode (npm run dev) and backend with Docker Compose"
11-
echo " --spdx3 Use the SPDX-3 example instead of SPDX-2"
12-
echo " --help Show this help message and exit"
10+
echo " --npm-build Build frontend (npm run build) before starting backend"
11+
echo " --npm-dev Start frontend in development mode (npm run dev) and backend with Docker Compose"
12+
echo " --spdx3 Use the SPDX-3 example instead of SPDX-2"
13+
echo " --help Show this help message and exit"
1314
echo ""
1415
echo "Default mode:"
15-
echo " If no arguments are passed, frontend will be built (npm run build) for SPDX2."
16+
echo " If no option is passed, the example will be started for SPDX2."
17+
}
18+
19+
# Function to set up frontend - Only required for development
20+
setup_frontend_devtools() {
21+
local mode=$1
22+
23+
if [[ "$mode" != "dev" && "$mode" != "build" ]]; then
24+
echo "Error: setup_frontend_devtools requires an argument: \"dev\" or \"build\""
25+
exit 1
26+
fi
27+
28+
if ! command -v npm &> /dev/null; then
29+
echo "Error: npm is not installed or not in PATH."
30+
exit 1
31+
fi
32+
33+
# Create the .env file in frontend if it doesn't exist
34+
if [ ! -f frontend/.env ]; then
35+
echo 'VITE_API_URL="http://localhost:7275"' > frontend/.env
36+
fi
37+
38+
# Check if node_modules exists in frontend; if not, run npm install
39+
if [ ! -d frontend/node_modules ]; then
40+
echo "node_modules not found. Running npm install first..."
41+
(cd frontend && npm install)
42+
fi
43+
44+
# Start frontend dev server from within the frontend folder
45+
# Run frontend
46+
if [ "$mode" == "dev" ]; then
47+
echo "Starting frontend in development mode..."
48+
(cd frontend && npm run dev) &
49+
npm_pid=$!
50+
echo "Frontend dev server started (PID $npm_pid)"
51+
52+
# Function to cleanup background process on exit (Ctrl+C)
53+
# Only needed in dev mode because we run npm in the background in dev mode
54+
# In build mode, we just run npm build and exit
55+
cleanup() {
56+
echo -e "\n Stopping frontend dev server (PID $npm_pid)..."
57+
kill -- -$(ps -o pgid= $npm_pid | grep -o '[0-9]*') 2>/dev/null
58+
wait $npm_pid 2>/dev/null
59+
exit 0
60+
}
61+
trap cleanup SIGINT SIGTERM EXIT
62+
63+
sleep 1
64+
else
65+
echo "Building frontend..."
66+
(cd frontend && npm run build)
67+
fi
1668
}
1769

1870
# Default settings
19-
NPM_MODE="build"
71+
NPM_MODE="none"
2072
DOCKER_COMPOSE_FILE=".vulnscout/example/docker-example.yml"
73+
DOCKER_EXTRA_VOLUMES=""
2174

2275
# Parse arguments
2376
for arg in "$@"; do
2477
case "$arg" in
25-
--dev)
78+
--npm-build)
79+
NPM_MODE="build"
80+
if [ "$NPM_MODE" == "dev" ]; then
81+
echo "Error: Cannot use --npm-build and --npm-dev at the same time."
82+
exit 1
83+
fi
84+
;;
85+
--npm-dev)
2686
NPM_MODE="dev"
87+
if [ "$NPM_MODE" == "build" ]; then
88+
echo "Error: Cannot use --npm-build and --npm-dev at the same time."
89+
exit 1
90+
fi
2791
;;
2892
--spdx3)
2993
DOCKER_COMPOSE_FILE=".vulnscout/example-spdx3/docker-example-spdx3.yml"
@@ -40,17 +104,20 @@ for arg in "$@"; do
40104
esac
41105
done
42106

43-
## Check for required tools
44-
if ! command -v npm &> /dev/null; then
45-
echo "Error: npm is not installed or not in PATH."
46-
exit 1
47-
fi
48-
107+
## Check for required docker compose command
49108
if ! command -v docker &> /dev/null; then
50109
echo "Error: Docker is not installed or not in PATH."
51110
exit 1
52111
fi
53112

113+
if [ "$NPM_MODE" == "dev" ]; then
114+
setup_frontend_devtools dev
115+
DOCKER_EXTRA_VOLUMES="-f .vulnscout/docker-npm-override.yml"
116+
elif [ "$NPM_MODE" == "build" ]; then
117+
setup_frontend_devtools build
118+
DOCKER_EXTRA_VOLUMES="-f .vulnscout/docker-npm-override.yml"
119+
fi
120+
54121
if docker compose version &> /dev/null; then
55122
DOCKER_COMPOSE="docker compose"
56123
elif command -v docker-compose &> /dev/null; then
@@ -62,53 +129,9 @@ fi
62129

63130
echo "Docker Compose command found: $DOCKER_COMPOSE"
64131

65-
## Frontend Development Environment Setup Script
66-
67-
# Create the .env file in frontend if it doesn't exist
68-
if [ ! -f frontend/.env ]; then
69-
echo 'VITE_API_URL="http://localhost:7275"' > frontend/.env
70-
fi
71-
72-
# Check if node_modules exists in frontend; if not, run npm install
73-
if [ ! -d frontend/node_modules ]; then
74-
echo "node_modules not found. Running npm install first..."
75-
(cd frontend && npm install)
76-
fi
77-
78-
# Start frontend dev server from within the frontend folder
79-
80-
# Run frontend
81-
if [ "$NPM_MODE" == "dev" ]; then
82-
echo "Starting frontend in development mode..."
83-
(cd frontend && npm run dev) &
84-
npm_pid=$!
85-
echo "Frontend dev server started (PID $npm_pid)"
86-
87-
# Function to cleanup background process on exit (Ctrl+C)
88-
# Only needed in dev mode because we run npm in the background in dev mode
89-
# In build mode, we just run npm build and exit
90-
cleanup() {
91-
echo -e "\n Stopping frontend dev server (PID $npm_pid)..."
92-
kill -- -$(ps -o pgid= $npm_pid | grep -o '[0-9]*') 2>/dev/null
93-
wait $npm_pid 2>/dev/null
94-
exit 0
95-
}
96-
trap cleanup SIGINT SIGTERM EXIT
97-
98-
sleep 1
99-
else
100-
echo "Building frontend..."
101-
(cd frontend && npm run build)
102-
fi
103-
104132
## Backend Development Environment Setup Script
105133
# Close any existing docker-compose processes
106-
docker rm -f vulnscout 2>/dev/null
134+
docker rm -f vulnscout 2>/dev/null || true
107135

108136
# Start docker services
109-
$DOCKER_COMPOSE -f "$DOCKER_COMPOSE_FILE" up
110-
111-
# When docker-compose finishes (or script ends), cleanup npm too if dev mode
112-
if [ "$NPM_MODE" == "dev" ]; then
113-
cleanup
114-
fi
137+
$DOCKER_COMPOSE -f "$DOCKER_COMPOSE_FILE" $DOCKER_EXTRA_VOLUMES up

0 commit comments

Comments
 (0)