-
Notifications
You must be signed in to change notification settings - Fork 825
[anaconda]-auto install vuln pkgs from conda / pip #1079
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
Merged
samruddhikhandale
merged 13 commits into
devcontainers:main
from
gauravsaini04:anaconda_compare_install_vuln_pkgs
Jun 11, 2024
Merged
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
99d0dd7
[anaconda]-auto install vuln pkgs from conda / pip
gauravsaini04 6df631e
Misc change
gauravsaini04 ed3b7c5
for test runs fails
gauravsaini04 b315f49
misc change
gauravsaini04 68971ba
Merge branch 'devcontainers:main' into anaconda_compare_install_vuln_…
gauravsaini04 1a5780a
changes requested
gauravsaini04 11ece68
minor change
gauravsaini04 3143cef
MSG CHANGE
gauravsaini04 9033c15
Merge branch 'devcontainers:main' into anaconda_compare_install_vuln_…
gauravsaini04 fd53e10
Merge branch 'devcontainers:main' into anaconda_compare_install_vuln_…
gauravsaini04 ab8e1d9
changes suggested
gauravsaini04 13aac29
changes acc. to review comments..
gauravsaini04 0b913dd
[anaconda] - changes as requested
gauravsaini04 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| #!/bin/bash | ||
|
|
||
| vulnerable_packages=( "pydantic=2.5.3" "joblib=1.3.1" "mistune=3.0.1" "werkzeug=3.0.3" "transformers=4.36.0" "pillow=10.3.0" "aiohttp=3.9.4" \ | ||
gauravsaini04 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "cryptography=42.0.4" "gitpython=3.1.41" "jupyter-lsp=2.2.2" "idna=3.7" "jinja2=3.1.4" "scrapy=2.11.2" ) | ||
|
|
||
| # Define the number of rows (based on the length of vulnerable_packages) | ||
| rows=${#vulnerable_packages[@]} | ||
|
|
||
| # Define the number of columns | ||
| cols=2 | ||
|
|
||
| # Define the 2D array | ||
| declare -A packages_array | ||
|
|
||
| # Fill the 2D array | ||
| for ((i=0; i<rows; i++)); do | ||
| # Split each element of vulnerable_packages by the '=' sign | ||
| IFS='=' read -ra parts <<< "${vulnerable_packages[$i]}" | ||
| # Assign the parts to the 2D array | ||
| packages_array[$i,0]=${parts[0]} | ||
| packages_array[$i,1]=${parts[1]} | ||
| done | ||
|
|
||
| for ((i=0; i<rows; i++)); do | ||
| CURRENT_VERSION=$(pip show "${packages_array[$i,0]}" | grep '^Version:' | awk '{print $2}') | ||
| if [[ -z "$CURRENT_VERSION" ]]; then | ||
| echo "No version for ${packages_array[$i,0]} found in upstream i.e. base image." | ||
gauravsaini04 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| CURRENT_VERSION="0" | ||
| fi | ||
| REQUIRED_VERSION="${packages_array[$i,1]}" | ||
| GREATER_VERSION_A=$((echo ${REQUIRED_VERSION}; echo ${CURRENT_VERSION}) | sort -V | tail -1) | ||
| # Check if the required_version is greater than current_version | ||
| if [[ $CURRENT_VERSION != $GREATER_VERSION_A ]]; then | ||
| echo "${packages_array[$i,0]} version v${CURRENT_VERSION} installed by the base image is not greater or equal to the required: v${REQUIRED_VERSION}" | ||
| # Check whether conda channel has a greater or equal version available, so install from conda, otherwise use pip package manager | ||
| channel_name="anaconda" | ||
| CONDA_VERSION=$(conda search "${packages_array[$i,0]}" -c "$channel_name" | \ | ||
| grep -E '^[[:alnum:]]' | \ | ||
| awk '{print $2}' | \ | ||
| sort -V | \ | ||
| uniq | \ | ||
| tail -n 2 | \ | ||
| head -n 1) | ||
| if [[ -z "$CONDA_VERSION" ]]; then | ||
| echo "No version for ${packages_array[$i,0]} found in conda channel." | ||
| CONDA_VERSION="0" | ||
| fi | ||
| GREATER_VERSION_B=$((echo ${REQUIRED_VERSION}; echo ${CONDA_VERSION}) | sort -V | tail -1) | ||
| if [[ $CONDA_VERSION == $GREATER_VERSION_B ]]; then | ||
| echo -e "Conda Version: ${CONDA_VERSION} is greater than or equal to the required version: ${REQUIRED_VERSION}. \n"; | ||
gauravsaini04 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| echo "Installing ${packages_array[$i,0]} from source from conda channel for ${REQUIRED_VERSION}..." | ||
| conda install "${packages_array[$i,0]}==${CONDA_VERSION}" | ||
| elif [[ $REQUIRED_VERSION == $GREATER_VERSION_B ]]; then | ||
| echo -e "Required version: ${REQUIRED_VERSION} is greater than the conda version: ${CONDA_VERSION}. \n"; | ||
gauravsaini04 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| echo "Installing ${packages_array[$i,0]} from source from pip package manager for ${REQUIRED_VERSION}..." | ||
| python3 -m pip install --upgrade "${packages_array[$i,0]}==${REQUIRED_VERSION}" | ||
| fi | ||
| fi | ||
gauravsaini04 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| done | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.