-
Notifications
You must be signed in to change notification settings - Fork 26
/
Dockerfile.awslambdaric
89 lines (69 loc) · 2.96 KB
/
Dockerfile.awslambdaric
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
ARG FUNCTION_DIR="/app/"
ARG AWS_LINUX_VERSION="2022"
ARG PYTHON_VERSION="3.11.1"
ARG ARCH=
FROM ${ARCH}amazonlinux:${AWS_LINUX_VERSION} as python-layer
ARG PYTHON_VERSION
# install python
RUN yum update -y
RUN yum groupinstall "Development Tools" -y
RUN yum install libffi-devel bzip2-devel wget openssl openssl-devel sqlite-devel -y
RUN wget https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz
RUN tar -xf Python-${PYTHON_VERSION}.tgz
RUN cd Python-${PYTHON_VERSION}/ && \
./configure --enable-optimizations --enable-loadable-sqlite-extensions && \
make install
RUN ln -s /Python-${PYTHON_VERSION}/python /usr/bin/python
RUN python -m ensurepip --upgrade
RUN python -m pip install --upgrade pip
FROM ${ARCH}amazonlinux:${AWS_LINUX_VERSION} as base-layer
RUN yum groupinstall "Development Tools" -y
RUN yum install git -y
# copy python to the necessary locations
ARG PYTHON_VERSION
COPY --from=python-layer /Python-${PYTHON_VERSION} /Python-${PYTHON_VERSION}
COPY --from=python-layer /usr/local/bin /usr/local/bin
COPY --from=python-layer /usr/local/lib /usr/local/lib
RUN ln -s /Python-${PYTHON_VERSION}/python /usr/bin/python
RUN ln -s /Python-${PYTHON_VERSION}/pip3 /usr/bin/pip3
ARG FUNCTION_DIR
RUN mkdir -p ${FUNCTION_DIR}
WORKDIR ${FUNCTION_DIR}
FROM base-layer as build-layer
######## YOUR OWN SETUP PROCESS HERE ########################
# copy over requirements and install those
# COPY . .
# RUN pip install . --target "${FUNCTION_DIR}"
# copy over configuration and service code then install it
# COPY config/ ${FUNCTION_DIR}/config/
# COPY service/ ${FUNCTION_DIR}/
# RUN pip install . --target "${FUNCTION_DIR}"
######## ########################### ########################
# install lambda runtime interface client for python
RUN pip3 install awslambdaric setuptools pip --target "${FUNCTION_DIR}" --upgrade
FROM base-layer as runtime-layer
# copy in the built dependencies
ARG FUNCTION_DIR
COPY --from=build-layer ${FUNCTION_DIR} ${FUNCTION_DIR}
WORKDIR ${FUNCTION_DIR}
# (optional) add lambda runtime interface emulator
ADD https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie /usr/bin/aws-lambda-rie
RUN chmod 755 /usr/bin/aws-lambda-rie
# ENTRYPOINT [ "/usr/bin/aws-lambda-rie", "python", "-m", "awslambdaric" ]
ENTRYPOINT [ "python", "-m", "awslambdaric" ]
# ######## REFERENCE YOUR OWN HANDLER HERE ########################
# CMD [ "main.app" ]```
######## ############################### ########################
# Install Requirements
# Install the functions dependencies
RUN pip3 install poetry awslambdaric argh watchdog
WORKDIR ${FUNCTION_DIR}
COPY pyproject.toml ${FUNCTION_DIR}
# Do not create virtualenv
RUN poetry config virtualenvs.create false
# Only install dependencies
RUN poetry install --no-root
# Copy function code
COPY . ${FUNCTION_DIR}
# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile)
CMD [ "python", "-m", "iambic.lambda.app.handler" ]