Skip to content

Commit 1775838

Browse files
heliocastronnobelis
authored andcommitted
refactor(docker): Use environments to install Conan
- Move previous conan/conan2 naming approach to Python environment solution. A wrapper that detects CONAN_SERIES environment var switchis between the two release series. Defaults to CONAN_SERIES=2. - Enable profile creation support by default Passing environment var CONAN_CREATE_PROFILE=false will prevent to generate a default profile. Signed-off-by: Helio Chissini de Castro <[email protected]> Signed-off-by: Nicolas Nobelis <[email protected]>
1 parent 034d082 commit 1775838

File tree

3 files changed

+63
-10
lines changed

3 files changed

+63
-10
lines changed

Dockerfile

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ ARG PYTHON_VERSION
136136
ARG PYENV_GIT_TAG
137137

138138
ENV PYENV_ROOT=/opt/python
139-
ENV PATH=$PATH:$PYENV_ROOT/shims:$PYENV_ROOT/bin:$PYENV_ROOT/conan2/bin
139+
ENV PATH=$PATH:$PYENV_ROOT/shims:$PYENV_ROOT/bin
140140
RUN curl -kSs https://pyenv.run | bash \
141141
&& pyenv install -v $PYTHON_VERSION \
142142
&& pyenv global $PYTHON_VERSION
@@ -170,18 +170,26 @@ RUN pip install --no-cache-dir -U \
170170
wheel \
171171
&& pip install --no-cache-dir -U \
172172
Mercurial \
173-
conan=="$CONAN_VERSION" \
174173
pipenv=="$PYTHON_PIPENV_VERSION" \
175174
poetry=="$PYTHON_POETRY_VERSION" \
176175
poetry-plugin-export=="$PYTHON_POETRY_PLUGIN_EXPORT_VERSION" \
177176
python-inspector=="$PYTHON_INSPECTOR_VERSION" \
178177
setuptools=="$PYTHON_SETUPTOOLS_VERSION"
179-
RUN mkdir /tmp/conan2 && cd /tmp/conan2 \
180-
&& wget https://github.com/conan-io/conan/releases/download/$CONAN2_VERSION/conan-$CONAN2_VERSION-linux-x86_64.tgz \
181-
&& tar -xvf conan-$CONAN2_VERSION-linux-x86_64.tgz\
182-
# Rename the Conan 2 executable to "conan2" to be able to call both Conan version from the package manager.
183-
&& mkdir $PYENV_ROOT/conan2 && mv /tmp/conan2/bin $PYENV_ROOT/conan2/ \
184-
&& mv $PYENV_ROOT/conan2/bin/conan $PYENV_ROOT/conan2/bin/conan2
178+
179+
# Create conan environments
180+
COPY scripts/setup_conan.sh ${PYENV_ROOT}/bin/conan
181+
RUN eval "$(pyenv init - bash)" \
182+
&& eval "$(pyenv virtualenv-init -)" \
183+
&& pyenv virtualenv conan \
184+
&& pyenv activate conan \
185+
&& pip install conan==${CONAN_VERSION} \
186+
&& pyenv deactivate \
187+
&& pyenv virtualenv conan2 \
188+
&& pyenv activate conan2 \
189+
&& pip install conan==${CONAN2_VERSION} \
190+
&& pyenv deactivate \
191+
&& sudo chmod +x ${PYENV_ROOT}/bin/conan
192+
185193

186194
FROM scratch AS python
187195
COPY --from=pythonbuild /opt/python /opt/python
@@ -484,7 +492,7 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
484492

485493
# Python
486494
ENV PYENV_ROOT=/opt/python
487-
ENV PATH=$PATH:$PYENV_ROOT/shims:$PYENV_ROOT/bin:$PYENV_ROOT/conan2/bin
495+
ENV PATH=$PATH:$PYENV_ROOT/shims:$PYENV_ROOT/bin:$PYENV_ROOT/plugins/pyenv-virtualenv/shims
488496
COPY --from=python --chown=$USER:$USER $PYENV_ROOT $PYENV_ROOT
489497

490498
# NodeJS

plugins/package-managers/conan/src/main/kotlin/Conan.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ internal class ConanCommand(private val useConan2: Boolean = false) : CommandLin
7979
override fun getVersionRequirement(): RangesList = RangesListFactory.create(">=1.44.0 <3.0")
8080

8181
override fun run(vararg args: CharSequence, workingDir: File?, environment: Map<String, String>) =
82-
super.run(args = args, workingDir, environment + ("CONAN_NON_INTERACTIVE" to "1"))
82+
super.run(args = args, workingDir, environment + mapOf("CONAN_NON_INTERACTIVE" to "1", "CONAN_SERIES" to "1"))
8383
}
8484

8585
data class ConanConfig(

scripts/setup_conan.sh

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_SERIES:-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)