Skip to content

Commit f30a167

Browse files
CopilotKaniska244
andauthored
Ensure pinned protobuf persists after conda updates in smoke test (#1785)
* Initial plan * Pin protobuf to required version Co-authored-by: Kaniska244 <186041440+Kaniska244@users.noreply.github.com> * Reapply pinned pip packages after conda installs Co-authored-by: Kaniska244 <186041440+Kaniska244@users.noreply.github.com> * Cache required versions for pinned packages Co-authored-by: Kaniska244 <186041440+Kaniska244@users.noreply.github.com> * Defer pinned installs until after conda updates Co-authored-by: Kaniska244 <186041440+Kaniska244@users.noreply.github.com> * Fix version comparisons and clarify pin reapply Co-authored-by: Kaniska244 <186041440+Kaniska244@users.noreply.github.com> * Clarify pinned package reinstall comment Co-authored-by: Kaniska244 <186041440+Kaniska244@users.noreply.github.com> * Expand pinned package reinstall comment Co-authored-by: Kaniska244 <186041440+Kaniska244@users.noreply.github.com> * Align comment terminology for pin list Co-authored-by: Kaniska244 <186041440+Kaniska244@users.noreply.github.com> * Refine pin list comment wording Co-authored-by: Kaniska244 <186041440+Kaniska244@users.noreply.github.com> * Clarify pin list timing in comment Co-authored-by: Kaniska244 <186041440+Kaniska244@users.noreply.github.com> * Quote associative array subscripts Co-authored-by: Kaniska244 <186041440+Kaniska244@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Kaniska244 <186041440+Kaniska244@users.noreply.github.com>
1 parent 80a8f70 commit f30a167

File tree

3 files changed

+37
-22
lines changed

3 files changed

+37
-22
lines changed

src/anaconda/.devcontainer/apply_security_patches.sh

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,21 @@ cols=2
1414

1515
# Define the 2D array
1616
declare -A packages_array
17+
declare -A required_versions
1718

1819
# Fill the 2D array
1920
for ((i=0; i<rows; i++)); do
2021
# Split each element of vulnerable_packages by the '=' sign
2122
IFS='=' read -ra parts <<< "${vulnerable_packages[$i]}"
2223
# Assign the parts to the 2D array
23-
packages_array[$i,0]=${parts[0]}
24-
packages_array[$i,1]=${parts[1]}
24+
packages_array["$i,0"]="${parts[0]}"
25+
packages_array["$i,1"]="${parts[1]}"
26+
required_versions["${parts[0]}"]="${parts[1]}"
2527
done
2628

2729
# Add an array for packages that should always pin to the provided version,
2830
# even if higher version is available in conda channel
29-
pin_to_required_version=("transformers" "imagecodecs" "brotli")
31+
pin_to_required_version=("transformers" "imagecodecs" "brotli" "protobuf")
3032

3133
# Function to check if a package is in the pin_to_required_version array
3234
function is_pin_to_required_version() {
@@ -40,38 +42,51 @@ function is_pin_to_required_version() {
4042
}
4143

4244
for ((i=0; i<rows; i++)); do
43-
CURRENT_VERSION=$(pip show "${packages_array[$i,0]}" --disable-pip-version-check | grep '^Version:' | awk '{print $2}')
44-
REQUIRED_VERSION="${packages_array[$i,1]}"
45-
GREATER_VERSION_A=$((echo ${REQUIRED_VERSION}; echo ${CURRENT_VERSION}) | sort -V | tail -1)
45+
CURRENT_VERSION=$(pip show "${packages_array["$i,0"]}" --disable-pip-version-check | grep '^Version:' | awk '{print $2}')
46+
REQUIRED_VERSION="${packages_array["$i,1"]}"
47+
if is_pin_to_required_version "${packages_array["$i,0"]}"; then
48+
continue
49+
fi
50+
GREATER_VERSION_A=$( (echo ${REQUIRED_VERSION}; echo ${CURRENT_VERSION}) | sort -V | tail -1)
4651
# Check if the required_version is greater than current_version
4752
if [[ $CURRENT_VERSION != $GREATER_VERSION_A ]]; then
48-
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}"
53+
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}"
4954
# Check whether conda channel has a greater or equal version available, so install from conda, otherwise use pip package manager
5055
channel_name="anaconda"
51-
CONDA_VERSION=$(conda search "${packages_array[$i,0]}" -c "$channel_name" | \
56+
CONDA_VERSION=$(conda search "${packages_array["$i,0"]}" -c "$channel_name" | \
5257
grep -E '^[[:alnum:]]' | \
5358
awk '{print $2}' | \
5459
sort -V | \
5560
uniq | \
5661
tail -n 2 | \
5762
head -n 1)
5863
if [[ -z "$CONDA_VERSION" ]]; then
59-
echo "No version for ${packages_array[$i,0]} found in conda channel."
64+
echo "No version for ${packages_array["$i,0"]} found in conda channel."
6065
CONDA_VERSION="0"
6166
fi
62-
GREATER_VERSION_B=$((echo ${REQUIRED_VERSION}; echo ${CONDA_VERSION}) | sort -V | tail -1)
63-
if is_pin_to_required_version "${packages_array[$i,0]}"; then
64-
echo -e "Package ${packages_array[$i,0]} is set to always use the required version: v${REQUIRED_VERSION}.\n";
65-
echo "Installing ${packages_array[$i,0]} from pip for v${REQUIRED_VERSION}..."
66-
python3 -m pip install --upgrade --no-cache-dir "${packages_array[$i,0]}==${REQUIRED_VERSION}"
67-
elif [[ $CONDA_VERSION == $GREATER_VERSION_B ]]; then
67+
GREATER_VERSION_B=$( (echo ${REQUIRED_VERSION}; echo ${CONDA_VERSION}) | sort -V | tail -1)
68+
if [[ $CONDA_VERSION == $GREATER_VERSION_B ]]; then
6869
echo -e "Found Version v${CONDA_VERSION} in the Conda channel which is greater than or equal to the required version: v${REQUIRED_VERSION}. \n";
69-
echo "Installing ${packages_array[$i,0]} from source from conda channel for v${REQUIRED_VERSION}..."
70-
conda install "${packages_array[$i,0]}==${CONDA_VERSION}"
70+
echo "Installing ${packages_array["$i,0"]} from source from conda channel for v${REQUIRED_VERSION}..."
71+
conda install "${packages_array["$i,0"]}==${CONDA_VERSION}"
7172
elif [[ $REQUIRED_VERSION == $GREATER_VERSION_B ]]; then
7273
echo -e "Required version: v${REQUIRED_VERSION} is greater than the version found in the Conda channel v${CONDA_VERSION}. \n";
73-
echo "Installing ${packages_array[$i,0]} from source from pip package manager for v${REQUIRED_VERSION}..."
74-
python3 -m pip install --upgrade --no-cache-dir "${packages_array[$i,0]}==${REQUIRED_VERSION}"
74+
echo "Installing ${packages_array["$i,0"]} from source from pip package manager for v${REQUIRED_VERSION}..."
75+
python3 -m pip install --upgrade --no-cache-dir "${packages_array["$i,0"]}==${REQUIRED_VERSION}"
7576
fi
7677
fi
7778
done
79+
80+
# After the main upgrade loop, install packages from the pin_to_required_version list at their required versions to keep exact versions even if conda upgrades them as dependencies.
81+
for pkg in "${pin_to_required_version[@]}"; do
82+
REQUIRED_VERSION="${required_versions["$pkg"]}"
83+
if [[ -z "${REQUIRED_VERSION}" ]]; then
84+
echo "WARNING: Missing required version for ${pkg}. Skipping installation."
85+
continue
86+
fi
87+
CURRENT_VERSION=$(pip show "${pkg}" --disable-pip-version-check | grep '^Version:' | awk '{print $2}')
88+
if [[ "${CURRENT_VERSION}" != "${REQUIRED_VERSION}" ]]; then
89+
echo "Installing ${pkg} from pip for v${REQUIRED_VERSION}..."
90+
python3 -m pip install --upgrade --no-cache-dir "${pkg}==${REQUIRED_VERSION}"
91+
fi
92+
done

src/anaconda/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ You can decide how often you want updates by referencing a [semantic version](ht
3030

3131
- `mcr.microsoft.com/devcontainers/anaconda:1-3`
3232
- `mcr.microsoft.com/devcontainers/anaconda:1.3-3`
33-
- `mcr.microsoft.com/devcontainers/anaconda:1.3.10-3`
33+
- `mcr.microsoft.com/devcontainers/anaconda:1.3.11-3`
3434

3535
See [history](history) for information on the contents of each version and [here for a complete list of available tags](https://mcr.microsoft.com/v2/devcontainers/anaconda/tags/list).
3636

src/anaconda/manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "1.3.10",
2+
"version": "1.3.11",
33
"build": {
44
"latest": true,
55
"rootDistro": "debian",
@@ -67,4 +67,4 @@
6767
}
6868
}
6969
}
70-
}
70+
}

0 commit comments

Comments
 (0)