SERVER-104255: Add new workstation configure script (#35338)

GitOrigin-RevId: 2b9342ed9daa9a18e5806aac5246a9b9f76d57bf
This commit is contained in:
Jeff Zambory 2025-04-25 10:19:27 -04:00 committed by MongoDB Bot
parent cbd69e13ae
commit 5fcecd403f
6 changed files with 281 additions and 0 deletions

View File

@ -808,6 +808,15 @@ functions:
dir: src/buildscripts/antithesis/base_images/workload/src
- *configure_evergreen_api_credentials
"do pre workstation setup":
- command: manifest.load
- *git_get_shallow_project
- *f_expansions_write
- *restore_git_history_and_tags
- *add_git_tag
- *kill_processes
- *cleanup_environment
"do non-compile setup":
- command: manifest.load
- *git_get_shallow_project
@ -1267,6 +1276,17 @@ functions:
- *check_run_tests_infrastructure_failure
- *check_resmoke_failure
"set up then check workstation script":
- command: subprocess.exec
params:
binary: bash
args:
- "-c"
- |
cd ./src
./etc/set_up_workstation.sh
./evergreen/check_workstation_setup.sh
"run tests":
- *f_expansions_write
- *configure_evergreen_api_credentials

View File

@ -116,6 +116,13 @@ tasks:
vars:
resmoke_jobs_max: 1
- name: check_workstation_setup_script
tags: ["assigned_to_jira_team_devprod_correctness", "development_critical"]
depends_on: []
commands:
- func: "do pre workstation setup"
- func: "set up then check workstation script"
- <<: *gen_burn_in_task_template
name: burn_in_tags_gen
tags: ["assigned_to_jira_team_devprod_correctness", "auxiliary"]

View File

@ -26,6 +26,9 @@ buildvariants:
- name: monitor_build_status
distros:
- ubuntu2404-large
- name: check_workstation_setup_script
distros:
- ubuntu2204-arm64-small
# Experimental variant running bazel targets for integration tests. To be removed with SERVER-103537.
- name: bazel-integration-tests

38
etc/gdb_init Normal file
View File

@ -0,0 +1,38 @@
add-auto-load-safe-path /
set pagination off
set print object on
set print static-members off
set print pretty on
#set print elements 0
# include venv in the Python path
python
import os, subprocess, sys
try:
gdb_python_version = sys.version.split()[0]
shell_python_version = subprocess.check_output('python -c "import sys;print(sys.version.split()[0])"', shell=True).decode("utf-8").strip()
if gdb_python_version == shell_python_version:
# Execute a Python using the user's shell and pull out the sys.path (for site-packages)
shell_paths = subprocess.check_output('python -c "import os,sys;print(os.linesep.join(sys.path).strip())"', shell=True).decode("utf-8").split()
# Extend GDB's Python's search path
sys.path.extend(path for path in shell_paths if not path in sys.path)
print("Included venv Python path")
else:
print("Failed to include venv Python path: Python version mismatch (shell {}, gdb {})".format(shell_python_version, gdb_python_version))
except Exception as e:
print("Failed to include venv Python path: " + str(e))
end
# register boost pretty printers
python
import sys, pathlib
try:
sys.path.insert(1, os.path.join(pathlib.Path.home(), 'Boost-Pretty-Printer'))
import boost
boost.register_printers(boost_version=(1,60,0))
print("Loaded boost pretty printers")
except Exception as e:
print("Failed to load the boost pretty printers: " + str(e))
end

162
etc/set_up_workstation.sh Executable file
View File

@ -0,0 +1,162 @@
silent_grep() {
command grep -q > /dev/null 2>&1 "$@"
}
idem_file_append() {
if [[ -z "$1" ]]; then
return 1
fi
if [[ ! -f "$1" && -n "${4-}" ]]; then
return
fi
if [[ -z "$2" ]]; then
return 2
fi
if [[ -z "$3" ]]; then
return 3
fi
local start_marker="# BEGIN $2"
local end_marker="# END $2"
if ! silent_grep "^$start_marker" "$1"; then
{
echo -e "\n$start_marker";
echo -e "$3";
echo -e "$end_marker";
} >> "$1"
fi
}
setup_bash() {
# Bash profile should source .bashrc
echo "################################################################################"
echo "Setting up bash..."
local block=$(cat <<BLOCK
if [[ -f ~/.bashrc ]]; then
source ~/.bashrc
fi
BLOCK
)
idem_file_append ~/.bash_profile "Source .bashrc" "$block"
set +o nounset
source ~/.bash_profile
set -o nounset
echo "Finished setting up ~/.bashprofile..."
}
setup_mongo_venv() {
echo "################################################################################"
echo "Setting up the local virtual environment..."
# PYTHON_KEYRING_BACKEND is needed to make poetry install work
# See guide https://wiki.corp.mongodb.com/display/KERNEL/Virtual+Workstation
export PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring
/opt/mongodbtoolchain/v4/bin/python3 -m venv python3-venv
source ./python3-venv/bin/activate
POETRY_VIRTUALENVS_IN_PROJECT=true poetry install --no-root --sync
deactivate
echo "Finished setting up the local virtual environment..."
echo "Activate it by running 'source python3-venv/bin/activate'"
}
setup_poetry() {
echo "################################################################################"
echo "Installing 'poetry' command..."
export PATH="$PATH:$HOME/.local/bin"
if command -v poetry &> /dev/null; then
echo "'poetry' command exists; skipping setup"
else
pipx install poetry==2.0.0
echo "Finished installing poetry..."
fi
}
setup_pipx() {
echo "################################################################################"
echo "Installing 'pipx' command..."
if command -v pipx &> /dev/null; then
echo "'pipx' command exists; skipping setup"
else
export PATH="$PATH:$HOME/.local/bin"
local venv_name="tmp-pipx-venv"
/opt/mongodbtoolchain/v4/bin/python3 -m venv $venv_name
# virtualenv doesn't like nounset
set +o nounset
source $venv_name/bin/activate
set -o nounset
python -m pip install --upgrade "pip<20.3"
python -m pip install pipx
pipx install pipx --python /opt/mongodbtoolchain/v4/bin/python3 --force
pipx ensurepath --force
set +o nounset
deactivate
set -o nounset
rm -rf $venv_name
source ~/.bashrc
echo "Finished installing pipx..."
fi
}
setup_db_contrib_tool() {
echo "################################################################################"
echo "Installing 'db-contrib-tool' command..."
export PATH="$PATH:$HOME/.local/bin"
if command -v db-contrib-tool &> /dev/null; then
echo "'db-contrib-tool' command exists; skipping setup"
else
pipx install db-contrib-tool
echo "Finished installing db-contrib-tool"
fi
}
setup_gdb() {
echo "################################################################################"
echo "Setting up GDB..."
cwd=$(pwd)
cd ..
if [[ -d 'Boost-Pretty-Printer' ]]; then
echo "'Boost-Pretty-Printer' dir exists; skipping setup"
else
git clone https://github.com/mongodb-forks/Boost-Pretty-Printer.git
# the original version of this script just appended this line, so we
# have to grep for it manually
if ! silent_grep "source $HOME/gdbinit" ~/.gdbinit; then
idem_file_append ~/.gdbinit "Server Workflow Tool gdbinit" "source $HOME/gdbinit"
fi
echo "Finished installing pretty printers..."
fi
cd $cwd
}
run_setup() {
set +o nounset
source ~/.bashrc
set -o nounset
setup_bash
setup_gdb
setup_pipx
setup_db_contrib_tool # This step requires `setup_pipx` to have been run.
setup_poetry # This step requires `setup_pipx` to have been run.
setup_mongo_venv # This step requires `setup_poetry` to have been run.
echo "Please run 'source ~/.bashrc' to complete setup!"
}
run_setup

View File

@ -0,0 +1,51 @@
failed_setup=false
source ~/.bashrc
if command -v pipx &> /dev/null; then
echo "'pipx' command exists"
else
echo "pipx command not found - failed setup"
failed_setup=true
fi
if command -v poetry &> /dev/null; then
echo "'poetry' command exists"
else
echo "poetry command not found - failed setup"
failed_setup=true
fi
if command -v db-contrib-tool &> /dev/null; then
echo "'db-contrib-tool' command exists"
else
echo "db-contrib-tool command not found - failed setup"
failed_setup=true
fi
if test -d "./python3-venv"; then
echo "Venv directory exists, checking activation"
. python3-venv/bin/activate
./buildscripts/resmoke.py run --help &> /dev/null
if [ $? -eq 0 ]; then
echo "Virtual workstation set up correctly"
else
echo "Virtual workstation failed activation"
failed_setup=true
fi
deactivate
else
echo "mongo virtual environment not created correctly - failed setup"
failed_setup=true
fi
if test -d "../Boost-Pretty-Printer"; then
echo "Pretty printers set up correctly"
else
echo "Pretty printers failed setup"
failed_setup=true
fi
if $failed_setup; then
exit 1
fi