-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
55 lines (39 loc) · 1.32 KB
/
Dockerfile
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
# Stage 1
# Local development image that also produces final build
# to optionally be used in next stage.
# To only use this stage, use --taget dev when building
FROM python:3-slim AS dev
RUN apt-get update
RUN apt-get upgrade
RUN apt-get install -y \
zip
ENV USERNAME=lambda
# Create new user for root-less installs
RUN useradd --create-home ${USERNAME}
# Create python user directories for root-less installs
RUN mkdir -p /.local && chown -R ${USERNAME}:${USERNAME} /.local
RUN mkdir -p /.cache/pip && chown -R ${USERNAME}:${USERNAME} /.cache/pip
# Add python bin path to system path
ENV PATH="/home/${USERNAME}/.local/bin:${PATH}"
# Create workdir and give user permissions
RUN mkdir -p /project/lambda
RUN chown -R ${USERNAME}:${USERNAME} /project
WORKDIR /project
# Copy project files
COPY --chown=${USERNAME}:${USERNAME} . .
RUN chown -R ${USERNAME}:${USERNAME} /home/${USERNAME}
# Switch to user
USER ${USERNAME}
RUN ./scripts/poetry.sh
RUN cd lambda && ../scripts/validate.sh
RUN cd lambda && ../scripts/build.sh
# Override entrypoint
ENTRYPOINT [ "bash" ]
# Stage 2
# Copy and install wheel from previous stage
# to build a final production-ready image
FROM public.ecr.aws/lambda/python:3
COPY --from=dev /project/lambda/dist/*.whl .
COPY --from=dev /project/lambda/app.py .
RUN pip install *.whl
CMD [ "app.handler" ]