forked from aws/aws-lambda-nodejs-runtime-interface-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile.echo.amazonlinux
76 lines (65 loc) · 2.57 KB
/
Dockerfile.echo.amazonlinux
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
# Define global args
ARG FUNCTION_DIR="/home/app/"
ARG RUNTIME_VERSION
ARG DISTRO_VERSION
# Stage 1 - bundle base image + runtime
# Grab a fresh copy of the image and install Node
FROM amazonlinux:${DISTRO_VERSION} AS node-amazonlinux
# Include global arg in this stage of the build
ARG RUNTIME_VERSION
ARG DISTRO_VERSION
# Install Py3 required to build Node16+
RUN if [[ "${DISTRO_VERSION}" == "2" ]] ; then amazon-linux-extras install python3.8 && update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1 ; fi
# Install NodeJS
RUN curl -sL https://rpm.nodesource.com/setup_${RUNTIME_VERSION}.x | bash - && \
yum install -y nodejs
# Stage 2 - build function and dependencies
FROM node-amazonlinux AS build-image
ARG ARCHITECTURE
# Install aws-lambda-cpp build dependencies
RUN yum install -y \
tar \
gzip \
make \
wget \
autoconf \
automake \
libtool \
libcurl-devel \
gcc-c++
# Install a modern CMake
RUN wget --quiet -O cmake-install https://github.com/Kitware/CMake/releases/download/v3.20.0/cmake-3.20.0-linux-${ARCHITECTURE}.sh && \
sh cmake-install --skip-license --prefix=/usr --exclude-subdirectory;
# Include global arg in this stage of the build
ARG FUNCTION_DIR
# Create function directory
RUN mkdir -p ${FUNCTION_DIR}
# Copy & build Runtime Interface Client package (as we're installing it from a local filesystem source)
WORKDIR ${FUNCTION_DIR}/deps/aws-lambda-ric
COPY . .
# Node14 uses [email protected] by default which will downgrade permissions, if it's root,
# before running any build scripts: https://github.com/npm/npm/issues/3497
# Starting from [email protected], when npm is run as root,
# scripts are always run with the effective uid and gid of the working directory owner.
RUN if [[ $(node -v | cut -c 1-3) == "v14" ]] ; then npm install -g npm@7 ; fi
RUN make build && \
npm run test:unit
# Copy function code
COPY test/integration/test-handlers/echo/* ${FUNCTION_DIR}
# Install the function's dependencies
WORKDIR ${FUNCTION_DIR}
RUN npm install
# Stage 3 - final runtime image
# Grab a fresh copy of the Node image
FROM node-amazonlinux
# Required for Node runtimes which use [email protected]+ because
# by default npm writes logs under /home/.npm and Lambda fs is read-only
ENV NPM_CONFIG_CACHE=/tmp/.npm
# Include global arg in this stage of the build
ARG FUNCTION_DIR
# 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/bin/npx", "aws-lambda-ric" ]
CMD [ "index.handler" ]