Skip to content

Commit

Permalink
[ci] Auto generate manylinux dockerfile (#3699)
Browse files Browse the repository at this point in the history
* Add generation for manylinux dockerfile

* Auto Format

* Incorporate comments

* Auto Format

Co-authored-by: Taichi Gardener <taichigardener@gmail.com>
  • Loading branch information
qiao-bo and taichi-gardener committed Dec 7, 2021
1 parent 831683e commit 4fb0ce6
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 25 deletions.
14 changes: 6 additions & 8 deletions ci/Dockerfile.manylinux.cpu → ci/Dockerfile.manylinux2014.cpu
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# This file is generated by python Dockerfile_generator.py -o manylinux2014 -t cpu
# Taichi Dockerfile (CPU only) for Manylinux2014 compliant
FROM quay.io/pypa/manylinux2014_x86_64
FROM quay.io/pypa/manylinux2014_x86_64

LABEL maintainer="https://github.com/taichi-dev"

Expand All @@ -12,17 +13,14 @@ RUN yum check-update && \
# Build LLVM/Clang 10 from source
WORKDIR /
RUN wget https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/llvm-10.0.0.src.tar.xz
RUN tar -xf llvm-10.0.0.src.tar.xz && \
rm llvm-10.0.0.src.tar.xz
RUN tar -xf llvm-10.0.0.src.tar.xz && rm llvm-10.0.0.src.tar.xz
RUN wget https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/clang-10.0.0.src.tar.xz
RUN tar -xf clang-10.0.0.src.tar.xz && \
rm clang-10.0.0.src.tar.xz
RUN tar -xf clang-10.0.0.src.tar.xz && rm clang-10.0.0.src.tar.xz
RUN cp -r clang-10.0.0.src llvm-10.0.0.src/tools/clang

WORKDIR /llvm-10.0.0.src/build
RUN cmake .. -DLLVM_ENABLE_RTTI:BOOL=ON -DBUILD_SHARED_LIBS:BOOL=OFF -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_TERMINFO=OFF
RUN make -j 8 && \
make install
RUN make -j 8 && make install
ENV CC="/usr/local/bin/clang"
ENV CXX="/usr/local/bin/clang++"

Expand All @@ -49,7 +47,7 @@ RUN conda create -n py37 python=3.7 -y
RUN conda create -n py38 python=3.8 -y
RUN conda create -n py39 python=3.9 -y

# Load scripts for build the wheel
# Load scripts for build and test
WORKDIR /home/dev/scripts
COPY ci/scripts/manylinux_build_wheel.sh manylinux_build_wheel.sh

Expand Down
2 changes: 2 additions & 0 deletions ci/Dockerfile.ubuntu.18.04
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# This file is generated by python Dockerfile_generator.py -o ubuntu -t gpu
# Taichi Dockerfile for development
FROM nvidia/cudagl:11.2.2-devel-ubuntu18.04
# Use 11.2 instead of 11.4 to avoid forward compatibility issue on Nvidia driver 460

ENV NVIDIA_DRIVER_CAPABILITIES compute,graphics,utility

ENV DEBIAN_FRONTEND=noninteractive

LABEL maintainer="https://github.com/taichi-dev"

RUN apt-get update && \
Expand Down
2 changes: 2 additions & 0 deletions ci/Dockerfile.ubuntu.18.04.cpu
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# This file is generated by python Dockerfile_generator.py -o ubuntu -t cpu
# Taichi Dockerfile for development
FROM ubuntu:18.04

ENV DEBIAN_FRONTEND=noninteractive

LABEL maintainer="https://github.com/taichi-dev"

RUN apt-get update && \
Expand Down
2 changes: 2 additions & 0 deletions ci/Dockerfile.ubuntu.20.04
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# This file is generated by python Dockerfile_generator.py -o ubuntu -t gpu
# Taichi Dockerfile for development
FROM nvidia/cudagl:11.2.2-devel-ubuntu20.04
# Use 11.2 instead of 11.4 to avoid forward compatibility issue on Nvidia driver 460

ENV NVIDIA_DRIVER_CAPABILITIES compute,graphics,utility

ENV DEBIAN_FRONTEND=noninteractive

LABEL maintainer="https://github.com/taichi-dev"

RUN apt-get update && \
Expand Down
2 changes: 2 additions & 0 deletions ci/Dockerfile.ubuntu.20.04.cpu
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# This file is generated by python Dockerfile_generator.py -o ubuntu -t cpu
# Taichi Dockerfile for development
FROM ubuntu:20.04

ENV DEBIAN_FRONTEND=noninteractive

LABEL maintainer="https://github.com/taichi-dev"

RUN apt-get update && \
Expand Down
99 changes: 82 additions & 17 deletions ci/Dockerfile_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,38 @@
OS = {
"windows": (),
"macos": (),
"manylinux2014": ("", ),
"ubuntu": (
"18.04",
"20.04",
)
}
HARDWARE = ("cpu", "gpu")

HEAD_BLOCK = """# This file is generated by python Dockerfile_generator.py -o {os} -t {target}
"""

CPU_BASE_BLOCK = """# Taichi Dockerfile for development
FROM {os}:{version}
"""

CPU_MANYLINUX_BASE_BLOCK = """# Taichi Dockerfile (CPU only) for Manylinux2014 compliant
FROM quay.io/pypa/manylinux2014_x86_64
"""

GPU_BASE_BLOCK = """# Taichi Dockerfile for development
FROM nvidia/cudagl:11.2.2-devel-ubuntu{version}
# Use 11.2 instead of 11.4 to avoid forward compatibility issue on Nvidia driver 460
"""

CPU_YUM_INSTALL_BLOCK = """
RUN yum check-update && \\
yum install -y git \\
cmake \\
wget \\
libXrandr
"""

CPU_APT_INSTALL_BLOCK = """
RUN apt-get update && \\
apt-get install -y software-properties-common \\
Expand Down Expand Up @@ -77,8 +93,11 @@
ENV NVIDIA_DRIVER_CAPABILITIES compute,graphics,utility
"""

MAINTAINER_BLOCK = """
DEBIAN_NONINTERACTIVE_BLOCK = """
ENV DEBIAN_FRONTEND=noninteractive
"""

MAINTAINER_BLOCK = """
LABEL maintainer="https://github.com/taichi-dev"
"""

Expand All @@ -104,6 +123,33 @@
ENV CXX="clang++-10"
"""

LLVM_CLANG_FROM_SOURCE_BLOCK = """
# Build LLVM/Clang 10 from source
WORKDIR /
RUN wget https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/llvm-10.0.0.src.tar.xz
RUN tar -xf llvm-10.0.0.src.tar.xz && \
rm llvm-10.0.0.src.tar.xz
RUN wget https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/clang-10.0.0.src.tar.xz
RUN tar -xf clang-10.0.0.src.tar.xz && \
rm clang-10.0.0.src.tar.xz
RUN cp -r clang-10.0.0.src llvm-10.0.0.src/tools/clang
WORKDIR /llvm-10.0.0.src/build
RUN cmake .. -DLLVM_ENABLE_RTTI:BOOL=ON -DBUILD_SHARED_LIBS:BOOL=OFF -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_TERMINFO=OFF
RUN make -j 8 && \
make install
ENV CC="/usr/local/bin/clang"
ENV CXX="/usr/local/bin/clang++"
"""

GCC_LINK_BLOCK = """
# Link gcc 10 to build Taichi
WORKDIR /usr/lib/gcc/x86_64-redhat-linux/
RUN ln -s /opt/rh/devtoolset-10/root/usr/lib/gcc/x86_64-redhat-linux/10 10
# Check gcc-10 is used
RUN clang++ -v
"""

USER_BLOCK = """
# Create non-root user for running the container
RUN useradd -ms /bin/bash dev
Expand Down Expand Up @@ -227,29 +273,47 @@ def main(arguments=None):
metavar="\b",
)
args = parser.parse_args()

pwd = Path(__file__).resolve().parent

head_block = HEAD_BLOCK.format(os=args.os, target=args.target)

if args.target == "cpu":
info("Generating Dockerfile(s) for CPU.")

def f(os: str, version: str) -> str:
info(f"OS: {os}, version: {version}")
base_block = CPU_BASE_BLOCK.format(os=os, version=version)
scripts_block = SCRIPTS_BLOCK.format(
script=f"{os}_build_test_cpu.sh")
install_block = CPU_APT_INSTALL_BLOCK

# ubuntu 18.04 needs special treatments
if os == "ubuntu" and version == "18.04":
install_block = install_block.rstrip() + """ \\
if os == "manylinux2014":
base_block = CPU_MANYLINUX_BASE_BLOCK
install_block = CPU_YUM_INSTALL_BLOCK
scripts_block = SCRIPTS_BLOCK.format(
script=f"manylinux_build_wheel.sh")

dockerfile = reduce(
lambda x, y: x + y,
(head_block, base_block, MAINTAINER_BLOCK, install_block,
LLVM_CLANG_FROM_SOURCE_BLOCK, GCC_LINK_BLOCK, USER_BLOCK,
CONDA_BLOCK, scripts_block))

filename = pwd / f"Dockerfile.{os}.cpu"
else:
base_block = CPU_BASE_BLOCK.format(os=os, version=version)
install_block = CPU_APT_INSTALL_BLOCK
scripts_block = SCRIPTS_BLOCK.format(
script=f"{os}_build_test_cpu.sh")
# ubuntu 18.04 needs special treatments
if os == "ubuntu" and version == "18.04":
install_block = install_block.rstrip() + """ \\
zlib1g-dev"""

dockerfile = reduce(
lambda x, y: x + y,
(base_block, MAINTAINER_BLOCK, install_block, CMAKE_BLOCK,
LLVM_BLOCK, USER_BLOCK, CONDA_BLOCK, scripts_block))
filename = pwd / f"Dockerfile.{os}.{version}.cpu"
dockerfile = reduce(
lambda x, y: x + y,
(head_block, base_block, DEBIAN_NONINTERACTIVE_BLOCK,
MAINTAINER_BLOCK, install_block, CMAKE_BLOCK, LLVM_BLOCK,
USER_BLOCK, CONDA_BLOCK, scripts_block))

filename = pwd / f"Dockerfile.{os}.{version}.cpu"

info(f"Storing at: {filename}")
with filename.open("w") as fp:
fp.write(dockerfile)
Expand All @@ -270,9 +334,10 @@ def f(os: str, version: str) -> str:

dockerfile = reduce(
lambda x, y: x + y,
(base_block, NVIDIA_DRIVER_CAPABILITIES_BLOCK,
MAINTAINER_BLOCK, install_block, CMAKE_BLOCK, LLVM_BLOCK,
VULKAN_BLOCK, USER_BLOCK, CONDA_BLOCK, scripts_block))
(head_block, base_block, NVIDIA_DRIVER_CAPABILITIES_BLOCK,
DEBIAN_NONINTERACTIVE_BLOCK, MAINTAINER_BLOCK, install_block,
CMAKE_BLOCK, LLVM_BLOCK, VULKAN_BLOCK, USER_BLOCK,
CONDA_BLOCK, scripts_block))
filename = pwd / f"Dockerfile.{os}.{version}"
info(f"Storing at: {filename}")
with (filename).open("w") as fp:
Expand Down

0 comments on commit 4fb0ce6

Please sign in to comment.