diff --git a/workers/analyzer/docker/Analyzer.Dockerfile b/workers/analyzer/docker/Analyzer.Dockerfile index 3b86e255cf..44800e2789 100644 --- a/workers/analyzer/docker/Analyzer.Dockerfile +++ b/workers/analyzer/docker/Analyzer.Dockerfile @@ -165,7 +165,7 @@ ARG PYTHON_VERSION ARG PYENV_GIT_TAG ENV PYENV_ROOT=/opt/python -ENV PATH=$PATH:$PYENV_ROOT/shims:$PYENV_ROOT/bin:$PYENV_ROOT/conan2/bin +ENV PATH=$PATH:$PYENV_ROOT/shims:$PYENV_ROOT/bin RUN curl -kSs https://pyenv.run | bash \ && pyenv install -v $PYTHON_VERSION \ && pyenv global $PYTHON_VERSION @@ -182,16 +182,23 @@ RUN pip install --no-cache-dir -U \ wheel \ && pip install --no-cache-dir -U \ Mercurial \ - conan=="$CONAN_VERSION" \ pipenv=="$PYTHON_PIPENV_VERSION" \ poetry=="$PYTHON_POETRY_VERSION" \ python-inspector=="$PYTHON_INSPECTOR_VERSION" -RUN mkdir /tmp/conan2 && cd /tmp/conan2 \ - && wget https://github.com/conan-io/conan/releases/download/$CONAN2_VERSION/conan-$CONAN2_VERSION-linux-x86_64.tgz \ - && tar -xvf conan-$CONAN2_VERSION-linux-x86_64.tgz\ - # Rename the Conan 2 executable to "conan2" to be able to call both Conan version from the package manager. - && mkdir $PYENV_ROOT/conan2 && mv /tmp/conan2/bin $PYENV_ROOT/conan2/ \ - && mv $PYENV_ROOT/conan2/bin/conan $PYENV_ROOT/conan2/bin/conan2 + +# Create conan environments +COPY scripts/setup_conan.sh ${PYENV_ROOT}/bin/conan +RUN eval "$(pyenv init - bash)" \ + && eval "$(pyenv virtualenv-init -)" \ + && pyenv virtualenv conan \ + && pyenv activate conan \ + && pip install conan==${CONAN_VERSION} \ + && pyenv deactivate \ + && pyenv virtualenv conan2 \ + && pyenv activate conan2 \ + && pip install conan==${CONAN2_VERSION} \ + && pyenv deactivate \ + && sudo chmod +x ${PYENV_ROOT}/bin/conan FROM scratch AS python COPY --from=pythonbuild /opt/python /opt/python @@ -463,7 +470,7 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ # Python ENV PYENV_ROOT=/opt/python -ENV PATH=$PATH:$PYENV_ROOT/shims:$PYENV_ROOT/bin:$PYENV_ROOT/conan2/bin +ENV PATH=$PATH:$PYENV_ROOT/shims:$PYENV_ROOT/bin:$PYENV_ROOT/plugins/pyenv-virtualenv/shims COPY --from=python --chown=$USER:$USER $PYENV_ROOT $PYENV_ROOT # NodeJS diff --git a/workers/analyzer/docker/scripts/setup_conan.sh b/workers/analyzer/docker/scripts/setup_conan.sh new file mode 100644 index 0000000000..d803d1feea --- /dev/null +++ b/workers/analyzer/docker/scripts/setup_conan.sh @@ -0,0 +1,45 @@ +#!/bin/bash +# +# Copyright (C) 2025 The ORT Project Authors (see ) +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# License-Filename: LICENSE +# + +conan_option=${CONAN_MAJOR_VERSION:-2} + +# Since this script is installed with the name "conan", there is a risk of infinite recursion if pyenv is not available +# on the PATH, which can occur when setting up a development environment. To prevent this, check for recursive calls. +if [[ "$CONAN_RECURSIVE_CALL" -eq 1 ]]; then + echo "Recursive call detected. Exiting." + exit 1 +fi + +# Setup pyenv +eval "$(pyenv init - --no-rehash bash)" +eval "$(pyenv virtualenv-init -)" + +# Setting up Conan 1.x +if [[ "$conan_option" -eq 1 ]]; then # Setting up Conan 1.x series + pyenv activate conan + # Docker has modern libc + CONAN_RECURSIVE_CALL=1 conan profile update settings.compiler.libcxx=libstdc++11 ort-default +elif [[ "$conan_option" -eq 2 ]]; then # Setting up Conan 2.x series + pyenv activate conan2 +fi + +# Runs conan from activated profile +CONAN_RECURSIVE_CALL=1 conan "$@" +