forked from aws/aws-lambda-python-runtime-interface-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile.echo.centos
116 lines (98 loc) · 3.64 KB
/
Dockerfile.echo.centos
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
ARG DISTRO_VERSION
# Stage 1 - bundle base image + runtime interface client
# Grab a fresh copy of the image and install Python
FROM centos:${DISTRO_VERSION} AS python-centos-builder
ARG RUNTIME_VERSION
# Install apt dependencies
RUN yum install -y \
gcc \
gcc-c++ \
tar \
gzip \
make \
autoconf \
automake \
freetype-devel \
yum-utils \
findutils \
openssl-devel \
wget \
libffi-devel \
sqlite-devel
RUN RUNTIME_LATEST_VERSION=${RUNTIME_VERSION}.$(curl -s https://www.python.org/ftp/python/ | \
grep -oE "href=\"$(echo ${RUNTIME_VERSION} | sed "s/\\./\\\./g")\.[0-9]+" | \
cut -d. -f3 | \
sort -rn | \
while read -r patch; do \
$(wget -c https://www.python.org/ftp/python/${RUNTIME_VERSION}.$patch/Python-${RUNTIME_VERSION}.$patch.tgz -O Python-${RUNTIME_VERSION}.$patch.tgz); \
[ $? -eq 0 ] && echo $patch && break; \
done) \
&& tar -xzf Python-${RUNTIME_LATEST_VERSION}.tgz \
&& cd Python-${RUNTIME_LATEST_VERSION} \
&& ./configure --prefix=/usr/local --enable-shared \
&& make \
&& make install \
&& ln -s /usr/local/bin/python${RUNTIME_VERSION} /usr/local/bin/python${RUNTIME_LATEST_VERSION}
# Stage 2 - clean python build dependencies
FROM centos:${DISTRO_VERSION} AS python-centos
RUN yum install -y \
libffi-devel
# Copy the compiled python to /usr/local
COPY --from=python-centos-builder /usr/local /usr/local
ENV LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
# Stage 3 - build function and dependencies
FROM python-centos-builder AS build-image
ARG RUNTIME_VERSION
# Install aws-lambda-cpp build dependencies
RUN yum install -y \
tar \
gzip \
make \
autoconf \
automake \
libtool \
libcurl-devel \
gcc-c++ \
wget
# Install a modern CMake
RUN wget --quiet -O cmake-install https://github.com/Kitware/CMake/releases/download/v3.18.4/cmake-3.18.4-Linux-x86_64.sh && \
sh cmake-install --skip-license --prefix=/usr --exclude-subdirectory;
ENV PATH=/usr/local/bin:$PATH
ENV LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
# Include global args in this stage of the build
ARG RIC_BUILD_DIR="/home/build/"
# Create function directory
RUN mkdir -p ${RIC_BUILD_DIR}
# Copy function code and Runtime Interface Client .tgz
WORKDIR ${RIC_BUILD_DIR}
COPY . .
RUN make init build && \
mv ./dist/awslambdaric-*.tar.gz ./dist/awslambdaric-test.tar.gz
# Include global args in this stage of the build
ARG FUNCTION_DIR="/home/app/"
# Create function directory
RUN mkdir -p ${FUNCTION_DIR}
# Copy function code
COPY test/integration/test-handlers/echo/* ${FUNCTION_DIR}
# Copy Runtime Interface Client .tgz
RUN cp ./dist/awslambdaric-test.tar.gz ${FUNCTION_DIR}/awslambdaric-test.tar.gz
# Install the function's dependencies
WORKDIR ${FUNCTION_DIR}
ARG ENABLE_LTO=OFF
ENV ENABLE_LTO ${ENABLE_LTO}
RUN python${RUNTIME_VERSION} -m pip install \
awslambdaric-test.tar.gz \
--verbose \
--target ${FUNCTION_DIR} && \
rm awslambdaric-test.tar.gz
# Stage 4 - final runtime interface client image
# Grab a fresh copy of the Python image
FROM python-centos
# Include global arg in this stage of the build
ARG FUNCTION_DIR="/home/app/"
# Set working directory to function root directory
WORKDIR ${FUNCTION_DIR}
# Copy in the built dependencies
COPY --from=build-image ${FUNCTION_DIR} ${FUNCTION_DIR}
ENTRYPOINT [ "/usr/local/bin/python3", "-m", "awslambdaric" ]
CMD [ "app.handler" ]