Skip to content

Commit 960bd67

Browse files
committed
refactor: 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]>
1 parent f26c647 commit 960bd67

File tree

2 files changed

+48
-9
lines changed

2 files changed

+48
-9
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

scripts/setup_conan.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
conan_option=${CONAN_SERIES:-2}
4+
create_profile=${CONAN_CREATE_PROFILE:-true}
5+
6+
# Setup pyenv
7+
eval "$(pyenv init - bash)"
8+
eval "$(pyenv virtualenv-init -)"
9+
10+
# Setting up Conan 1.x
11+
if [[ "$conan_option" -eq 1 ]]; then # Setting up Conan 1.x series
12+
pyenv activate conan
13+
if "$create_profile"; then
14+
echo "Creating Conan profile."
15+
conan profile new default --detect
16+
# Docker has modern libc
17+
conan profile update settings.compiler.libcxx=libstdc++11 default
18+
fi
19+
echo "Using Conan 1.x series."
20+
elif [[ "$conan_option" -eq 2 ]]; then # Setting up Conan 2.x series
21+
pyenv activate conan2
22+
if "$create_profile"; then
23+
echo "Creating Conan profile."
24+
conan profile detect --force
25+
fi
26+
echo "Using Conan 2.x series."
27+
fi
28+
29+
# Runs conan from activated profile
30+
conan "$@"
31+

0 commit comments

Comments
 (0)