Skip to content

Commit 34f1910

Browse files
authored
fix aws setup for ibm smoke tests (#392)
# Summary **Python environment and version management:** - The `ensure_required_python` function in `recreate_python_venv.sh` now installs a specific, pinned Python version (`3.13.7` by default) for consistency across runs, instead of installing the latest version in a major/minor series. It also removes redundant logic and streamlines the installation process. - The script now checks for and installs the `python3-venv` package on Debian/Ubuntu systems before attempting to set up Python with pyenv, improving compatibility on those platforms. **Virtual environment activation and AWS CLI setup:** - The AWS CLI installation script (`setup_aws.sh`) has been updated to require and activate the Python venv before installing AWS CLI with pip, ensuring all installations are isolated and reproducible. It also verifies AWS CLI functionality within the venv and reinstalls if necessary. - The container authentication configuration script (`configure_container_auth.sh`) now automatically activates the venv if it exists, which is necessary for AWS CLI usage on IBM architectures. ## Proof of Work - green ci - [smoke test run](https://spruce.mongodb.com/version/68b57f84a001500007f90609/tasks?sorts=STATUS%3AASC%3BBASE_STATUS%3ADESC) (the test failure is because staging doesn't work - so the images are not build on multi-arch but aws setup is working as shown there. It has been re-run to show it works on the same machine multiple times) ## Checklist - [ ] Have you linked a jira ticket and/or is the ticket in the title? - [ ] Have you checked whether your jira ticket required DOCSP changes? - [ ] Have you added changelog file? - use `skip-changelog` label if not needed - refer to [Changelog files and Release Notes](https://github.com/mongodb/mongodb-kubernetes/blob/master/CONTRIBUTING.md#changelog-files-and-release-notes) section in CONTRIBUTING.md for more details
1 parent 1c5f517 commit 34f1910

File tree

3 files changed

+37
-40
lines changed

3 files changed

+37
-40
lines changed

scripts/dev/configure_container_auth.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ source scripts/funcs/checks
88
source scripts/funcs/printing
99
source scripts/funcs/kubernetes
1010

11+
# Activate venv if it exists (needed for AWS CLI on IBM architectures)
12+
if [[ -f "${PROJECT_DIR}/venv/bin/activate" ]]; then
13+
source "${PROJECT_DIR}/venv/bin/activate"
14+
fi
15+
1116
CONTAINER_RUNTIME="${CONTAINER_RUNTIME-"docker"}"
1217

1318
setup_validate_container_runtime() {

scripts/dev/recreate_python_venv.sh

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ set -Eeou pipefail
77
source scripts/dev/set_env_context.sh
88

99
install_pyenv() {
10+
# Install python3-venv package for Debian/Ubuntu systems if needed
11+
if command -v apt-get &> /dev/null; then
12+
echo "Installing python3-venv package for venv support..." >&2
13+
sudo apt-get update -qq || true
14+
sudo apt-get install -y python3-venv || true
15+
fi
16+
1017
# Check if pyenv directory exists first
1118
if [[ -d "${HOME}/.pyenv" ]]; then
1219
echo "pyenv directory already exists, setting up environment..." >&2
@@ -54,38 +61,22 @@ install_pyenv() {
5461
}
5562

5663
ensure_required_python() {
57-
local required_version="${PYTHON_VERSION:-3.13}"
58-
local major_minor
59-
major_minor=$(echo "${required_version}" | grep -oE '^[0-9]+\.[0-9]+')
64+
local required_version="${PYTHON_VERSION:-3.13.7}"
6065

61-
echo "Setting up Python ${required_version} (${major_minor}.x)..." >&2
66+
echo "Setting up Python ${required_version}..." >&2
6267

63-
# Always install pyenv first
6468
if ! install_pyenv; then
6569
echo "Error: Failed to install pyenv" >&2
6670
return 1
6771
fi
6872

69-
# Install latest version in the required series
70-
local latest_version
71-
latest_version=$(pyenv install --list | grep -E "^[[:space:]]*${major_minor}\.[0-9]+$" | tail -1 | xargs)
72-
if [[ -n "${latest_version}" ]]; then
73-
echo "Installing Python ${latest_version} via pyenv..." >&2
74-
# Use --skip-existing to avoid errors if version already exists
75-
if pyenv install --skip-existing "${latest_version}"; then
76-
pyenv global "${latest_version}"
77-
# Install python3-venv package for Debian/Ubuntu systems if needed
78-
if command -v apt-get &> /dev/null; then
79-
echo "Installing python3-venv package for venv support..." >&2
80-
sudo apt-get update -qq || true
81-
sudo apt-get install -y python3-venv || true
82-
fi
83-
return 0
84-
fi
73+
# Install specific pinned version for consistency across runs
74+
echo "Installing Python ${required_version} via pyenv..." >&2
75+
# Use --skip-existing to avoid errors if version already exists
76+
if pyenv install --skip-existing "${required_version}"; then
77+
pyenv global "${required_version}"
78+
return 0
8579
fi
86-
87-
echo "Error: Unable to install Python ${major_minor} via pyenv" >&2
88-
return 1
8980
}
9081

9182
if [[ -d "${PROJECT_DIR}"/venv ]]; then

scripts/evergreen/setup_aws.sh

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,30 +42,31 @@ install_aws_cli_binary() {
4242
install_aws_cli_pip() {
4343
echo "Installing AWS CLI v1 via pip (for IBM architectures)..."
4444

45-
# Ensure pip is available
46-
if ! command -v pip3 &> /dev/null && ! command -v pip &> /dev/null; then
47-
echo "Error: pip is not available. Please install Python and pip first." >&2
45+
if [[ ! -d "${PROJECT_DIR}/venv" ]]; then
46+
echo "Error: Python venv not found at ${PROJECT_DIR}/venv. Please run recreate_python_venv.sh first." >&2
4847
return 1
4948
fi
5049

51-
# Check if AWS CLI exists and works before installing
52-
if command -v aws &> /dev/null && aws --version &> /dev/null 2>&1; then
53-
echo "AWS CLI is already installed and working"
54-
return 0
55-
fi
56-
57-
echo "Installing AWS CLI using pip3..."
58-
pip3 install --user awscli
50+
# Activate the venv
51+
source "${PROJECT_DIR}/venv/bin/activate"
5952

60-
# Add ~/.local/bin to PATH if not already there (where pip --user installs)
61-
if [[ ":${PATH}:" != *":${HOME}/.local/bin:"* ]]; then
62-
export PATH="${HOME}/.local/bin:${PATH}"
63-
echo "Added ~/.local/bin to PATH"
53+
# Check if AWS CLI exists and works in the venv
54+
if command -v aws &> /dev/null; then
55+
if aws --version > /dev/null 2>&1; then
56+
echo "AWS CLI is already installed and working in venv"
57+
return 0
58+
else
59+
echo "AWS CLI exists but not functional, reinstalling in venv..."
60+
pip uninstall -y awscli || true
61+
fi
6462
fi
6563

64+
echo "Installing AWS CLI into venv using pip..."
65+
pip install awscli
66+
6667
# Verify installation
6768
if command -v aws &> /dev/null; then
68-
echo "AWS CLI v1 installed successfully"
69+
echo "AWS CLI v1 installed successfully in venv"
6970
else
7071
echo "Error: AWS CLI v1 installation failed" >&2
7172
return 1

0 commit comments

Comments
 (0)