Skip to content

Commit 569db97

Browse files
Docker folder
1 parent 2ede67a commit 569db97

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

layer_v3/docker/Dockerfile

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# First stage: setting the base image
2+
ARG PYTHON_VERSION=""
3+
4+
FROM public.ecr.aws/lambda/python:${PYTHON_VERSION} AS base_build
5+
6+
# Second stage: building the layer
7+
FROM base_build
8+
9+
ARG PYTHON_VERSION=""
10+
ARG PACKAGE_SUFFIX=""
11+
12+
USER root
13+
WORKDIR /tmp
14+
15+
# PACKAGE_SUFFIX = '[all]==2.0.0'
16+
# PACKAGE_SUFFIX = '[all] @ git+https://github.com/awslabs/aws-lambda-powertools-python@v2'
17+
# PACKAGE_SUFFIX = '[all]'
18+
# PACKAGE_SUFFIX = '=='2.0.0'
19+
# PACKAGE_SUFFIX = ' @ git+https://github.com/awslabs/aws-lambda-powertools-python@v2'
20+
# PACKAGE_SUFFIX = ''
21+
22+
# PYTHON_VERSION = 3.8, 3.9, 3.10, 3.11, and 3.12
23+
24+
# Installing libs based on base image; We must use dnf for AL2023 (Python 3.12+)
25+
COPY install_libraries.sh .
26+
RUN ls -la
27+
RUN chmod a+x /tmp/install_libraries.sh
28+
RUN /bin/sh /tmp/install_libraries.sh
29+
30+
# Install cython to generate native code
31+
RUN pip install --upgrade pip wheel && pip install --upgrade cython
32+
# Optimize binary size and strip debugging symbols for optimum size
33+
RUN CFLAGS="-Os -g0 -s" pip install -t /asset/python "aws-lambda-powertools${PACKAGE_SUFFIX}"
34+
35+
# Removing nonessential files
36+
RUN cd /asset/python && \
37+
# remove boto3 and botocore (already available in Lambda Runtime)
38+
rm -rf boto* && \
39+
# remove boto3 dependencies
40+
rm -rf s3transfer* *dateutil* urllib3* six* jmespath* && \
41+
# remove debugging symbols
42+
find . -name '*.so' -type f -exec strip "{}" \; && \
43+
# remove tests
44+
find . -wholename "*/tests/*" -type f -delete && \
45+
# remove python bytecode
46+
find . -regex '^.*\(__pycache__\|\.py[co]\)$' -delete

layer_v3/docker/install_libraries.sh

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/sh
2+
3+
al2_versions=("3.8" "3.9" "3.10" "3.11")
4+
5+
# Flag to indicate if the version is al2 or not
6+
is_al2=0
7+
8+
for version in "${al2_versions[@]}"; do
9+
if [ "$PYTHON_VERSION" = "$version" ]; then
10+
is_al2=1
11+
break
12+
fi
13+
done
14+
15+
if [ "$is_al2" -eq 1 ]; then
16+
yum update -y && yum install -y zip unzip wget tar gzip binutils
17+
yum install -y \
18+
boost-devel \
19+
jemalloc-devel \
20+
bison \
21+
make \
22+
gcc \
23+
gcc-c++ \
24+
flex \
25+
autoconf \
26+
zip \
27+
git \
28+
ninja-build
29+
30+
else
31+
dnf update -y && dnf install -y zip unzip wget tar gzip binutils
32+
dnf install -y \
33+
boost-devel \
34+
jemalloc-devel \
35+
bison \
36+
make \
37+
gcc \
38+
gcc-c++ \
39+
flex \
40+
autoconf \
41+
zip \
42+
git \
43+
ninja-build
44+
45+
fi

0 commit comments

Comments
 (0)