- amazon/aws-lambda-python supports Python 3.12 (released Oct 2023), amazonlinux does not ๐ข
- (currently) no way to install
python3.12
in a standard way (i.e. viadnf
and the official package repos, AFAICT) - solutions involving pyenv or manually building Python... ๐คฎ
- multi-stage build copying the 3.12 (and potentially future versions) distribution from
aws-lambda-python
โก๏ธamazonlinux:2023
? slightly less ๐คฎ
Last active
September 4, 2024 19:31
-
-
Save darvid/6b32ce975d099382a6d323257f525b73 to your computer and use it in GitHub Desktop.
โ๏ธ ๐ Amazon Linux 2023 + Python 3.12 (containers)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# syntax=docker/dockerfile:1.9.0-labs | |
ARG PYTHON_VERSION=3.12 | |
FROM public.ecr.aws/lambda/python:${PYTHON_VERSION} AS lambda-python | |
ARG PYTHON_VERSION | |
ENV PYTHON_VERSION=${PYTHON_VERSION} | |
ARG PYTHON_VERSION | |
FROM public.ecr.aws/amazonlinux/amazonlinux:2023 AS al2023-python | |
ARG PYTHON_VERSION | |
ENV PYTHON_VERSION=${PYTHON_VERSION} | |
COPY --from=lambda-python \ | |
/var/lang/bin/python${PYTHON_VERSION} \ | |
/usr/bin/ | |
COPY --from=lambda-python \ | |
/var/lang/include/python${PYTHON_VERSION} \ | |
/usr/include/python${PYTHON_VERSION} | |
COPY --from=lambda-python \ | |
/var/lang/lib/python${PYTHON_VERSION}/lib-dynload \ | |
/usr/lib64/python${PYTHON_VERSION}/lib-dynload | |
COPY --from=lambda-python \ | |
/var/lang/lib/python${PYTHON_VERSION} \ | |
/usr/lib64/python${PYTHON_VERSION} | |
COPY --from=lambda-python \ | |
/var/lang/lib/libpython${PYTHON_VERSION}*.so* \ | |
/usr/lib64/ | |
WORKDIR /var/lang | |
RUN <<EOF | |
mkdir -p bin include lib | |
ln -s /usr/lib64/python${PYTHON_VERSION} ./lib/python${PYTHON_VERSION} | |
ln -s /usr/lib64/python${PYTHON_VERSION}/lib-dynload ./lib/python${PYTHON_VERSION}/lib-dynload | |
ln -s /usr/lib64/libpython${PYTHON_VERSION}*.so* ./lib/ | |
ln -s /usr/bin/python${PYTHON_VERSION} ./bin/python${PYTHON_VERSION} | |
ln -s /usr/bin/python${PYTHON_VERSION} ./bin/python | |
ln -s /usr/include/python${PYTHON_VERSION} ./include/python${PYTHON_VERSION} | |
EOF | |
WORKDIR / | |
# example final stage using ``scratch`` | |
ARG PYTHON_VERSION | |
FROM scratch | |
ARG PYTHON_VERSION | |
ENV PYTHON_VERSION=${PYTHON_VERSION} | |
COPY --from=build /sysroot / | |
COPY --from=build /var/lang ./var/lang | |
COPY --from=build \ | |
/var/lang/include/python${PYTHON_VERSION} \ | |
/usr/include/python${PYTHON_VERSION} | |
COPY --from=build /usr/lib64/python${PYTHON_VERSION} /usr/lib64/python${PYTHON_VERSION} | |
COPY --from=build /usr/lib64/libpython${PYTHON_VERSION}*.so* /usr/lib64/ | |
COPY --from=build /usr/lib64/python${PYTHON_VERSION}/lib-dynload /usr/lib64/python${PYTHON_VERSION}/lib-dynload | |
COPY --from=build /usr/lib64/python${PYTHON_VERSION}/site-packages /usr/lib64/python${PYTHON_VERSION}/site-packages | |
COPY --from=build /usr/bin/python${PYTHON_VERSION} /usr/bin/python${PYTHON_VERSION} | |
WORKDIR / | |
ENTRYPOINT ["/var/lang/bin/python"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment