-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile.lambda-debian
94 lines (71 loc) · 2.33 KB
/
Dockerfile.lambda-debian
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
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Dockerfile.lambda-debian
#
# An image ready for AWS Lambda. In contrast to the alpine Dockerfile,
# this is based on the node image and installs Chrome manually.
#
# Status: Works locally but fails to start Chrome in cloud.
#
# ref: https://nodejs.org/en/docs/guides/nodejs-docker-webapp/
# ref: https://github.com/Zenika/alpine-chrome#run-examples
# ref: https://www.npmjs.com/package/aws-lambda-ric
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Define custom function directory
ARG FUNCTION_DIR="/function"
# 2-stage docker build to reduce image size, bc aws tool building is heavy.
###############################
# Docker Build Stage 1
###############################
FROM node:14.16.0-buster as build-image
# Include global arg in this stage of the build
ARG FUNCTION_DIR
WORKDIR ${FUNCTION_DIR}
# Multi-stage dep install to (1) leverage docker layer caching and (2) cleanup
# Stage 1: Install system deps
RUN apt update
RUN apt-get install -y \
g++ \
make \
cmake \
unzip \
autoconf \
libtool \
libcurl4-openssl-dev \
python3 \
rsync
# Stage 2: Build the aws-lambda-ric node app
RUN npm init -y &> /dev/null
RUN npm i aws-lambda-ric
RUN mv node_modules aws_node_modules
# Stage 3: Copy package*.json and install deps
COPY package*.json ./
RUN npm i
# Stage 4: Copy remaining source files
COPY src src
COPY tsconfig.json ./
# Stage 5: Transpile typescript
RUN npx tsc
# Stage 6: Remove dev files
RUN mv node_modules /tmp; mv src /tmp; mv tsconfig.json /tmp
RUN npm i --production
# Stage 7: Merge aws-lambda-ric deps
RUN rsync -ar aws_node_modules/ node_modules
# Stage 8 copy extra files
COPY lambda.js README.md ./
###############################
# Docker Build Stage 2
###############################
FROM node:14.16.0-buster-slim
# Include global arg in this stage of the build
ARG FUNCTION_DIR
WORKDIR ${FUNCTION_DIR}
# Install chrome
RUN apt update
RUN apt install -y wget
RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN apt install -y ./google-chrome-stable_current_amd64.deb
# Copy in the built dependencies
COPY --from=build-image ${FUNCTION_DIR} ${FUNCTION_DIR}
ADD aws/aws-lambda-rie /usr/local/bin/aws-lambda-rie
ADD aws/lambda-entryscript.sh /
ENTRYPOINT ["/lambda-entryscript.sh"]