11#! /bin/bash
22
33# Usage
4- # build_and_run_tests.sh <workspace> [-b <bazel path>] [--env pip|conda] [--mode merge_gate|continuous_run] [--with-snowpark] [--with-spcs-image] [--report <report_path>]
4+ # build_and_run_tests.sh <workspace> [-b <bazel path>] [--env pip|conda] [--mode merge_gate|continuous_run] [--with-snowpark] [--with-spcs-image] [--run-grype] [-- report <report_path>]
55#
66# Args
77# workspace: path to the workspace, SnowML code should be in snowml directory.
1515# quarantined: run all quarantined tests.
1616# with-snowpark: Build and test with snowpark in snowpark-python directory in the workspace.
1717# with-spcs-image: Build and test with spcs-image in spcs-image directory in the workspace.
18+ # run-grype: Run grype security scanning on SPCS images. Only valid with --with-spcs-image.
1819# snowflake-env: The environment of the snowflake, use to determine the test quarantine list
1920# report: Path to xml test report
2021#
@@ -30,7 +31,7 @@ PROG=$0
3031
3132help () {
3233 local exit_code=$1
33- echo " Usage: ${PROG} <workspace> [-b <bazel path>] [--env pip|conda] [--mode merge_gate|continuous_run|quarantined] [--with-snowpark] [--with-spcs-image] [--snowflake-env <sf_env>] [--report <report_path>]"
34+ echo " Usage: ${PROG} <workspace> [-b <bazel path>] [--env pip|conda] [--mode merge_gate|continuous_run|quarantined] [--with-snowpark] [--with-spcs-image] [--run-grype] [-- snowflake-env <sf_env>] [--report <report_path>]"
3435 exit " ${exit_code} "
3536}
3637
@@ -39,6 +40,7 @@ BAZEL="bazel"
3940ENV=" pip"
4041WITH_SNOWPARK=false
4142WITH_SPCS_IMAGE=false
43+ RUN_GRYPE=false
4244MODE=" continuous_run"
4345PYTHON_VERSION=3.9
4446PYTHON_ENABLE_SCRIPT=" bin/activate"
@@ -91,6 +93,9 @@ while (($#)); do
9193 --with-spcs-image)
9294 WITH_SPCS_IMAGE=true
9395 ;;
96+ --run-grype)
97+ RUN_GRYPE=true
98+ ;;
9499 -h | --help)
95100 help 0
96101 ;;
@@ -101,6 +106,12 @@ while (($#)); do
101106 shift
102107done
103108
109+ # Validate flag combinations
110+ if [ " ${RUN_GRYPE} " = true ] && [ " ${WITH_SPCS_IMAGE} " = false ]; then
111+ echo " Error: --run-grype flag requires --with-spcs-image to be set"
112+ help 1
113+ fi
114+
104115echo " Running build_and_run_tests with PYTHON_VERSION ${PYTHON_VERSION} "
105116
106117EXT=" "
@@ -180,6 +191,25 @@ trap 'rm -rf "${TEMP_BIN}"' EXIT
180191# Install micromamba
181192_MICROMAMBA_BIN=" micromamba${EXT} "
182193if [ " ${ENV} " = " conda" ]; then
194+ CONDA=" /mnt/jenkins/home/jenkins/miniforge3/condabin/conda"
195+
196+ # Check if miniforge is already installed
197+ if [ -x " ${CONDA} " ]; then
198+ echo " Miniforge exists at ${CONDA} ."
199+ else
200+ echo " Downloading miniforge ..."
201+ curl -L -O " https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$( uname) -$( uname -m) .sh"
202+
203+ echo " Installing miniforge ..."
204+ /bin/bash " Miniforge3-$( uname) -$( uname -m) .sh" -b -u
205+ fi
206+
207+ echo " Using ${CONDA} ..."
208+
209+ echo " Installing conda-build ..."
210+ ${CONDA} install conda-build --yes
211+
212+ echo " Installing micromamba ..."
183213 if ! command -v " ${_MICROMAMBA_BIN} " & > /dev/null; then
184214 curl -Lsv " https://github.com/mamba-org/micromamba-releases/releases/latest/download/micromamba-${MICROMAMBA_PLATFORM} -${MICROMAMBA_ARCH} " -o " ${TEMP_BIN} /micromamba${EXT} " && chmod +x " ${TEMP_BIN} /micromamba${EXT} "
185215 _MICROMAMBA_BIN=" ${TEMP_BIN} /micromamba${EXT} "
@@ -264,30 +294,31 @@ if [ "${ENV}" = "pip" ]; then
264294 cp " $( " ${BAZEL} " " ${BAZEL_ADDITIONAL_STARTUP_FLAGS[@]+" ${BAZEL_ADDITIONAL_STARTUP_FLAGS[@]} " } " info bazel-bin) /dist/snowflake_ml_python-${VERSION} -py3-none-any.whl" " ${WORKSPACE} "
265295 popd
266296else
267- # Clean conda cache
268- conda clean --all --force-pkgs-dirs -y
297+ echo " Cleaning conda cache ... "
298+ ${CONDA} clean --all --force-pkgs-dirs -y
269299
270- # Clean conda build workspace
300+ echo " Cleaning conda build workspace ... "
271301 rm -rf " ${WORKSPACE} /conda-bld"
272302
273- # Build Snowpark
303+ echo " Building snowpark-python conda package ... "
274304 if [ " ${WITH_SNOWPARK} " = true ]; then
275305 pushd ${SNOWPARK_DIR}
276- conda build recipe/ --python=${PYTHON_VERSION} --numpy=1.16 --croot " ${WORKSPACE} /conda-bld"
306+ ${CONDA} build recipe/ --python=${PYTHON_VERSION} --numpy=1.16 --croot " ${WORKSPACE} /conda-bld"
277307 popd
278308 fi
279309
280- # Build SnowML
281310 pushd ${SNOWML_DIR}
282- # Build conda package
283- conda build -c conda-forge --override-channels --prefix-length 50 --python=${PYTHON_VERSION} --croot " ${WORKSPACE} /conda-bld" ci/conda_recipe
284- conda build purge
311+
312+ echo " Building snowflake-ml-python conda package ..."
313+ ${CONDA} build -c conda-forge --override-channels --prefix-length 50 --python=${PYTHON_VERSION} --croot " ${WORKSPACE} /conda-bld" ci/conda_recipe
314+ ${CONDA} build purge
285315 popd
286316fi
287317
288318if [[ " ${WITH_SPCS_IMAGE} " = true ]]; then
289319 pushd ${SNOWML_DIR}
290- # Build SPCS Image
320+ echo " Building SPCS Image ..."
321+ export RUN_GRYPE
291322 source model_container_services_deployment/ci/build_and_push_images.sh
292323 popd
293324fi
@@ -361,7 +392,7 @@ for i in "${!groups[@]}"; do
361392 COMMON_PYTEST_FLAG+=(-m " not conda_incompatible" )
362393 fi
363394 # Create local conda channel
364- conda index " ${WORKSPACE} /conda-bld"
395+ ${CONDA} index " ${WORKSPACE} /conda-bld"
365396
366397 # Clean conda cache
367398 " ${_MICROMAMBA_BIN} " clean --all --force-pkgs-dirs -y
@@ -384,7 +415,7 @@ for i in "${!groups[@]}"; do
384415
385416 # Run integration tests
386417 set +e
387- TEST_SRCDIR=" ${TEMP_TEST_DIR} " conda run -p ./testenv --no-capture-output python -m pytest " ${COMMON_PYTEST_FLAG[@]} " tests/integ/
418+ TEST_SRCDIR=" ${TEMP_TEST_DIR} " ${CONDA} run -p ./testenv --no-capture-output python -m pytest " ${COMMON_PYTEST_FLAG[@]} " tests/integ/
388419 group_exit_codes[$i ]=$?
389420 set -e
390421
0 commit comments