-
Notifications
You must be signed in to change notification settings - Fork 4.5k
chore: Adding step for install #37276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -21,6 +21,69 @@ GITHUB_PR_LINK="$3" | |||||||||||||||||||
| GITHUB_RUN_ID="$4" | ||||||||||||||||||||
| OLD_VULN_FILE="${5:-vulnerability_base_data.csv}" | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Function to install Docker Scout | ||||||||||||||||||||
| install_docker_scout() { | ||||||||||||||||||||
| echo "Installing Docker Scout..." | ||||||||||||||||||||
| local attempts=0 | ||||||||||||||||||||
| while [ $attempts -lt 5 ]; do | ||||||||||||||||||||
| echo "Attempt $((attempts + 1))..." | ||||||||||||||||||||
| curl -fsSL https://raw.githubusercontent.com/docker/scout-cli/main/install.sh -o install-scout.sh | ||||||||||||||||||||
| sh install-scout.sh &> install_scout_log.txt | ||||||||||||||||||||
| if [ $? -eq 0 ]; then | ||||||||||||||||||||
| echo "Docker Scout installed successfully." | ||||||||||||||||||||
| return 0 | ||||||||||||||||||||
| fi | ||||||||||||||||||||
| echo "Attempt $((attempts + 1)) failed. Check install_scout_log.txt for details." | ||||||||||||||||||||
| ((attempts++)) | ||||||||||||||||||||
| sleep 2 | ||||||||||||||||||||
| done | ||||||||||||||||||||
| echo "Error: Docker Scout installation failed after $attempts attempts." | ||||||||||||||||||||
| exit 1 | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Check if Docker is installed | ||||||||||||||||||||
| if ! command -v docker &> /dev/null; then | ||||||||||||||||||||
| echo "Error: Docker is not installed. Please install Docker and try again." | ||||||||||||||||||||
| exit 1 | ||||||||||||||||||||
| fi | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Ensure Docker is running | ||||||||||||||||||||
| if ! systemctl is-active --quiet docker; then | ||||||||||||||||||||
| echo "Starting Docker..." | ||||||||||||||||||||
| sudo systemctl start docker | ||||||||||||||||||||
| fi | ||||||||||||||||||||
|
Comment on lines
+51
to
+54
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Avoid using 'sudo' within scripts; handle Docker daemon status appropriately Using Apply this diff: if ! systemctl is-active --quiet docker; then
echo "Docker is not running. Please start Docker and try again."
exit 1
fi📝 Committable suggestion
Suggested change
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| # Check if Docker Scout is installed | ||||||||||||||||||||
| if ! command -v scout &> /dev/null; then | ||||||||||||||||||||
| install_docker_scout | ||||||||||||||||||||
| fi | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Prepare the output CSV file | ||||||||||||||||||||
| CSV_OUTPUT_FILE="scout_vulnerabilities.csv" | ||||||||||||||||||||
| rm -f "$CSV_OUTPUT_FILE" | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Extract the product name from the image name | ||||||||||||||||||||
| case "$IMAGE" in | ||||||||||||||||||||
| *appsmith/appsmith-ce:*) product_name="CE" ;; | ||||||||||||||||||||
| *appsmith/appsmith-ee:*) product_name="EE" ;; | ||||||||||||||||||||
| *appsmith/cloud-services:*) product_name="CLOUD" ;; | ||||||||||||||||||||
| *) product_name="UNKNOWN" ;; | ||||||||||||||||||||
| esac | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Fetch vulnerabilities and format the output correctly | ||||||||||||||||||||
| docker scout cves "$IMAGE" | grep -E "✗ |CVE-" | awk -v product_name="$product_name" -F' ' ' | ||||||||||||||||||||
| { | ||||||||||||||||||||
| # Check for valid vulnerability data and format it correctly | ||||||||||||||||||||
| if ($2 != "" && $3 ~ /^CVE-/) { | ||||||||||||||||||||
| # Extract severity level, CVE ID, and format output correctly | ||||||||||||||||||||
| print $3","product_name",""SCOUT"","$2 | ||||||||||||||||||||
| } | ||||||||||||||||||||
| }' | sort -u > "$CSV_OUTPUT_FILE" | ||||||||||||||||||||
|
Comment on lines
+74
to
+81
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Use structured output for reliable parsing of vulnerabilities Parsing command-line output is fragile. If available, use JSON output from Example adjustment: -docker scout cves "$IMAGE" | grep -E "✗ |CVE-" | awk -v product_name="$product_name" -F' ' '
-{
- if ($2 != "" && $3 ~ /^CVE-/) {
- print $3","product_name",""SCOUT"","$2
- }
-}' | sort -u > "$CSV_OUTPUT_FILE"
+docker scout cves "$IMAGE" --output json | jq -r '.vulnerabilities[] | "\(.identifiers.CVE[0]),'"$product_name"',SCOUT,\(.severity)"' | sort -u > "$CSV_OUTPUT_FILE"📝 Committable suggestion
Suggested change
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| # Check if the CSV output file is empty | ||||||||||||||||||||
| [ -s "$CSV_OUTPUT_FILE" ] || echo "No vulnerabilities found for image: $IMAGE" > "$CSV_OUTPUT_FILE" | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
Comment on lines
+84
to
+85
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid writing messages into CSV output files Writing non-CSV messages into the CSV file can break downstream processing. Handle the case separately without altering the CSV file. Apply this diff: # Check if the CSV output file is empty
-[ -s "$CSV_OUTPUT_FILE" ] || echo "No vulnerabilities found for image: $IMAGE" > "$CSV_OUTPUT_FILE"
+if [ ! -s "$CSV_OUTPUT_FILE" ]; then
+ echo "No vulnerabilities found for image: $IMAGE"
+fi📝 Committable suggestion
Suggested change
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| # Compare each vulnerability with the database and store new ones in a CSV file | ||||||||||||||||||||
| compare_and_store_vulns() { | ||||||||||||||||||||
| local new_vulns_file="scout_new_vulnerabilities.csv" | ||||||||||||||||||||
|
|
@@ -68,4 +131,4 @@ if [ -s "$CSV_OUTPUT_FILE" ]; then | |||||||||||||||||||
| compare_and_store_vulns | ||||||||||||||||||||
| else | ||||||||||||||||||||
| echo "No vulnerabilities to process." | ||||||||||||||||||||
| fi | ||||||||||||||||||||
| fi | ||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Verify 'curl' command success before executing the installation script
Ensure that the 'curl' command successfully downloads the installation script before executing it to prevent errors from incomplete downloads.
Apply this diff to add an error check:
📝 Committable suggestion