-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLambda.Dockerfile
More file actions
83 lines (65 loc) · 2.67 KB
/
Lambda.Dockerfile
File metadata and controls
83 lines (65 loc) · 2.67 KB
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
# https://www.haskelltutorials.com/haskell-aws-lambda/compiling-haskell-runtime-in-docker.html#docker-solution
# NOTE: This Docker image is required ONLY to compile the lambda-haskell
# component that is deployed to AWS Lambda. This is the reason why it is not
# being built on an ubuntu container but on an amazonlinux container. The core
# OS libraries, like glibc, etc. are sufficiently different between the two
# systems, that a binary compiled on Ubunut 18.04 cannot work when deployed to
# AWS Lambda.
FROM amazonlinux:2023
SHELL ["/bin/bash", "--rcfile", "~/.profile", "-c", "-o", "pipefail"]
ARG BOOTSTRAP=mnet-aggregator:exe:bootstrap
################################
#### Switching to root user
################################
USER root
# Saving default system libraries before doing anything else
RUN du -a /lib64 /usr/lib64 | cut -f2 > /root/default-libraries
# Installing basic dependencies
RUN dnf install -y \
git-core \
tar \
sudo \
xz \
zlib \
libffi \
make \
gmp-devel \
postgresql-devel \
libicu libicu-devel \
libyaml libyaml-devel \
ncurses-term ncurses-devel \
&& dnf clean all
# libtinfo libtinfo-devel \
RUN dnf group install -y "Development Tools"
# Installing Haskell Stack
RUN curl -sSL https://get.haskellstack.org/ | sh
ARG STACK_RESOLVER=lts-22.20
# Setting up GHC
RUN stack setup --resolver=${STACK_RESOLVER} && stack update
RUN mkdir /root/lambda-function
COPY stack.yaml stack.yaml.lock mnet-aggregator.cabal /root/lambda-function/
WORKDIR /root/lambda-function
# Make cached layer from dependencies so subsequent builds where only source
# files change are faster
RUN stack build --resolver=${STACK_RESOLVER} --dependencies-only ${BOOTSTRAP}
WORKDIR /tmp
RUN git clone https://github.com/saurabhnanda/aws-lambda-packager.git
WORKDIR /tmp/aws-lambda-packager
# ARG PACKAGER_COMMIT_SHA=d3312736a38f7b93f87c313a8fb9c0798938b403
ARG PACKAGER_COMMIT_SHA=0efa19d99794493a5c7a7234975377e148d04875
RUN git checkout ${PACKAGER_COMMIT_SHA} && \
stack install --resolver=${STACK_RESOLVER}
# Copying the source code of the lambda function into the Docker container
COPY . /root/lambda-function/
# Building the lambda-function and copying it to the output directory
WORKDIR /root/lambda-function
RUN stack build ${BOOTSTRAP}
ARG OUTPUT_DIR=/root/output
RUN mkdir ${OUTPUT_DIR} && \
mkdir ${OUTPUT_DIR}/lib
RUN cp "$(stack path --local-install-root)/bin/bootstrap" ${OUTPUT_DIR}/bootstrap
# Finally, copying over all custom/extra libraries with the help of aws-lambda-packager
RUN /root/.local/bin/aws-lambda-packager copy-custom-libraries \
-l /root/default-libraries \
-f /root/output/bootstrap \
-o /root/output/lib