Skip to content

Commit 675c1fd

Browse files
committed
refactor(analyzer): Use environments to install Conan
This is an alignment commit to reflect the change in ORT due to [1]. [1]: oss-review-toolkit/ort#10127 Signed-off-by: Nicolas Nobelis <[email protected]>
1 parent 6cbbf73 commit 675c1fd

File tree

2 files changed

+61
-9
lines changed

2 files changed

+61
-9
lines changed

workers/analyzer/docker/Analyzer.Dockerfile

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ ARG PYTHON_VERSION
165165
ARG PYENV_GIT_TAG
166166

167167
ENV PYENV_ROOT=/opt/python
168-
ENV PATH=$PATH:$PYENV_ROOT/shims:$PYENV_ROOT/bin:$PYENV_ROOT/conan2/bin
168+
ENV PATH=$PATH:$PYENV_ROOT/shims:$PYENV_ROOT/bin
169169
RUN curl -kSs https://pyenv.run | bash \
170170
&& pyenv install -v $PYTHON_VERSION \
171171
&& pyenv global $PYTHON_VERSION
@@ -182,16 +182,23 @@ RUN pip install --no-cache-dir -U \
182182
wheel \
183183
&& pip install --no-cache-dir -U \
184184
Mercurial \
185-
conan=="$CONAN_VERSION" \
186185
pipenv=="$PYTHON_PIPENV_VERSION" \
187186
poetry=="$PYTHON_POETRY_VERSION" \
188187
python-inspector=="$PYTHON_INSPECTOR_VERSION"
189-
RUN mkdir /tmp/conan2 && cd /tmp/conan2 \
190-
&& wget https://github.com/conan-io/conan/releases/download/$CONAN2_VERSION/conan-$CONAN2_VERSION-linux-x86_64.tgz \
191-
&& tar -xvf conan-$CONAN2_VERSION-linux-x86_64.tgz\
192-
# Rename the Conan 2 executable to "conan2" to be able to call both Conan version from the package manager.
193-
&& mkdir $PYENV_ROOT/conan2 && mv /tmp/conan2/bin $PYENV_ROOT/conan2/ \
194-
&& mv $PYENV_ROOT/conan2/bin/conan $PYENV_ROOT/conan2/bin/conan2
188+
189+
# Create conan environments
190+
COPY scripts/setup_conan.sh ${PYENV_ROOT}/bin/conan
191+
RUN eval "$(pyenv init - bash)" \
192+
&& eval "$(pyenv virtualenv-init -)" \
193+
&& pyenv virtualenv conan \
194+
&& pyenv activate conan \
195+
&& pip install conan==${CONAN_VERSION} \
196+
&& pyenv deactivate \
197+
&& pyenv virtualenv conan2 \
198+
&& pyenv activate conan2 \
199+
&& pip install conan==${CONAN2_VERSION} \
200+
&& pyenv deactivate \
201+
&& sudo chmod +x ${PYENV_ROOT}/bin/conan
195202

196203
FROM scratch AS python
197204
COPY --from=pythonbuild /opt/python /opt/python
@@ -463,7 +470,7 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
463470

464471
# Python
465472
ENV PYENV_ROOT=/opt/python
466-
ENV PATH=$PATH:$PYENV_ROOT/shims:$PYENV_ROOT/bin:$PYENV_ROOT/conan2/bin
473+
ENV PATH=$PATH:$PYENV_ROOT/shims:$PYENV_ROOT/bin:$PYENV_ROOT/plugins/pyenv-virtualenv/shims
467474
COPY --from=python --chown=$USER:$USER $PYENV_ROOT $PYENV_ROOT
468475

469476
# NodeJS
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
#
3+
# Copyright (C) 2025 The ORT Project Authors (see <https://github.com/oss-review-toolkit/ort/blob/main/NOTICE>)
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
# SPDX-License-Identifier: Apache-2.0
18+
# License-Filename: LICENSE
19+
#
20+
21+
conan_option=${CONAN_MAJOR_VERSION:-2}
22+
23+
# Since this script is installed with the name "conan", there is a risk of infinite recursion if pyenv is not available
24+
# on the PATH, which can occur when setting up a development environment. To prevent this, check for recursive calls.
25+
if [[ "$CONAN_RECURSIVE_CALL" -eq 1 ]]; then
26+
echo "Recursive call detected. Exiting."
27+
exit 1
28+
fi
29+
30+
# Setup pyenv
31+
eval "$(pyenv init - --no-rehash bash)"
32+
eval "$(pyenv virtualenv-init -)"
33+
34+
# Setting up Conan 1.x
35+
if [[ "$conan_option" -eq 1 ]]; then # Setting up Conan 1.x series
36+
pyenv activate conan
37+
# Docker has modern libc
38+
CONAN_RECURSIVE_CALL=1 conan profile update settings.compiler.libcxx=libstdc++11 ort-default
39+
elif [[ "$conan_option" -eq 2 ]]; then # Setting up Conan 2.x series
40+
pyenv activate conan2
41+
fi
42+
43+
# Runs conan from activated profile
44+
CONAN_RECURSIVE_CALL=1 conan "$@"
45+

0 commit comments

Comments
 (0)