gpuceleryworker.dockerfile 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. FROM nvidia/cuda:11.7.0-cudnn8-runtime-ubuntu20.04
  2. # ensure local python is preferred over distribution python
  3. ENV PATH /usr/local/bin:$PATH
  4. # http://bugs.python.org/issue19846
  5. # > At the moment, setting "LANG=C" on a Linux system *fundamentally breaks Python 3*, and that's not OK.
  6. ENV LANG C.UTF-8
  7. RUN apt-get update
  8. # runtime dependencies
  9. RUN set -eux; \
  10. apt-get install -y \
  11. ca-certificates \
  12. tzdata \
  13. ;
  14. ENV GPG_KEY A035C8C19219BA821ECEA86B64E628F8D684696D
  15. ENV PYTHON_VERSION 3.10.10
  16. RUN apt-get update && \
  17. set -eux; \
  18. \
  19. apt-get install -y \
  20. build-essential\
  21. wget \
  22. curl \
  23. tar \
  24. xz-utils\
  25. make \
  26. cmake \
  27. zlib1g-dev \
  28. libssl-dev \
  29. libssl1.1 || sudo apt install libssl1.0 \
  30. software-properties-common \
  31. libgl1-mesa-glx libsm6 libxrender1 libxext-dev\
  32. ; \
  33. \
  34. wget -O python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz"; \
  35. wget -O python.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc"; \
  36. GNUPGHOME="$(mktemp -d)"; export GNUPGHOME; \
  37. gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys "$GPG_KEY"; \
  38. gpg --batch --verify python.tar.xz.asc python.tar.xz; \
  39. command -v gpgconf > /dev/null && gpgconf --kill all || :; \
  40. rm -rf "$GNUPGHOME" python.tar.xz.asc; \
  41. mkdir -p /usr/src/python; \
  42. tar --extract --directory /usr/src/python --strip-components=1 --file python.tar.xz; \
  43. rm python.tar.xz; \
  44. \
  45. cd /usr/src/python; \
  46. # gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \
  47. ./configure \
  48. #--build="$gnuArch" \
  49. --enable-loadable-sqlite-extensions \
  50. --enable-optimizations \
  51. --enable-option-checking=fatal \
  52. --enable-shared \
  53. --with-lto \
  54. --with-system-expat \
  55. --without-ensurepip \
  56. ; \
  57. nproc="$(nproc)"; \
  58. # set thread stack size to 1MB so we don't segfault before we hit sys.getrecursionlimit()
  59. # https://github.com/alpinelinux/aports/commit/2026e1259422d4e0cf92391ca2d3844356c649d0
  60. EXTRA_CFLAGS="-DTHREAD_STACK_SIZE=0x100000"; \
  61. LDFLAGS="-Wl,--strip-all"; \
  62. make -j "$nproc" \
  63. "EXTRA_CFLAGS=${EXTRA_CFLAGS:-}" \
  64. "LDFLAGS=${LDFLAGS:-}" \
  65. "PROFILE_TASK=${PROFILE_TASK:-}" \
  66. ; \
  67. # https://github.com/docker-library/python/issues/784
  68. # prevent accidental usage of a system installed libpython of the same version
  69. rm python; \
  70. make -j "$nproc" \
  71. "EXTRA_CFLAGS=${EXTRA_CFLAGS:-}" \
  72. "LDFLAGS=${LDFLAGS:--Wl},-rpath='\$\$ORIGIN/../lib'" \
  73. "PROFILE_TASK=${PROFILE_TASK:-}" \
  74. python \
  75. ; \
  76. make install; \
  77. \
  78. cd /; \
  79. rm -rf /usr/src/python; \
  80. \
  81. find /usr/local -depth \
  82. \( \
  83. \( -type d -a \( -name test -o -name tests -o -name idle_test \) \) \
  84. -o \( -type f -a \( -name '*.pyc' -o -name '*.pyo' -o -name 'libpython*.a' \) \) \
  85. \) -exec rm -rf '{}' + \
  86. ; \
  87. \
  88. find /usr/local -type f -executable -not \( -name '*tkinter*' \) -exec scanelf --needed --nobanner --format '%n#p' '{}' ';' \
  89. | tr ',' '\n' \
  90. | sort -u \
  91. | awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
  92. | xargs -rt apk add --no-network --virtual .python-rundeps \
  93. ; \
  94. # apk del --no-network .build-deps; \
  95. \
  96. python3 --version
  97. # make some useful symlinks that are expected to exist ("/usr/local/bin/python" and friends)
  98. RUN set -eux; \
  99. for src in idle3 pydoc3 python3 python3-config; do \
  100. dst="$(echo "$src" | tr -d 3)"; \
  101. [ -s "/usr/local/bin/$src" ]; \
  102. [ ! -e "/usr/local/bin/$dst" ]; \
  103. ln -svT "$src" "/usr/local/bin/$dst"; \
  104. done
  105. # if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
  106. ENV PYTHON_PIP_VERSION 22.3.1
  107. # https://github.com/docker-library/python/issues/365
  108. ENV PYTHON_SETUPTOOLS_VERSION 65.5.1
  109. # https://github.com/pypa/get-pip
  110. ENV PYTHON_GET_PIP_URL https://github.com/pypa/get-pip/raw/1a96dc5acd0303c4700e02655aefd3bc68c78958/public/get-pip.py
  111. ENV PYTHON_GET_PIP_SHA256 d1d09b0f9e745610657a528689ba3ea44a73bd19c60f4c954271b790c71c2653
  112. RUN curl -O https://bootstrap.pypa.io/get-pip.py && \
  113. python get-pip.py && \
  114. rm get-pip.py \
  115. \
  116. pip --version
  117. RUN sed -i 's/^#force_color_prompt=yes/force_color_prompt=yes/' ~/.bashrc && \
  118. # above enable color prompt of docker in terminal
  119. # set alias
  120. echo "alias nv='nvidia-smi'" >> ~/.bash_aliases && \
  121. echo "alias wnv='watch -n 1 nvidia-smi'" >> ~/.bash_aliases && \
  122. echo "alias wwnv='watch -n 0.1 nvidia-smi'" >> ~/.bash_aliases
  123. RUN python3 --version
  124. WORKDIR /app/
  125. RUN curl -sSL https://install.python-poetry.org | POETRY_HOME=/opt/poetry python3 && \
  126. cd /usr/local/bin && \
  127. ln -s /opt/poetry/bin/poetry && \
  128. poetry config virtualenvs.create false
  129. COPY ./app/gpuproject.toml /app/pyproject.toml
  130. ARG INSTALL_DEV=false
  131. RUN bash -c "if [ $INSTALL_DEV == 'true' ] ; then poetry install --no-root ; else poetry install --no-root --no-dev ; fi"
  132. ENV C_FORCE_ROOT=1
  133. COPY ./app /app
  134. WORKDIR /app
  135. COPY /${CELERY_ZIP_STORAGE} /app/${CELERY_ZIP_STORAGE}
  136. COPY /${CELERY_ZIP_STORAGE} /app/${CELERY_ZIP_STORAGE}
  137. COPY ./app/worker-start.sh /worker-start.sh
  138. RUN chmod +x /worker-start.sh
  139. CMD ["bash", "/worker-start.sh"]