SHARE
    TWEET
    ferrybig

    Node & Python from source Dockerfile

    Oct 24th, 2024
    563
    0
    Never
    Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
    text 8.93 KB | None | 0 0
    1. FROM debian:bookworm-slim
    2. # ensure local python is preferred over distribution python
    3. ENV PATH /usr/local/bin:$PATH
    4. # cannot remove LANG even though https://bugs.python.org/issue19846 is fixed
    5. # last attempted removal of LANG broke many users:
    6. # https://github.com/docker-library/python/pull/570
    7. ENV LANG C.UTF-8
    8. # runtime dependencies
    9. RUN set -eux; \
    10. apt-get update; \
    11. apt-get install -y --no-install-recommends \
    12. ca-certificates \
    13. netbase \
    14. tzdata \
    15. ; \
    16. rm -rf /var/lib/apt/lists/*
    17. ENV GPG_KEY A035C8C19219BA821ECEA86B64E628F8D684696D
    18. ENV PYTHON_VERSION 3.11.10
    19. ENV PYTHON_SHA256 07a4356e912900e61a15cb0949a06c4a05012e213ecd6b4e84d0f67aabbee372
    20. RUN set -eux; \
    21. \
    22. savedAptMark="$(apt-mark showmanual)"; \
    23. apt-get update; \
    24. apt-get install -y --no-install-recommends \
    25. dpkg-dev \
    26. gcc \
    27. gnupg \
    28. libbluetooth-dev \
    29. libbz2-dev \
    30. libc6-dev \
    31. libdb-dev \
    32. libffi-dev \
    33. libgdbm-dev \
    34. liblzma-dev \
    35. libncursesw5-dev \
    36. libreadline-dev \
    37. libsqlite3-dev \
    38. libssl-dev \
    39. make \
    40. tk-dev \
    41. uuid-dev \
    42. wget \
    43. xz-utils \
    44. zlib1g-dev \
    45. ; \
    46. \
    47. wget -O python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz"; \
    48. echo "$PYTHON_SHA256 *python.tar.xz" | sha256sum -c -; \
    49. wget -O python.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc"; \
    50. GNUPGHOME="$(mktemp -d)"; export GNUPGHOME; \
    51. gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys "$GPG_KEY"; \
    52. gpg --batch --verify python.tar.xz.asc python.tar.xz; \
    53. gpgconf --kill all; \
    54. rm -rf "$GNUPGHOME" python.tar.xz.asc; \
    55. mkdir -p /usr/src/python; \
    56. tar --extract --directory /usr/src/python --strip-components=1 --file python.tar.xz; \
    57. rm python.tar.xz; \
    58. \
    59. cd /usr/src/python; \
    60. gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \
    61. ./configure \
    62. --build="$gnuArch" \
    63. --enable-loadable-sqlite-extensions \
    64. --enable-optimizations \
    65. --enable-option-checking=fatal \
    66. --enable-shared \
    67. --with-lto \
    68. --with-ensurepip \
    69. ; \
    70. nproc="$(nproc)"; \
    71. EXTRA_CFLAGS="$(dpkg-buildflags --get CFLAGS)"; \
    72. LDFLAGS="$(dpkg-buildflags --get LDFLAGS)"; \
    73. LDFLAGS="${LDFLAGS:--Wl},--strip-all"; \
    74. make -j "$nproc" \
    75. "EXTRA_CFLAGS=${EXTRA_CFLAGS:-}" \
    76. "LDFLAGS=${LDFLAGS:-}" \
    77. ; \
    78. # https://github.com/docker-library/python/issues/784
    79. # prevent accidental usage of a system installed libpython of the same version
    80. rm python; \
    81. make -j "$nproc" \
    82. "EXTRA_CFLAGS=${EXTRA_CFLAGS:-}" \
    83. "LDFLAGS=${LDFLAGS:--Wl},-rpath='\$\$ORIGIN/../lib'" \
    84. python \
    85. ; \
    86. make install; \
    87. \
    88. cd /; \
    89. rm -rf /usr/src/python; \
    90. \
    91. find /usr/local -depth \
    92. \( \
    93. \( -type d -a \( -name test -o -name tests -o -name idle_test \) \) \
    94. -o \( -type f -a \( -name '*.pyc' -o -name '*.pyo' -o -name 'libpython*.a' \) \) \
    95. \) -exec rm -rf '{}' + \
    96. ; \
    97. \
    98. ldconfig; \
    99. \
    100. apt-mark auto '.*' > /dev/null; \
    101. apt-mark manual $savedAptMark; \
    102. find /usr/local -type f -executable -not \( -name '*tkinter*' \) -exec ldd '{}' ';' \
    103. | awk '/=>/ { so = $(NF-1); if (index(so, "/usr/local/") == 1) { next }; gsub("^/(usr/)?", "", so); printf "*%s\n", so }' \
    104. | sort -u \
    105. | xargs -r dpkg-query --search \
    106. | cut -d: -f1 \
    107. | sort -u \
    108. | xargs -r apt-mark manual \
    109. ; \
    110. apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
    111. rm -rf /var/lib/apt/lists/*; \
    112. \
    113. export PYTHONDONTWRITEBYTECODE=1; \
    114. python3 --version; \
    115. \
    116. pip3 install \
    117. --disable-pip-version-check \
    118. --no-cache-dir \
    119. --no-compile \
    120. 'setuptools==65.5.1' \
    121. wheel \
    122. ; \
    123. pip3 --version
    124. # make some useful symlinks that are expected to exist ("/usr/local/bin/python" and friends)
    125. RUN set -eux; \
    126. for src in idle3 pip3 pydoc3 python3 python3-config; do \
    127. dst="$(echo "$src" | tr -d 3)"; \
    128. [ -s "/usr/local/bin/$src" ]; \
    129. [ ! -e "/usr/local/bin/$dst" ]; \
    130. ln -svT "$src" "/usr/local/bin/$dst"; \
    131. done
    132. RUN groupadd --gid 1000 node \
    133. && useradd --uid 1000 --gid node --shell /bin/bash --create-home node
    134. ENV NODE_VERSION 20.18.0
    135. RUN ARCH= OPENSSL_ARCH= && dpkgArch="$(dpkg --print-architecture)" \
    136. && case "${dpkgArch##*-}" in \
    137. amd64) ARCH='x64' OPENSSL_ARCH='linux-x86_64';; \
    138. ppc64el) ARCH='ppc64le' OPENSSL_ARCH='linux-ppc64le';; \
    139. s390x) ARCH='s390x' OPENSSL_ARCH='linux*-s390x';; \
    140. arm64) ARCH='arm64' OPENSSL_ARCH='linux-aarch64';; \
    141. armhf) ARCH='armv7l' OPENSSL_ARCH='linux-armv4';; \
    142. i386) ARCH='x86' OPENSSL_ARCH='linux-elf';; \
    143. *) echo "unsupported architecture"; exit 1 ;; \
    144. esac \
    145. && set -ex \
    146. # libatomic1 for arm
    147. && apt-get update && apt-get install -y ca-certificates curl wget gnupg dirmngr xz-utils libatomic1 --no-install-recommends \
    148. && rm -rf /var/lib/apt/lists/* \
    149. # use pre-existing gpg directory, see https://github.com/nodejs/docker-node/pull/1895#issuecomment-1550389150
    150. && export GNUPGHOME="$(mktemp -d)" \
    151. # gpg keys listed at https://github.com/nodejs/node#release-keys
    152. && for key in \
    153. 4ED778F539E3634C779C87C6D7062848A1AB005C \
    154. 141F07595B7B3FFE74309A937405533BE57C7D57 \
    155. 74F12602B6F1C4E913FAA37AD3A89613643B6201 \
    156. DD792F5973C6DE52C432CBDAC77ABFA00DDBF2B7 \
    157. CC68F5A3106FF448322E48ED27F5E38D5B0A215F \
    158. 8FCCA13FEF1D0C2E91008E09770F7A9A5AE15600 \
    159. 890C08DB8579162FEE0DF9DB8BEAB4DFCF555EF4 \
    160. C82FA3AE1CBEDC6BE46B9360C43CEC45C17AB93C \
    161. 108F52B48DB57BB0CC439B2997B01419BD92F80A \
    162. A363A499291CBBC940DD62E41F10027AF002F8B0 \
    163. ; do \
    164. gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys "$key" || \
    165. gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key" ; \
    166. done \
    167. && curl -fsSLO --compressed "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-$ARCH.tar.xz" \
    168. && curl -fsSLO --compressed "https://nodejs.org/dist/v$NODE_VERSION/SHASUMS256.txt.asc" \
    169. && gpg --batch --decrypt --output SHASUMS256.txt SHASUMS256.txt.asc \
    170. && gpgconf --kill all \
    171. && rm -rf "$GNUPGHOME" \
    172. && grep " node-v$NODE_VERSION-linux-$ARCH.tar.xz\$" SHASUMS256.txt | sha256sum -c - \
    173. && tar -xJf "node-v$NODE_VERSION-linux-$ARCH.tar.xz" -C /usr/local --strip-components=1 --no-same-owner \
    174. && rm "node-v$NODE_VERSION-linux-$ARCH.tar.xz" SHASUMS256.txt.asc SHASUMS256.txt \
    175. # Remove unused OpenSSL headers to save ~34MB. See this NodeJS issue: https://github.com/nodejs/node/issues/46451
    176. && find /usr/local/include/node/openssl/archs -mindepth 1 -maxdepth 1 ! -name "$OPENSSL_ARCH" -exec rm -rf {} \; \
    177. && apt-mark auto '.*' > /dev/null \
    178. && find /usr/local -type f -executable -exec ldd '{}' ';' \
    179. | awk '/=>/ { so = $(NF-1); if (index(so, "/usr/local/") == 1) { next }; gsub("^/(usr/)?", "", so); print so }' \
    180. | sort -u \
    181. | xargs -r dpkg-query --search \
    182. | cut -d: -f1 \
    183. | sort -u \
    184. | xargs -r apt-mark manual \
    185. && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
    186. && ln -s /usr/local/bin/node /usr/local/bin/nodejs \
    187. # smoke tests
    188. && node --version \
    189. && npm --version
    190. ENV YARN_VERSION 1.22.22
    191. RUN set -ex \
    192. && savedAptMark="$(apt-mark showmanual)" \
    193. && apt-get update && apt-get install -y ca-certificates curl wget gnupg dirmngr --no-install-recommends \
    194. && rm -rf /var/lib/apt/lists/* \
    195. # use pre-existing gpg directory, see https://github.com/nodejs/docker-node/pull/1895#issuecomment-1550389150
    196. && export GNUPGHOME="$(mktemp -d)" \
    197. && for key in \
    198. 6A010C5166006599AA17F08146C2130DFD2497F5 \
    199. ; do \
    200. gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys "$key" || \
    201. gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key" ; \
    202. done \
    203. && curl -fsSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz" \
    204. && curl -fsSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz.asc" \
    205. && gpg --batch --verify yarn-v$YARN_VERSION.tar.gz.asc yarn-v$YARN_VERSION.tar.gz \
    206. && gpgconf --kill all \
    207. && rm -rf "$GNUPGHOME" \
    208. && mkdir -p /opt \
    209. && tar -xzf yarn-v$YARN_VERSION.tar.gz -C /opt/ \
    210. && ln -s /opt/yarn-v$YARN_VERSION/bin/yarn /usr/local/bin/yarn \
    211. && ln -s /opt/yarn-v$YARN_VERSION/bin/yarnpkg /usr/local/bin/yarnpkg \
    212. && rm yarn-v$YARN_VERSION.tar.gz.asc yarn-v$YARN_VERSION.tar.gz \
    213. && apt-mark auto '.*' > /dev/null \
    214. && { [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark > /dev/null; } \
    215. && find /usr/local -type f -executable -exec ldd '{}' ';' \
    216. | awk '/=>/ { so = $(NF-1); if (index(so, "/usr/local/") == 1) { next }; gsub("^/(usr/)?", "", so); print so }' \
    217. | sort -u \
    218. | xargs -r dpkg-query --search \
    219. | cut -d: -f1 \
    220. | sort -u \
    221. | xargs -r apt-mark manual \
    222. && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
    223. # smoke test
    224. && yarn --version \
    225. && rm -rf /tmp/*
    Advertisement
    Add Comment
    Please, Sign In to add comment
    Public Pastes
    We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
    Not a member of Pastebin yet?
    Sign Up, it unlocks many cool features!

    AltStyle によって変換されたページ (->オリジナル) /