Skip to content

Commit

Permalink
Merge pull request #20 from yzewei/main
Browse files Browse the repository at this point in the history
python 3.8.0 alpine
  • Loading branch information
yzewei authored Mar 27, 2024
2 parents 00fa61e + f3c3446 commit 69fdf81
Show file tree
Hide file tree
Showing 2 changed files with 161 additions and 0 deletions.
135 changes: 135 additions & 0 deletions library/python/3.8.0-alpine/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
FROM lcr.loongnix.cn/library/alpine:3.19

LABEL maintainer="[email protected]"

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


# runtime dependencies
RUN set -eux; \
apk add --no-cache \
ca-certificates \
wget \
;

ARG PYTHON_VERSION 3.8.0
ENV PYTHON_VERSION ${PYTHON_VERSION}

RUN set -eux; \
\
apk add --no-cache --virtual .fetch-deps \
gnupg \
tar \
xz \
; \
\
wget -O python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz"; \
mkdir -p /usr/src/python && tar --extract --directory /usr/src/python --strip-components=1 --file python.tar.xz --no-same-owner && \
rm python.tar.xz; \
\
apk add --no-cache --virtual .build-deps \
bzip2-dev \
coreutils \
dpkg-dev dpkg \
expat-dev \
findutils \
gcc \
gdbm-dev \
libc-dev \
libffi-dev \
libnsl-dev \
libtirpc-dev \
linux-headers \
make \
ncurses-dev \
openssl-dev \
pax-utils \
readline-dev \
sqlite-dev \
tcl-dev \
tk \
tk-dev \
util-linux-dev \
xz-dev \
zlib-dev \
; \
\
cd /usr/src/python; \
# update config.sub && config.guess
wget -O ./config.sub "git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD"; \
wget -O ./config.guess "git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD"; \
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 \
--without-ensurepip \
; \
nproc="$(nproc)"; \
make -j "$nproc" \
# set thread stack size to 1MB so we don't segfault before we hit sys.getrecursionlimit()
# https://github.com/alpinelinux/aports/commit/2026e1259422d4e0cf92391ca2d3844356c649d0
EXTRA_CFLAGS="-DTHREAD_STACK_SIZE=0x100000" \
; \
make install; \
\
cd /; \
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 'libpython*.a' \) \) \
-o \( -type f -a -name 'wininst-*.exe' \) \
\) -exec rm -rf '{}' + \
; \
\
find /usr/local -type f -executable -not \( -name '*tkinter*' \) -exec scanelf --needed --nobanner --format '%n#p' '{}' ';' \
| tr ',' '\n' \
| sort -u \
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
| xargs -rt apk add --no-network --virtual .python-rundeps \
; \
apk del --no-network .build-deps; \
\
python3 --version

# make some useful symlinks that are expected to exist ("/usr/local/bin/python" and friends)
RUN set -eux; \
for src in idle3 pydoc3 python3 python3-config; do \
dst="$(echo "$src" | tr -d 3)"; \
[ -s "/usr/local/bin/$src" ]; \
[ ! -e "/usr/local/bin/$dst" ]; \
ln -svT "$src" "/usr/local/bin/$dst"; \
done

# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
ENV PYTHON_PIP_VERSION 19.3.1
# https://github.com/pypa/get-pip
ARG PYTHON_GET_PIP_URL https://github.com/pypa/get-pip/raw/ffe826207a010164265d9cc807978e3604d18ca0/get-pip.py
ENV PYTHON_GET_PIP_URL ${PYTHON_GET_PIP_URL}

RUN set -ex; \
\
wget -O get-pip.py "$PYTHON_GET_PIP_URL"; \
\
export PYTHONDONTWRITEBYTECODE=1; \
\
python get-pip.py \
--disable-pip-version-check \
--no-cache-dir \
--no-compile \
"pip==$PYTHON_PIP_VERSION" \
; \
rm -f get-pip.py; \
\
pip --version

CMD ["python3"]
26 changes: 26 additions & 0 deletions library/python/3.8.0-alpine/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# This file is generated by the template.

REGISTRY?=lcr.loongnix.cn
ORGANIZATION?=python
REPOSITORY?=python3
TAG?=3.8.0-alpine

IMAGE=$(REGISTRY)/$(ORGANIZATION)/$(REPOSITORY):$(TAG)

PYTHON_VERSION?=3.8.0
PYTHON_PIP_VERSION?=19.3.1
PYTHON_GET_PIP_URL?=https://github.com/pypa/get-pip/raw/ffe826207a010164265d9cc807978e3604d18ca0/get-pip.py

default: image

image:
docker build \
--build-arg PYTHON_VERSION=${PYTHON_VERSION} \
--build-arg PYTHON_GET_PIP_URL=${PYTHON_GET_PIP_URL} \
--build-arg http_proxy=$(http_proxy) \
--build-arg https_proxy=$(https_proxy) \
-t $(IMAGE) \
.

push:
docker push $(IMAGE)

0 comments on commit 69fdf81

Please sign in to comment.