Skip to content

Commit 0686a62

Browse files
committed
ci: rework dockerfile
1 parent 2c2fc26 commit 0686a62

File tree

10 files changed

+119
-96
lines changed

10 files changed

+119
-96
lines changed

ci/docker/almalinux/Dockerfile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ RUN dnf -y update \
1212
CMD [ "/usr/bin/bash" ]
1313

1414
RUN dnf -y update \
15-
&& dnf -y install python3-devel python3-pip python3-numpy \
15+
&& dnf -y install python3-devel python3-pip \
16+
python3-numpy \
1617
&& dnf clean all \
1718
&& rm -rf /var/cache/dnf
18-
RUN python3 -m pip install mypy
19+
RUN python3 -m pip install \
20+
mypy
1921

2022
# Add the library src to our build env
2123
FROM env AS devel
@@ -34,9 +36,9 @@ RUN CTEST_OUTPUT_ON_FAILURE=1 cmake --build build --target test -v
3436
# Test install rules
3537
FROM env AS install_env
3638
COPY --from=build /home/project/build/python/dist/*.whl ./
37-
RUN python3 -m pip install \
38-
--find-links=. \
39-
cmakepybind11*.whl
39+
RUN python3 -m pip install --find-links=. \
40+
cmpb11*.whl
41+
RUN python3 -m pip show cmpb11
4042

4143
FROM install_env AS install_devel
4244
WORKDIR /home/samples

ci/docker/alpine/Dockerfile

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ FROM alpine:edge AS env
44

55
# Install system build dependencies
66
ENV PATH=/usr/local/bin:$PATH
7-
RUN apk add --no-cache git build-base linux-headers cmake
8-
9-
# Install Python
107
RUN apk add --no-cache \
8+
git build-base linux-headers cmake \
119
python3 python3-dev py3-pip py3-wheel \
1210
py3-virtualenv \
1311
py3-mypy
@@ -29,10 +27,8 @@ RUN CTEST_OUTPUT_ON_FAILURE=1 cmake --build build --target test -v
2927
# Test install rules
3028
FROM env AS install_env
3129
COPY --from=build /home/project/build/python/dist/*.whl ./
32-
RUN python3 -m pip install \
33-
--break-system-packages \
34-
--find-links=. \
35-
cmakepybind11*.whl
30+
RUN python3 -m pip install --break-system-packages --find-links=. \
31+
cmpb11*.whl
3632

3733
FROM install_env AS install_devel
3834
WORKDIR /home/samples

ci/docker/archlinux/Dockerfile

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
FROM archlinux:latest AS env
44

55
# Install system build dependencies
6-
ENV PATH=/usr/local/bin:$PATH
7-
RUN pacman -Syu --noconfirm git base-devel cmake
8-
9-
# Install Python
6+
ENV PATH=/root/.local/bin:$PATH
107
RUN pacman -Syu --noconfirm \
8+
git base-devel cmake \
119
python python-pip python-wheel python-setuptools \
1210
python-virtualenv
11+
RUN python -m pip install --break-system-package \
12+
mypy
1313

1414
# Add the library src to our build env
1515
FROM env AS devel
@@ -28,17 +28,15 @@ RUN CTEST_OUTPUT_ON_FAILURE=1 cmake --build build --target test -v
2828
# Test install rules
2929
FROM env AS install_env
3030
COPY --from=build /home/project/build/python/dist/*.whl ./
31-
RUN python3 -m pip install \
32-
--break-system-packages \
33-
--find-links=. \
34-
cmakepybind11*.whl
31+
RUN python -m pip install --break-system-packages --find-links=. \
32+
cmpb11*.whl
3533

3634
FROM install_env AS install_devel
3735
WORKDIR /home/samples
3836
COPY ci/samples .
3937

4038
FROM install_devel AS install_build
41-
RUN python3 -m compileall .
39+
RUN python -m compileall .
4240

4341
FROM install_build AS install_test
44-
RUN python3 sample.py
42+
RUN python sample.py

ci/docker/debian/Dockerfile

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Create a virtual environment with all tools installed
22
# ref: https://hub.docker.com/_/debian
3-
FROM debian:unstable AS env
3+
FROM debian:latest AS env
44

55
# Install system build dependencies
66
ENV PATH=/usr/local/bin:$PATH
@@ -39,10 +39,8 @@ RUN CTEST_OUTPUT_ON_FAILURE=1 cmake --build build --target test -v
3939
# Test install rules
4040
FROM env AS install_env
4141
COPY --from=build /home/project/build/python/dist/*.whl ./
42-
RUN python3 -m pip install \
43-
--break-system-packages \
44-
--find-links=. \
45-
cmakepybind11*.whl
42+
RUN python3 -m pip install --break-system-packages --find-links=. \
43+
cmpb11*.whl
4644

4745
FROM install_env AS install_devel
4846
WORKDIR /home/samples

ci/docker/fedora/Dockerfile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ RUN dnf -y update \
1414
# Install Python
1515
RUN dnf -y update \
1616
&& dnf -y install \
17-
python3 python3-devel python3-pip \
17+
python3 python3-devel python3-pip python3-wheel \
18+
python3-virtualenv \
1819
&& dnf clean all
20+
RUN python3 -m pip install \
21+
mypy
1922

2023
# Add the library src to our build env
2124
FROM env AS devel
@@ -34,9 +37,8 @@ RUN CTEST_OUTPUT_ON_FAILURE=1 cmake --build build --target test -v
3437
# Test install rules
3538
FROM env AS install_env
3639
COPY --from=build /home/project/build/python/dist/*.whl ./
37-
RUN python3 -m pip install \
38-
--find-links=. \
39-
cmakepybind11*.whl
40+
RUN python3 -m pip install --find-links=. \
41+
cmpb11*.whl
4042

4143
FROM install_env AS install_devel
4244
WORKDIR /home/samples

ci/docker/manylinux/Dockerfile

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,24 @@ CMD ["/usr/bin/bash"]
2121
FROM env AS devel
2222
WORKDIR /home/project
2323
COPY . .
24-
COPY ./ci/docker/arm64v8/manylinux/build-manylinux.sh .
24+
COPY ./ci/docker/manylinux/build-manylinux.sh .
2525

2626
FROM devel AS build
2727
RUN ./build-manylinux.sh build
2828

2929
FROM build AS test
3030
RUN ./build-manylinux.sh test
3131

32-
FROM env AS install_env
32+
FROM ubuntu:latest AS install_env
33+
RUN apt update -q \
34+
&& apt install -yq python3-dev python3-pip \
35+
&& apt clean \
36+
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
37+
3338
COPY --from=build /home/project/build*/python/dist/*.whl ./
34-
RUN python3 -m pip install \
35-
--find-links=. \
36-
cmakepybind11*.whl
39+
RUN python3 -m pip install --break-system-packages --find-links=. \
40+
cmpb11*.whl
41+
RUN python3 -m pip show cmpb11
3742

3843
FROM install_env AS install_devel
3944
WORKDIR /home/sample

ci/docker/manylinux/build-manylinux.sh

Lines changed: 65 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
#!/usr/bin/env bash
2+
23
# Build all the wheel artifacts for the platforms supported by manylinux2014 and
34
# export them to the specified location.
45
set -euxo pipefail
56

7+
function assert_defined(){
8+
if [[ -z "${!1}" ]]; then
9+
>&2 echo "Variable '${1}' must be defined"
10+
exit 1
11+
fi
12+
}
13+
614
function usage() {
715
local -r NAME=$(basename "$0")
816
echo -e "$NAME - Build using a cross toolchain.
@@ -38,56 +46,83 @@ function contains_element() {
3846
}
3947

4048
function build_wheel() {
49+
assert_defined BUILD_DIR
50+
assert_defined VENV_DIR
4151
# Build the wheel artifact
4252
# Arguments:
4353
# $1 the python root directory
4454
if [[ "$#" -ne 1 ]]; then
4555
echo "$0 called with an illegal number of parameters"
46-
exit 1 # TODO return error and check it outside
56+
exit 1
4757
fi
4858

49-
#pwd
59+
# Create and activate virtualenv
60+
# this is needed so protoc can call the correct python executable
61+
local -r PYBIN="$1/bin"
62+
"${PYBIN}/pip" install virtualenv
63+
"${PYBIN}/virtualenv" -p "${PYBIN}/python" "${VENV_DIR}"
64+
# shellcheck source=/dev/null
65+
source "${VENV_DIR}/bin/activate"
66+
pip install -U pip setuptools wheel mypy
67+
68+
echo "current dir: $(pwd)"
69+
5070
if [[ ! -e "CMakeLists.txt" ]] || [[ ! -d "cmake" ]]; then
5171
>&2 echo "Can't find project's CMakeLists.txt or cmake"
5272
exit 2
5373
fi
74+
cmake -S. -B"${BUILD_DIR}" \
75+
-DCMAKE_BUILD_TYPE=Release \
76+
-DPython3_ROOT_DIR="$1" \
77+
-DBUILD_TESTING=OFF #--debug-find
78+
cmake --build "${BUILD_DIR}" -v -j4
5479

55-
cmake -S. -B"${BUILD_DIR}" -DPython3_ROOT_DIR="$1" -DBUILD_TESTING=OFF #--debug-find
56-
cmake --build "${BUILD_DIR}"
80+
# Restore environment
81+
deactivate
5782
}
5883

5984
function check_wheel() {
85+
assert_defined BUILD_DIR
86+
assert_defined VENV_DIR
6087
# Check the wheel artifact
6188
# Arguments:
6289
# $1 the python root directory
6390
if [[ "$#" -ne 1 ]]; then
6491
echo "$0 called with an illegal number of parameters"
65-
exit 1 # TODO return error and check it outside
92+
exit 1
6693
fi
6794

68-
# Build python bindings
95+
# shellcheck source=/dev/null
96+
source "${VENV_DIR}/bin/activate"
97+
pip install -U auditwheel
98+
99+
# Check all generated wheel packages
100+
ROOT_DIR=$(pwd)
69101
pushd "${BUILD_DIR}/python/dist"
70102
for FILE in *.whl; do
71103
# if no files found do nothing
72104
[[ -e "$FILE" ]] || continue
73-
auditwheel show "$FILE" || true
74-
#auditwheel -v repair --plat manylinux2014_aarch64 "$FILE" -w "$export_root"
105+
python -m auditwheel show "$FILE" || true
106+
#python -m auditwheel -v repair --plat manylinux2014_aarch64 "$FILE" -w "$export_root"
107+
#python -m auditwheel -v repair --plat manylinux_2_28_x86_64 "$FILE" -w .
75108
done
76109
popd
110+
111+
# Restore environment
112+
deactivate
77113
}
78114

79115
function test_wheel() {
116+
assert_defined BUILD_DIR
117+
assert_defined TEST_DIR
80118
# Test the wheel artifacts
81119
# Arguments:
82120
# $1 the python root directory
83121
if [[ "$#" -ne 1 ]]; then
84122
echo "$0 called with an illegal number of parameters"
85-
exit 1 # TODO return error and check it outside
123+
exit 1
86124
fi
87125

88-
local -r BUILD_DIR="build_${PYTAG}"
89-
local -r TEST_DIR="test_${PYTAG}"
90-
91126
# Create and activate virtualenv
92127
local -r PYBIN="$1/bin"
93128
"${PYBIN}/pip" install virtualenv
@@ -102,29 +137,31 @@ function test_wheel() {
102137
local -r WHEEL_FILE=$(find "${BUILD_DIR}"/python/dist/*.whl | head -1)
103138
echo "WHEEL file: ${WHEEL_FILE}"
104139
pip install --no-cache-dir "$WHEEL_FILE"
105-
pip show pythonnative
140+
pip show cmpb11
106141

107-
# Run tests
108-
run_tests
109-
110-
# Restore environment
111-
deactivate
112-
}
142+
# Python scripts to be used as tests for the installed wheel. This list of files
143+
# has been taken from the 'test_python' make target.
144+
declare -a TESTS=(
145+
"samples/sample.py"
146+
"tests/test.py"
147+
)
113148

114-
function run_tests() {
115149
# Run all the specified test scripts using the current environment.
150+
local -r ROOT_DIR=$(pwd)
116151
pushd "$(mktemp -d)" # ensure we are not importing something from $PWD
117152
python --version
118-
for TEST in "${TESTS[@]}"
119-
do
120-
python "$TEST"
153+
for TEST in "${TESTS[@]}"; do
154+
python "${ROOT_DIR}/${TEST}"
121155
done
122156
popd
157+
158+
# Restore environment
159+
deactivate
123160
}
124161

125162
function build() {
126163
# For each python platform provided by manylinux, build and test artifacts.
127-
for PYROOT in /opt/python/*; do
164+
for PYROOT in /opt/python/cp*; do
128165
# shellcheck disable=SC2155
129166
PYTAG=$(basename "$PYROOT")
130167
echo "Python: $PYTAG"
@@ -136,15 +173,15 @@ function build() {
136173
fi
137174

138175
BUILD_DIR="build_${PYTAG}"
139-
TEST_DIR="test_${PYTAG}"
176+
VENV_DIR="env_${PYTAG}"
140177
build_wheel "$PYROOT"
141178
check_wheel "$PYROOT"
142179
done
143180
}
144181

145182
function tests() {
146183
# For each python platform provided by manylinux, build and test artifacts.
147-
for PYROOT in /opt/python/*; do
184+
for PYROOT in /opt/python/cp*; do
148185
# shellcheck disable=SC2155
149186
PYTAG=$(basename "$PYROOT")
150187
echo "Python: $PYTAG"
@@ -154,9 +191,9 @@ function tests() {
154191
>&2 echo "skipping deprecated platform $PYTAG"
155192
continue
156193
fi
194+
157195
BUILD_DIR="build_${PYTAG}"
158196
TEST_DIR="test_${PYTAG}"
159-
160197
test_wheel "$PYROOT"
161198
done
162199
}
@@ -169,10 +206,7 @@ function main() {
169206
esac
170207

171208
# Setup
172-
# Python scripts to be used as tests for the installed wheel. This list of files
173-
# has been taken from the 'test_python' make target.
174-
declare -a TESTS=( "/home/project/ci/samples/sample.py" "/home/project/tests/test.py" )
175-
declare -a SKIPS=( "pp37-pypy37_pp73" )
209+
declare -a SKIPS=("cp36-cp36m" "cp37-cp37m")
176210

177211
case ${1} in
178212
build)

ci/docker/opensuse/Dockerfile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,8 @@ RUN CTEST_OUTPUT_ON_FAILURE=1 cmake --build build --target test -v
3636
# Test install rules
3737
FROM env AS install_env
3838
COPY --from=build /home/project/build/python/dist/*.whl ./
39-
RUN python3 -m pip install \
40-
--break-system-packages \
41-
--find-links=. \
42-
cmakepybind11*.whl
39+
RUN python3 -m pip install --break-system-packages --find-links=. \
40+
cmpb11*.whl
4341

4442
FROM install_env AS install_devel
4543
WORKDIR /home/samples

0 commit comments

Comments
 (0)