From 895c1244da745492d0b88df75660ddc89d8a8f25 Mon Sep 17 00:00:00 2001 From: Sam Gross Date: Thu, 30 Dec 2021 13:38:34 -0800 Subject: [PATCH] Add docker files for building nogil Python --- docker/Dockerfile | 60 ++++++++++++++++++++++++++++ docker/cuda/Dockerfile | 88 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 148 insertions(+) create mode 100644 docker/Dockerfile create mode 100644 docker/cuda/Dockerfile diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 00000000000..6b3672de87c --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,60 @@ +# Copied from https://github.com/docker-library/python/blob/master/3.9/bullseye/Dockerfile + +FROM buildpack-deps:bullseye + +ARG commit + +# ensure local python is preferred over distribution python +ENV PATH /usr/local/bin:$PATH + +# http://bugs.python.org/issue19846 +# > At the moment, setting "LANG=C" on a Linux system *fundamentally breaks Python 3*, and that's not OK. +ENV LANG C.UTF-8 + +# extra dependencies (over what buildpack-deps already includes) +RUN apt-get update && apt-get install -y --no-install-recommends \ + libbluetooth-dev \ + tk-dev \ + uuid-dev \ + && rm -rf /var/lib/apt/lists/* + +RUN set -ex \ + \ + && wget -O python.tar.gz "https://github.com/colesbury/nogil/tarball/$commit" \ + && mkdir -p /usr/src/python \ + && tar -xC /usr/src/python --strip-components=1 -f python.tar.gz \ + && rm python.tar.gz \ + \ + && cd /usr/src/python \ + && gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)" \ + && ./configure \ + --build="$gnuArch" \ + --enable-loadable-sqlite-extensions \ + --enable-optimizations \ + --enable-option-checking=fatal \ + --enable-shared \ + --with-system-expat \ + --with-system-ffi \ + && make -j "$(nproc)" \ + && make install \ + && rm -rf /usr/src/python \ + \ + && find /usr/local -depth \ + \( \ + \( -type d -a \( -name test -o -name tests -o -name idle_test \) \) \ + -o \( -type f -a \( -name '*.pyc' -o -name '*.pyo' -o -name '*.a' \) \) \ + \) -exec rm -rf '{}' + \ + \ + && ldconfig \ + \ + && python3 --version + +# make some useful symlinks that are expected to exist +RUN cd /usr/local/bin \ + && ln -s idle3 idle \ + && ln -s pydoc3 pydoc \ + && ln -s python3 python \ + && ln -s python3-config python-config \ + && ln -s pip3 pip + +CMD ["python3"] diff --git a/docker/cuda/Dockerfile b/docker/cuda/Dockerfile new file mode 100644 index 00000000000..1e2bdabaaab --- /dev/null +++ b/docker/cuda/Dockerfile @@ -0,0 +1,88 @@ +# Copied from +# https://github.com/docker-library/python/blob/master/3.9/bullseye/Dockerfile +# and modified. + +FROM nvidia/cuda:11.0-devel-ubuntu20.04 + +ARG commit + +# ensure local python is preferred over distribution python +ENV PATH /usr/local/bin:$PATH + +# http://bugs.python.org/issue19846 +# > At the moment, setting "LANG=C" on a Linux system *fundamentally breaks Python 3*, and that's not OK. +ENV LANG C.UTF-8 + +# Don't ask questions during build. +ENV DEBIAN_FRONTEND=noninteractive + +# Dependencies. +RUN apt-get update && apt-get install -y --no-install-recommends \ + build-essential \ + bzip2 \ + libbluetooth-dev \ + libbz2-dev \ + libcurl4-openssl-dev \ + libdb-dev \ + libffi-dev \ + libgdbm-dev \ + liblzma-dev \ + libncurses5-dev \ + libncursesw5-dev \ + libpng-dev \ + libreadline-dev \ + libsqlite3-dev \ + libssl-dev \ + tk-dev \ + uuid-dev \ + wget \ + && rm -rf /var/lib/apt/lists/* + +RUN set -ex \ + \ + && wget --no-verbose -O python.tar.gz "https://github.com/colesbury/nogil/tarball/$commit" \ + && mkdir -p /usr/src/python \ + && tar -xC /usr/src/python --strip-components=1 -f python.tar.gz \ + && rm python.tar.gz \ + \ + && cd /usr/src/python \ + && gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)" \ + && ./configure \ + --build="$gnuArch" \ + --enable-loadable-sqlite-extensions \ + --enable-optimizations \ + --enable-option-checking=fatal \ + --enable-shared \ + --with-system-expat \ + --with-system-ffi \ + && make -j "$(nproc)" \ + && make install \ + && rm -rf /usr/src/python \ + \ + && find /usr/local -depth \ + \( \ + \( -type d -a \( -name test -o -name tests -o -name idle_test \) \) \ + -o \( -type f -a \( -name '*.pyc' -o -name '*.pyo' -o -name '*.a' \) \) \ + \) -exec rm -rf '{}' + \ + \ + && ldconfig \ + \ + && python3 --version + +# make some useful symlinks that are expected to exist +RUN cd /usr/local/bin \ + && ln -s idle3 idle \ + && ln -s pydoc3 pydoc \ + && ln -s python3 python \ + && ln -s python3-config python-config \ + && ln -s pip3 pip + +CMD ["python3"] + + +# Docker commands: +# docker rm nogil -v +# docker build -t nogil . +# docker run --gpus all --rm --name nogil nogil +# or +# docker run --gpus all -it --entrypoint /bin/bash nogil