Skip to content

update dockerfile template #116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions stack-template.hsfiles
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,11 @@ handler person context =
return (Left "A person's age must be positive")

{-# START_FILE Dockerfile #-}
# Loosely based on https://timwspence.github.io/blog/posts/2019-08-02-optimized-docker-builds-for-haskell-stack.html
ARG OUTPUT_DIR=/root/output
ARG EXECUTABLE_NAME=bootstrap

FROM lambci/lambda:build-provided as build

COPY . .
FROM lambci/lambda:build-provided.al2 as build

SHELL ["/bin/bash", "--rcfile", "~/.profile", "-c"]

Expand All @@ -83,17 +82,18 @@ RUN yum update -y ca-certificates
# Installing Haskell Stack
RUN curl -sSL https://get.haskellstack.org/ | sh

# Build the lambda
COPY . /root/lambda-function/
WORKDIR /root/lambda-function/

RUN pwd
# Build the deps
RUN stack clean --full
RUN yum install -y gmp-devel ncurses-devel # Add more build time dependencies here if needed. EG: postgresql-devel

RUN cd /root/lambda-function
WORKDIR /root/lambda-function/
COPY stack.yaml package.yaml stack.yaml.lock /root/lambda-function/
RUN stack build --dependencies-only

RUN ls
# Build the lambda
COPY . /root/lambda-function/

RUN stack clean --full
RUN stack build

ARG OUTPUT_DIR
Expand All @@ -103,12 +103,15 @@ RUN mkdir -p ${OUTPUT_DIR} && \

ARG EXECUTABLE_NAME

RUN cp $(stack path --local-install-root)/bin/${EXECUTABLE_NAME} ${OUTPUT_DIR}/${EXECUTABLE_NAME}
RUN mv $(stack path --local-install-root)/bin/${EXECUTABLE_NAME} ${OUTPUT_DIR}/${EXECUTABLE_NAME}

ENTRYPOINT sh

FROM public.ecr.aws/lambda/provided:al2 as deploy

# Install any runtime dependencies. EG:
# RUN yum install -y postgresql

ARG EXECUTABLE_NAME

WORKDIR ${LAMBDA_RUNTIME_DIR}
Expand All @@ -117,9 +120,7 @@ ARG OUTPUT_DIR

COPY --from=build ${OUTPUT_DIR} .

RUN ls
RUN mv ${EXECUTABLE_NAME} bootstrap || true
RUN ls

CMD [ "handler" ]

Expand Down