-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile.lambda-alpine
88 lines (74 loc) · 2.55 KB
/
Dockerfile.lambda-alpine
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
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Dockerfile.lambda-alpine
#
# An image ready for AWS Lambda. In contrast to the debian Dockerfile,
# this is based on a Chrome image -- slimmer and more reliable.
#
# Status: Working
#
# 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
#
# Using chrome 85 tag b/c AWS build fails with 86, I think bc 86 is built with a newer Alpine using
# the latest tag. 85 also uses the latest tag, but it was built before the bug was introduced. Therefor,
# this workaround to using 85 could be broken if the maintainer pushes a new build of 85 with the
# broken version of Alpine. I should create an issue or pr in the repo, but would need to create a
# bug demo and don't have time now.
# ref: https://gitlab.alpinelinux.org/alpine/aports/-/issues/12321
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Define custom function directory
ARG FUNCTION_DIR="/function"
# 2-stage docker build to build aws and reduce image size, bc aws tool building is heavy.
###############################
# Docker Build Stage 1
###############################
FROM zenika/alpine-chrome:85-with-node as build-image
# Include global arg in this stage of the build
ARG FUNCTION_DIR
WORKDIR ${FUNCTION_DIR}
USER root
# Step 1: Build the aws-lambda-cpp node app
RUN apk update
RUN apk add --no-cache \
build-base \
libtool \
autoconf \
automake \
libexecinfo-dev \
make \
cmake \
libcurl \
git \
rsync
RUN npm init -y &> /dev/null
RUN npm i aws-lambda-ric
RUN mv node_modules aws_node_modules
# Step 2: Copy package*.json and install dev deps
COPY package*.json ./
RUN npm i
# Step 3: Copy remaining source files
COPY src src
COPY tsconfig.json ./
# Step 4: Transpile typescript
RUN npx tsc
# Step 5: Remove dev files
RUN mv node_modules src tsconfig.json /tmp
RUN npm i --production
# Step 6: Merge aws-lambda-ric deps
RUN rsync -ar aws_node_modules/ node_modules
# Step 7: copy extra files
COPY lambda.js README.md ./
###############################
# Docker Build Stage 2
###############################
FROM zenika/alpine-chrome:85-with-node
# Include global arg in this stage of the build
ARG FUNCTION_DIR
WORKDIR ${FUNCTION_DIR}
USER root
COPY --from=build-image ${FUNCTION_DIR} ${FUNCTION_DIR}
RUN chown -R chrome $FUNCTION_DIR
ADD aws/aws-lambda-rie /usr/local/bin/aws-lambda-rie
ADD aws/lambda-entryscript.sh /
ENTRYPOINT ["/lambda-entryscript.sh"]