Skip to content

Commit f9491a8

Browse files
Merge pull request savoirfairelinux#60 from ValentinBoudevin/fix/remove-npm-requirements
Fix/NPM issue with default Ubuntu version provided with pip install + NPM should NOT be mandotry for testing
2 parents fac61e8 + 3c522e0 commit f9491a8

File tree

5 files changed

+73
-62
lines changed

5 files changed

+73
-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

README_DEV.adoc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,25 @@
22

33
This document provides guidelines for developers working on the vulnscout project, including setup, testing, and code quality practices.
44

5+
== Requirements
6+
7+
NVM 22 is required to develop on vulnscout without any issues.
8+
Installation guide for NVM : https://github.com/nvm-sh/nvm
9+
10+
[source,bash]
11+
----
12+
nvm install 22
13+
nvm use 22
14+
----
15+
516
== Modify the frontend
617

718
To modify the frontend, you will need to run vulnscout in development mode.
819
To do so, you can run the following command:
920

1021
[source,bash]
1122
----
12-
./start-example.sh --dev
23+
./start-example.sh --npm-dev
1324
----
1425

1526
== Testing the project

start-example.sh

Lines changed: 55 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,62 @@
44
set -e
55

66
show_help() {
7-
echo "Usage: ./start-example.sh [--dev | --help]"
7+
echo "Usage: ./start-example.sh [--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 " --dev Start frontend in development mode (npm run dev) and mount volume on src/ for the backend"
11+
echo " --spdx3 Use the SPDX-3 example instead of SPDX-2"
12+
echo " --help Show this help message and exit"
1313
echo ""
1414
echo "Default mode:"
15-
echo " If no arguments are passed, frontend will be built (npm run build) for SPDX2."
15+
echo " If no option is passed, the example will be started for SPDX2."
16+
}
17+
18+
# Function to set up frontend - Only required for development
19+
setup_devtools() {
20+
21+
# Check if npm is installed
22+
if ! command -v npm &> /dev/null; then
23+
echo "Error: npm is not installed or not in PATH."
24+
exit 1
25+
fi
26+
27+
# Create the .env file in frontend if it doesn't exist
28+
if [ ! -f frontend/.env ]; then
29+
echo 'VITE_API_URL="http://localhost:7275"' > frontend/.env
30+
fi
31+
32+
# Check if node_modules exists in frontend; if not, run npm install
33+
if [ ! -d frontend/node_modules ]; then
34+
echo "node_modules not found. Running npm install first..."
35+
(cd frontend && npm install)
36+
fi
37+
38+
# Start frontend dev server from within the frontend folder
39+
echo "Starting frontend in development mode..."
40+
(cd frontend && npm run dev) &
41+
npm_pid=$!
42+
echo "Frontend dev server started (PID $npm_pid)"
43+
44+
# Function to cleanup background process on exit (Ctrl+C)
45+
cleanup() {
46+
echo -e "\n Stopping frontend dev server (PID $npm_pid)..."
47+
kill -- -$(ps -o pgid= $npm_pid | grep -o '[0-9]*') 2>/dev/null
48+
wait $npm_pid 2>/dev/null
49+
exit 0
50+
}
51+
trap cleanup SIGINT SIGTERM EXIT
52+
53+
sleep 1
54+
55+
# Modify the docker-compose file to mount the backend src/ directory in addition
56+
DOCKER_EXTRA_VOLUMES="-f .vulnscout/docker-npm-override.yml"
1657
}
1758

1859
# Default settings
19-
NPM_MODE="build"
60+
NPM_MODE="none"
2061
DOCKER_COMPOSE_FILE=".vulnscout/example/docker-example.yml"
62+
DOCKER_EXTRA_VOLUMES=""
2163

2264
# Parse arguments
2365
for arg in "$@"; do
@@ -40,17 +82,16 @@ for arg in "$@"; do
4082
esac
4183
done
4284

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-
85+
## Check for required docker compose command
4986
if ! command -v docker &> /dev/null; then
5087
echo "Error: Docker is not installed or not in PATH."
5188
exit 1
5289
fi
5390

91+
if [ "$NPM_MODE" == "dev" ]; then
92+
setup_devtools
93+
fi
94+
5495
if docker compose version &> /dev/null; then
5596
DOCKER_COMPOSE="docker compose"
5697
elif command -v docker-compose &> /dev/null; then
@@ -62,53 +103,9 @@ fi
62103

63104
echo "Docker Compose command found: $DOCKER_COMPOSE"
64105

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-
104106
## Backend Development Environment Setup Script
105107
# Close any existing docker-compose processes
106-
docker rm -f vulnscout 2>/dev/null
108+
docker rm -f vulnscout 2>/dev/null || true
107109

108110
# 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
111+
$DOCKER_COMPOSE -f "$DOCKER_COMPOSE_FILE" $DOCKER_EXTRA_VOLUMES up

0 commit comments

Comments
 (0)