Skip to content

Commit 88c4bfc

Browse files
authored
Merge pull request #27753 from jaimergp/optimize-install-times
MNT: Use micromamba to provision base environment on macOS and Windows
2 parents ada0caf + a7625fb commit 88c4bfc

File tree

4 files changed

+69
-48
lines changed

4 files changed

+69
-48
lines changed

.azure-pipelines/azure-pipelines-osx.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@ jobs:
1616

1717
steps:
1818
- script: |
19-
export CI=azure
2019
./.scripts/run_osx_build.sh
2120
displayName: Run OSX build
21+
env:
22+
CI: azure
23+
CONDA_BLD_PATH: /Users/runner/Miniforge3/conda-bld
24+
MINIFORGE_HOME: /Users/runner/Miniforge3
2225
2326
- publish: /Users/runner/Miniforge3/conda-bld/osx-64/
2427
artifact: conda_pkgs_osx

.azure-pipelines/azure-pipelines-win.yml

+1-15
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,13 @@ jobs:
1010
CONFIG: win64
1111
timeoutInMinutes: 360
1212
steps:
13-
- task: PythonScript@0
14-
displayName: 'Download Miniforge'
15-
inputs:
16-
scriptSource: inline
17-
script: |
18-
import urllib.request
19-
url = 'https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Windows-x86_64.exe'
20-
path = r"$(Build.ArtifactStagingDirectory)/Miniforge.exe"
21-
urllib.request.urlretrieve(url, path)
22-
- script: |
23-
start /wait "" %BUILD_ARTIFACTSTAGINGDIRECTORY%\Miniforge.exe /InstallationType=JustMe /RegisterPython=0 /S /D=D:\Miniforge
24-
displayName: Install Miniforge
25-
- powershell: Write-Host "##vso[task.prependpath]D:\Miniforge\Scripts"
26-
displayName: Add conda to PATH
27-
2813
- script: |
2914
call .scripts\run_win_build.bat
3015
displayName: Build recipes
3116
env:
3217
CI: azure
3318
CONDA_BLD_PATH: D:\bld
19+
MINIFORGE_HOME: D:\Miniforge
3420
3521
- publish: D:\\bld\\win-64\\
3622
artifact: conda_pkgs_win

.scripts/run_osx_build.sh

+23-15
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,32 @@ set -x
44

55
source .scripts/logging_utils.sh
66

7-
( startgroup "Ensuring Miniforge" ) 2> /dev/null
7+
( startgroup "Provisioning base env with micromamba" ) 2> /dev/null
88

9-
MINIFORGE_URL="https://github.com/conda-forge/miniforge/releases/latest/download"
10-
MINIFORGE_FILE="Miniforge3-MacOSX-x86_64.sh"
11-
MINIFORGE_ROOT="${MINIFORGE_ROOT:-${HOME}/Miniforge3}"
9+
MINIFORGE_HOME=${MINIFORGE_HOME:-${HOME}/miniforge3}
10+
MINIFORGE_HOME=${MINIFORGE_HOME%/} # remove trailing slash
1211

13-
if [[ -d "${MINIFORGE_ROOT}" ]]; then
14-
echo "Miniforge already installed at ${MINIFORGE_ROOT}."
12+
if [[ -d "${MINIFORGE_HOME}" ]]; then
13+
echo "Miniforge already installed at ${MINIFORGE_HOME}."
1514
else
16-
echo "Installing Miniforge"
17-
curl -L -O "${MINIFORGE_URL}/${MINIFORGE_FILE}"
18-
bash $MINIFORGE_FILE -bp "${MINIFORGE_ROOT}"
15+
MICROMAMBA_VERSION="1.5.10-0"
16+
if [[ "$(uname -m)" == "arm64" ]]; then
17+
osx_arch="osx-arm64"
18+
else
19+
osx_arch="osx-64"
20+
fi
21+
MICROMAMBA_URL="https://github.com/mamba-org/micromamba-releases/releases/download/${MICROMAMBA_VERSION}/micromamba-${osx_arch}"
22+
echo "Downloading micromamba ${MICROMAMBA_VERSION}"
23+
micromamba_exe="$(mktemp -d)/micromamba"
24+
curl -L -o "${micromamba_exe}" "${MICROMAMBA_URL}"
25+
chmod +x "${micromamba_exe}"
26+
echo "Creating environment"
27+
"${micromamba_exe}" create --yes --root-prefix ~/.conda --prefix "${MINIFORGE_HOME}" \
28+
--channel conda-forge \
29+
--file .ci_support/requirements.txt
1930
fi
2031

21-
( endgroup "Ensuring Miniforge" ) 2> /dev/null
32+
( endgroup "Provisioning base env with micromamba" ) 2> /dev/null
2233

2334
( startgroup "Configuring conda" ) 2> /dev/null
2435

@@ -28,12 +39,9 @@ show_channel_urls: true
2839
solver: libmamba
2940
CONDARC
3041

31-
source "${MINIFORGE_ROOT}/etc/profile.d/conda.sh"
42+
source "${MINIFORGE_HOME}/etc/profile.d/conda.sh"
3243
conda activate base
3344

34-
echo -e "\n\nInstalling conda-forge-ci-setup, conda-build."
35-
conda install --quiet --file .ci_support/requirements.txt
36-
3745
echo -e "\n\nSetting up the condarc and mangling the compiler."
3846
setup_conda_rc ./ ./recipes ./.ci_support/${CONFIG}.yaml
3947
if [[ "${CI:-}" != "" ]]; then
@@ -54,7 +62,7 @@ source run_conda_forge_build_setup
5462
set -e
5563

5664
# make sure there is a package directory so that artifact publishing works
57-
mkdir -p "${MINIFORGE_ROOT}/conda-bld/osx-64/" "${MINIFORGE_ROOT}/conda-bld/noarch/"
65+
mkdir -p "${MINIFORGE_HOME}/conda-bld/osx-64/" "${MINIFORGE_HOME}/conda-bld/noarch/"
5866

5967
# Find the recipes from main in this PR and remove them.
6068
echo ""

.scripts/run_win_build.bat

+41-17
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,70 @@
33
:: changes to this script, consider a proposal to conda-smithy so that other feedstocks can also
44
:: benefit from the improvement.
55

6-
:: Note: we assume a Miniforge installation is available
7-
86
:: INPUTS (required environment variables)
97
:: CONDA_BLD_PATH: path for the conda-build workspace
108
:: CI: azure, or unset
9+
:: MINIFORGE_HOME: where to install the base conda environment
1110

1211
setlocal enableextensions enabledelayedexpansion
1312

13+
if "%MINIFORGE_HOME%"=="" set "MINIFORGE_HOME=%USERPROFILE%\Miniforge3"
14+
:: Remove trailing backslash, if present
15+
if "%MINIFORGE_HOME:~-1%"=="\" set "MINIFORGE_HOME=%MINIFORGE_HOME:~0,-1%"
16+
call :start_group "Provisioning base env with micromamba"
17+
set "MAMBA_ROOT_PREFIX=%MINIFORGE_HOME%-micromamba-%RANDOM%"
18+
set "MICROMAMBA_VERSION=1.5.10-0"
19+
set "MICROMAMBA_URL=https://github.com/mamba-org/micromamba-releases/releases/download/%MICROMAMBA_VERSION%/micromamba-win-64"
20+
set "MICROMAMBA_TMPDIR=%TMP%\micromamba-%RANDOM%"
21+
set "MICROMAMBA_EXE=%MICROMAMBA_TMPDIR%\micromamba.exe"
22+
23+
echo Downloading micromamba %MICROMAMBA_VERSION%
24+
if not exist "%MICROMAMBA_TMPDIR%" mkdir "%MICROMAMBA_TMPDIR%"
25+
certutil -urlcache -split -f "%MICROMAMBA_URL%" "%MICROMAMBA_EXE%"
26+
if !errorlevel! neq 0 exit /b !errorlevel!
27+
28+
echo Creating environment
29+
call "%MICROMAMBA_EXE%" create --yes --root-prefix "%MAMBA_ROOT_PREFIX%" --prefix "%MINIFORGE_HOME%" ^
30+
--channel conda-forge ^
31+
--file .ci_support\requirements.txt
32+
if !errorlevel! neq 0 exit /b !errorlevel!
33+
echo Moving pkgs cache from %MAMBA_ROOT_PREFIX% to %MINIFORGE_HOME%
34+
move /Y "%MAMBA_ROOT_PREFIX%\pkgs" "%MINIFORGE_HOME%"
35+
if !errorlevel! neq 0 exit /b !errorlevel!
36+
echo Removing %MAMBA_ROOT_PREFIX%
37+
del /S /Q "%MAMBA_ROOT_PREFIX%"
38+
del /S /Q "%MICROMAMBA_TMPDIR%"
39+
call :end_group
40+
1441
call :start_group "Configuring conda"
1542

1643
if "%CONDA_BLD_PATH%" == "" (
1744
set "CONDA_BLD_PATH=C:\bld"
1845
)
1946

2047
:: Activate the base conda environment
21-
call activate base
48+
echo Activating "%MINIFORGE_HOME%"
49+
call "%MINIFORGE_HOME%\Scripts\activate"
2250

51+
:: Set basic configuration
52+
echo Setting up configuration
2353
conda.exe config --set always_yes yes
24-
if errorlevel 1 exit 1
54+
if !errorlevel! neq 0 exit /b !errorlevel!
2555
conda.exe config --set channel_priority strict
26-
if errorlevel 1 exit 1
56+
if !errorlevel! neq 0 exit /b !errorlevel!
2757
conda.exe config --set solver libmamba
28-
if errorlevel 1 exit 1
29-
30-
echo Installing dependencies
31-
conda.exe install --file .\.ci_support\requirements.txt
32-
if errorlevel 1 exit 1
58+
if !errorlevel! neq 0 exit /b !errorlevel!
3359

34-
:: Set basic configuration
35-
echo Setting up configuration
3660
setup_conda_rc .\ ".\recipes" .\.ci_support\%CONFIG%.yaml
37-
if errorlevel 1 exit 1
61+
if !errorlevel! neq 0 exit /b !errorlevel!
3862

3963
echo Run conda_forge_build_setup
4064
call run_conda_forge_build_setup
41-
if errorlevel 1 exit 1
65+
if !errorlevel! neq 0 exit /b !errorlevel!
4266

4367
echo Force fetch origin/main
4468
git fetch --force origin main:main
45-
if errorlevel 1 exit 1
69+
if !errorlevel! neq 0 exit /b !errorlevel!
4670
echo Removing recipes also present in main
4771
cd recipes
4872
for /f "tokens=*" %%a in ('git ls-tree --name-only main -- .') do rmdir /s /q %%a && echo Removing recipe: %%a
@@ -54,13 +78,13 @@ if not exist "%CONDA_BLD_PATH%\noarch\" mkdir "%CONDA_BLD_PATH%\noarch\"
5478

5579
echo Index %CONDA_BLD_PATH%
5680
conda.exe index "%CONDA_BLD_PATH%"
57-
if errorlevel 1 exit 1
81+
if !errorlevel! neq 0 exit /b !errorlevel!
5882

5983
call :end_group
6084

6185
echo Building all recipes
6286
python .ci_support\build_all.py --arch 64
63-
if errorlevel 1 exit 1
87+
if !errorlevel! neq 0 exit /b !errorlevel!
6488

6589
call :start_group "Inspecting artifacts"
6690

0 commit comments

Comments
 (0)