Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a manylinux image for building X86_64 wheels #27

Merged
merged 20 commits into from
Nov 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/publish_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches:
- master
- dev
- dev2

jobs:
push_to_docker_hub:
Expand All @@ -18,6 +19,8 @@ jobs:
arch: linux/amd64
- docker_image: manylinux2014_aarch64
arch: linux/arm64
- docker_image: manylinux_2_28_x86_64
arch: linux/amd64
steps:
- name: Checkout repository
uses: actions/checkout@v2
Expand Down
2 changes: 2 additions & 0 deletions dockers/manylinux_2_28_x86_64/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!start_azure.sh
130 changes: 130 additions & 0 deletions dockers/manylinux_2_28_x86_64/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
FROM quay.io/pypa/manylinux_2_28_x86_64

# ensure that libraries like libc++ built in this image can be found by the linker
ENV LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/local/lib:/usr/local/lib64"

RUN yum update -y \
&& yum install -y \
sudo \
&& yum clean all

# Install CMake
RUN curl -sL https://cmake.org/files/v3.23/cmake-3.23.1-linux-x86_64.sh -o cmake.sh \
&& chmod +x cmake.sh \
&& ./cmake.sh --prefix=/usr/local --exclude-subdir \
&& rm -f ./cmake.sh

# building clang
#
# [why v11.1.0?]
#
# - LightGBM is incompatible with libomp v12 and v13 (https://github.com/microsoft/LightGBM/issues/4229)
# - PoCL v1.8 requires LLVM+clang, but only supports v6-v13 (https://github.com/pocl/pocl/blob/3f420ef735672e439097d020db605778dbc4a6a1/cmake/LLVM.cmake#L209)
# - so v11.x is the latest version that will work with the these constraints, and v11.1.0 was the last release in the v11 series
#
# [why from source?]
#
# - manylinux images use a custom sysroot foor the gcc toolchain, which doesn't play well with the precompiled llvm+clang available from https://github.com/llvm/llvm-project/releases
# - there is not a precompiled llvm+clang available for x86_64 architecture + non-Ubuntu distributions
#
# [why are we building libcxx and lld?]
#
# - in case compilation with clang (e.g. of PoCL v1.8) uses libc++ instead of libstdc++
#
# https://clang.llvm.org/get_started.html
# https://llvm.org/docs/GettingStarted.html#compiling-the-llvm-suite-source-code
ARG CLANG_VER=11.1.0
RUN mkdir /usr/local/src/clang \
&& cd /usr/local/src/clang \
&& git clone --depth 1 --branch llvmorg-$CLANG_VER https://github.com/llvm/llvm-project.git \
&& cd llvm-project \
&& mkdir build \
&& cd build \
&& cmake \
-DCMAKE_BUILD_TYPE=Release \
-DGCC_INSTALL_PREFIX=${DEVTOOLSET_ROOTPATH} \
-DLLVM_BUILD_BENCHMARKS=OFF \
-DLLVM_BUILD_DOCS=OFF \
-DLLVM_BUILD_TESTS=OFF \
-DLLVM_INCLUDE_BENCHMARKS=OFF \
-DLLVM_INCLUDE_DOCS=OFF \
-DLLVM_INCLUDE_TESTS=OFF \
-DLLVM_ENABLE_BINDINGS=OFF \
-DLLVM_ENABLE_DOXYGEN=OFF \
-DLLVM_ENABLE_OCAMLDOC=OFF \
-DLLVM_ENABLE_PROJECTS="clang;openmp" \
-DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" \
-DLLVM_ENABLE_SPHINX=OFF \
-DLLVM_TARGETS_TO_BUILD="X86" \
-G "Unix Makefiles" \
../llvm \
&& make -j2 \
&& make install \
# `make install` places libc++ into a different directory,
# symlinking it into /usr/local/lib so the linker can find it
&& cp -s /usr/local/lib/x86_64-unknown-linux-gnu/c++/* /usr/local/lib/ \
# manylinux images already come with an ldconfig rule pointing at /usr/local/lib,
# but just doing this explicitly to be safe in case they remove that in the future
&& echo /usr/local/lib > /etc/ld.so.conf.d/llvm.conf \
&& ldconfig \
&& cd "${HOME}" \
&& rm -rf /usr/local/src/clang

# Install PoCL
RUN git clone --depth 1 --branch v1.8 https://github.com/pocl/pocl.git \
&& cmake \
-B pocl/build \
-S pocl \
-DCMAKE_BUILD_TYPE=release \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_CXX_FLAGS=-stdlib=libstdc++ \
-DPOCL_INSTALL_ICD_VENDORDIR=/etc/OpenCL/vendors \
-DPOCL_DEBUG_MESSAGES=OFF \
-DSTATIC_LLVM=ON \
-DINSTALL_OPENCL_HEADERS=OFF \
-DENABLE_SPIR=OFF \
-DENABLE_POCLCC=OFF \
-DENABLE_TESTS=OFF \
-DENABLE_EXAMPLES=OFF \
&& cmake --build pocl/build -j4 \
&& cmake --install pocl/build \
&& rm -f ./compile_test*.bc \
&& rm -f ./compile_test*.o \
&& rm -rf ./pocl

# Install Java
RUN yum install -y \
java-1.8.0-openjdk-devel.x86_64 \
&& yum clean all

ENV JAVA_HOME_8_X64=/usr/lib/jvm/java
ENV JAVA_HOME=$JAVA_HOME_8_X64

# Install SWIG
RUN curl -sLk https://sourceforge.net/projects/swig/files/swig/swig-4.0.2/swig-4.0.2.tar.gz/download -o swig.tar.gz \
&& tar -xzf swig.tar.gz \
&& cd swig-4.0.2 \
&& ./configure --prefix=/usr/local --without-pcre \
&& make \
&& make install \
&& cd .. \
&& rm -f ./swig.tar.gz \
&& rm -rf ./swig-4.0.2

# Install miniforge
RUN curl -sL "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-$(uname -m).sh" -o miniforge.sh \
&& chmod +x miniforge.sh \
&& ./miniforge.sh -b -p /opt/miniforge \
&& rm -f ./miniforge.sh \
&& /opt/miniforge/bin/conda clean -a -y \
&& chmod -R 777 /opt/miniforge

ENV CONDA=/opt/miniforge/

WORKDIR /vsts

COPY ./start_azure.sh .
RUN chmod +x start_azure.sh

CMD ["./start_azure.sh"]
93 changes: 93 additions & 0 deletions dockers/manylinux_2_28_x86_64/start_azure.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/bin/bash
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file was exactly copied from https://github.com/guolinke/lightgbm-ci-docker/blob/master/dockers/ubuntu-14.04/start_azure.sh. I didn't change anything ini it.

set -e

export VSO_AGENT_IGNORE=_,MAIL,OLDPWD,PATH,PWD,VSTS_AGENT,VSTS_ACCOUNT,VSTS_TOKEN_FILE,VSTS_TOKEN,VSTS_POOL,VSTS_WORK,VSO_AGENT_IGNORE
if [ -n "$VSTS_AGENT_IGNORE" ]; then
export VSO_AGENT_IGNORE=$VSO_AGENT_IGNORE,VSTS_AGENT_IGNORE,$VSTS_AGENT_IGNORE
fi

if [ -e /vsts/agent -a ! -e /vsts/.configure ]; then
trap 'kill -SIGINT $!; exit 130' INT
trap 'kill -SIGTERM $!; exit 143' TERM
/vsts/agent/bin/Agent.Listener run & wait $!
exit $?
fi

if [ -z "$VSTS_ACCOUNT" ]; then
echo 1>&2 error: missing VSTS_ACCOUNT environment variable
exit 1
fi

if [ -z "$VSTS_TOKEN_FILE" ]; then
if [ -z "$VSTS_TOKEN" ]; then
echo 1>&2 error: missing VSTS_TOKEN environment variable
exit 1
fi
VSTS_TOKEN_FILE=/vsts/.token
echo -n $VSTS_TOKEN > "$VSTS_TOKEN_FILE"
fi
unset VSTS_TOKEN

if [ -n "$VSTS_AGENT" ]; then
export VSTS_AGENT="$(eval echo $VSTS_AGENT)"
fi

if [ -n "$VSTS_WORK" ]; then
export VSTS_WORK="$(eval echo $VSTS_WORK)"
mkdir -p "$VSTS_WORK"
fi

touch /vsts/.configure
rm -rf /vsts/agent
mkdir /vsts/agent
cd /vsts/agent

web-server() {
while true; do
printf 'HTTP/1.1 302 Found\r\nLocation: https://'$VSTS_ACCOUNT'.visualstudio.com/_admin/_AgentPool\r\n\r\n' | nc -l -p 80 -q 0 > /dev/null
done
}

cleanup() {
if [ -e config.sh ]; then
./bin/Agent.Listener remove --unattended \
--auth PAT \
--token $(cat "$VSTS_TOKEN_FILE")
fi
}

trap 'cleanup; exit 130' INT
trap 'cleanup; exit 143' TERM

echo Determining matching VSTS agent...
VSTS_AGENT_RESPONSE=$(curl -LsS \
-u user:$(cat "$VSTS_TOKEN_FILE") \
-H 'Accept:application/json;api-version=3.0-preview' \
"https://$VSTS_ACCOUNT.visualstudio.com/_apis/distributedtask/packages/agent?platform=linux-x64")

if echo "$VSTS_AGENT_RESPONSE" | jq . >/dev/null 2>&1; then
VSTS_AGENT_URL=$(echo "$VSTS_AGENT_RESPONSE" \
| jq -r '.value | map([.version.major,.version.minor,.version.patch,.downloadUrl]) | sort | .[length-1] | .[3]')
fi

if [ -z "$VSTS_AGENT_URL" -o "$VSTS_AGENT_URL" == "null" ]; then
echo 1>&2 error: could not determine a matching VSTS agent - check that account \'$VSTS_ACCOUNT\' is correct and the token is valid for that account
exit 1
fi

echo Downloading and installing VSTS agent...
curl -LsS $VSTS_AGENT_URL | tar -xz --no-same-owner & wait $!

source ./env.sh

./bin/Agent.Listener configure --unattended \
--agent "${VSTS_AGENT:-$(hostname)}" \
--url "https://$VSTS_ACCOUNT.visualstudio.com" \
--auth PAT \
--token $(cat "$VSTS_TOKEN_FILE") \
--pool "${VSTS_POOL:-Default}" \
--work "${VSTS_WORK:-_work}" \
--replace & wait $!

web-server &
./bin/Agent.Listener run & wait $!