########################################################################################### # Stage 0 # Install all dependencies, build output and set up the AWS Lambda RIC. ########################################################################################### ARG FUNCTION_DIR="/function" FROM node:14-alpine as builder ENV HUSKY_SKIP_INSTALL=true ENV DISABLE_OPENCOLLECTIVE=true ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true # Install build-time dependencies for the Node.js AWS Lambda RIC ("Runtime Interface Client"). RUN apk update && \ apk add --no-cache --virtual build-dependencies \ build-base \ cmake \ automake \ autoconf \ libtool \ gcc \ wget \ curl \ libcurl \ curl-dev \ libexecinfo-dev \ python3 \ git ARG FUNCTION_DIR RUN mkdir -p ${FUNCTION_DIR} COPY . ${FUNCTION_DIR} WORKDIR ${FUNCTION_DIR} RUN yarn install --frozen-lockfile && yarn run build && yarn install --production --frozen-lockfile RUN yarn add aws-lambda-ric@1.0.0 ########################################################################################### # Stage 1 # Install Chromium and prepare entrypoint script. ########################################################################################### FROM node:14-alpine ARG FUNCTION_DIR WORKDIR ${FUNCTION_DIR} # Install AWS Lambda Container dependencies. ADD https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie /usr/local/bin/aws-lambda-rie RUN chmod ugo+x /usr/local/bin/aws-lambda-rie # Runtime dependency for Lambda RIC. RUN apk add --no-cache nghttp2-libs # Install Chromium dev build. RUN echo "@edgecommunity https://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories RUN apk update && \ apk add --no-cache \ chromium@edgecommunity \ nss \ freetype \ freetype-dev \ harfbuzz \ ca-certificates \ ttf-freefont ENV PUPPETEER_EXECUTABLE_PATH="/usr/bin/chromium-browser" # Copy all build output and Node.js dependencies from stage 0. COPY --from=builder ${FUNCTION_DIR} ${FUNCTION_DIR} # If testing locally, run the Lambda RIE ("Runtime Interface Emulator"); # Otherwise run the Lambda RIC ("Runtime Interface Client"). RUN echo -e '#!/bin/sh\n\ if [ -z "${AWS_LAMBDA_RUNTIME_API}" ]; then\n \ exec /usr/local/bin/aws-lambda-rie /usr/local/bin/npx aws-lambda-ric $1\n \ else\n \ exec /usr/local/bin/npx aws-lambda-ric $1\n \ fi'\ >> /entrypoint.sh RUN chmod ugo+x /entrypoint.sh ENTRYPOINT ["/entrypoint.sh"] CMD ["lib/lambda.handler"]