Skip to content

Commit 33c8926

Browse files
committed
...
1 parent 34f9311 commit 33c8926

File tree

2 files changed

+27
-26
lines changed

2 files changed

+27
-26
lines changed

Dockerfile

+18-21
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# vim: ft=Dockerfile ts=4 sw=4 expandtab
1+
# vim: ft=dockerfile ts=4 sw=4 expandtab
22
###############################################################################
33
#
44
# Multi-stage Python 3.x build
@@ -47,7 +47,7 @@ RUN set -ex \
4747
&& apt update \
4848
&& apt -y upgrade \
4949
&& apt-mark unhold apt libcap2 libsemanage1 passwd \
50-
&& apt-get install --no-install-recommends -qq -y libsqlite3-0 zlib1g libexpat1 bash procps less libbz2-1.0 netcat-openbsd git binutils \
50+
&& apt-get install --no-install-recommends -qq -y ca-certificates libsqlite3-0 zlib1g libexpat1 bash procps less libbz2-1.0 netcat-openbsd git binutils \
5151
&& find /usr -type f -name "*.so" -exec strip --strip-unneeded {} + \
5252
&& apt-get remove -qq --allow-remove-essential --purge -y -qq \
5353
binutils e2fsprogs e2fslibs libx11-6 libx11-data \
@@ -65,12 +65,21 @@ LABEL stage RUNTIME
6565
###############################################################################
6666
FROM scratch as runtime
6767

68+
ENV PATH /usr/local/bin:$PATH
69+
70+
# http://bugs.python.org/issue19846
71+
# > At the moment, setting "LANG=C" on a Linux system *fundamentally breaks Python 3*, and that's not OK.
72+
ENV LANG C.UTF-8
73+
74+
COPY ./init-functions /lib/lsb/
75+
6876
COPY --from=base / /
6977

7078
###############################################################################
7179
FROM alpine as source-download
7280

7381
ARG PYTHON_VERSION
82+
ENV PYTHON_VERSION ${PYTHON_VERSION}
7483

7584
ENV SRCDIR /python
7685
RUN apk add curl
@@ -83,8 +92,6 @@ FROM runtime as build-setup
8392

8493
WORKDIR /python
8594

86-
ARG PYTHON_VERSION
87-
8895
RUN apt-get update
8996
RUN apt-get -y install --no-install-recommends \
9097
libsqlite3-dev zlib1g-dev libexpat1-dev \
@@ -94,9 +101,6 @@ RUN apt-get -y install --no-install-recommends \
94101
gcc g++ make autoconf libtool \
95102
dpkg-dev
96103

97-
# COPY --from=source-download /${PYTHON_VERSION} /python
98-
99-
100104
LABEL stage BUILD-SETUP
101105

102106
###############################################################################
@@ -110,12 +114,9 @@ ENV CFLAGS -I/usr/include/openssl
110114

111115
WORKDIR /build
112116

113-
RUN --mount=type=bind,from=source-download,target=/python,source=/python \
114-
--mount=type=cache,target=/tmp \
115-
--mount=type=cache,target=/var/tmp \
116-
--mount=type=cache,target=/var/log \
117-
--mount=type=cache,target=/root \
118-
set -ex \
117+
COPY --from=source-download /python /python
118+
119+
RUN set -ex \
119120
&& gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)" \
120121
&& [ $(( ` echo $PYTHON_VERSION | cut -d"." -f1 ` )) -lt 3 ] && BUILD_ARGS="" \
121122
; ../python/configure \
@@ -126,12 +127,7 @@ RUN --mount=type=bind,from=source-download,target=/python,source=/python \
126127
--with-system-ffi \
127128
--without-ensurepip ${BUILD_ARGS}
128129

129-
RUN --mount=type=bind,from=source-download,target=/python,source=/python \
130-
--mount=type=cache,target=/tmp \
131-
--mount=type=cache,target=/var/tmp \
132-
--mount=type=cache,target=/var/log \
133-
--mount=type=cache,target=/root \
134-
make -j $(( 1 * $( egrep '^processor[[:space:]]+:' /proc/cpuinfo | wc -l ) )) \
130+
RUN make -j $(( 1 * $( egrep '^processor[[:space:]]+:' /proc/cpuinfo | wc -l ) )) \
135131
&& make install
136132

137133
RUN set -ex \
@@ -161,7 +157,7 @@ LABEL version ${PYTHON_VERSION}
161157
FROM builder as post-build
162158

163159
# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
164-
ENV PYTHON_PIP_VERSION 19.1.1
160+
ENV PYTHON_PIP_VERSION 22.2.2
165161

166162

167163
ADD https://bootstrap.pypa.io/get-pip.py .
@@ -191,10 +187,11 @@ LABEL stage POST-BUILD
191187
LABEL version ${PYTHON_VERSION}
192188

193189
###############################################################################
194-
FROM runtime as final
190+
FROM runtime as release
195191

196192
COPY --from=post-build /usr/local /usr/local
197193
COPY --from=post-build /root/* /root/
194+
198195
RUN /sbin/ldconfig
199196

200197
LABEL stage FINAL

Makefile

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: image push-image build-image optimal
1+
.PHONY: image push-image build-image optimal buil-builder
22

33
include .version
44

@@ -9,10 +9,11 @@ TAG = ${PYTHON_VERSION}-wee
99
IMAGE_TAG = ${IMAGE}:${TAG}${TAG_SUFFIX}
1010
LATEST = ${IMAGE}:latest
1111

12-
BUILD_ARGS =
1312

1413
PLATFORMS ?= linux/amd64
1514

15+
TARGETS := --platform ${PLATFORMS}
16+
1617
ifdef PKG_PROXY
1718
PROXY_ARGS := --build-arg=http_proxy=${PKG_PROXY} --build-arg=https_proxy=${PKG_PROXY}
1819
else
@@ -43,12 +44,15 @@ endif
4344

4445
TAG_SUFFIX ?=
4546

46-
build-image:
47+
build-builder:
48+
docker buildx build ${PROXY_ARGS} ${TARGETS} --cache-from=type=registry,ref=${LATEST} --cache-to=type=registry,ref=${LATEST},mode=max -f ${DOCKERFILE} --build-arg=PYTHON_VERSION=${PYTHON_VERSION} --build-arg=BUILD_ARGS="${BUILD_ARGS}" --target builder -t ${IMAGE_TAG} .
49+
50+
build-image: build-builder
4751
@echo building ${IMAGE_TAG}
48-
docker buildx build ${PROXY_ARGS} --cache-from=type=registry,ref=${LATEST} --cache-to=type=registry,ref=${LATEST},mode=max -f ${DOCKERFILE} --build-arg=PYTHON_VERSION=${PYTHON_VERSION} --build-arg=BUILD_ARGS="${BUILD_ARGS}" --platform ${PLATFORMS} --load -t ${IMAGE_TAG} .
52+
docker buildx build ${PROXY_ARGS} ${TARGETS} --cache-from=type=registry,ref=${LATEST} -f ${DOCKERFILE} --build-arg=PYTHON_VERSION=${PYTHON_VERSION} --build-arg=BUILD_ARGS="${BUILD_ARGS}" --load -t ${IMAGE_TAG} .
4953

5054
push-image:
5155
@echo pushing ${IMAGE_TAG}
52-
docker buildx build ${PROXY_ARGS} --cache-from=type=registry,ref=${LATEST} --cache-to=type=registry,ref=${LATEST},mode=max -f ${DOCKERFILE} --build-arg=PYTHON_VERSION=${PYTHON_VERSION} --build-arg=BUILD_ARGS="${BUILD_ARGS}" --platform ${PLATFORMS} --push -t ${IMAGE_TAG} .
56+
docker buildx build ${PROXY_ARGS} ${TARGETS} --cache-from=type=registry,ref=${LATEST} -f ${DOCKERFILE} --build-arg=PYTHON_VERSION=${PYTHON_VERSION} --build-arg=BUILD_ARGS="${BUILD_ARGS}" --push -t ${IMAGE_TAG} .
5357

5458
image: push-image

0 commit comments

Comments
 (0)