Skip to content
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

Feature/add dockerfile for newest LTS builds #81

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
30 changes: 30 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Start from the Lambda Env mirror
FROM lambci/lambda:provided

# Switch to root, so we can install packages and configure users
USER root

# Install packages required for building GHC
RUN yum -y install gcc gmp-devel zlib-devel

# Give users access to /tmp, as stack uses it to build GHC
RUN chmod a=rwx,o+t /tmp

# Custom stack images require a stack group and stack user in the stack group
RUN /usr/sbin/groupadd stack
RUN /usr/sbin/useradd stack -g stack

# Switch to the stack user so we can setup its home directory
USER stack
RUN mkdir ~/.stack
ENV PATH=/usr/sbin:$HOME/.local/bin:$PATH
RUN mkdir -p ~/.local/bin

# Install stack
RUN curl -L https://get.haskellstack.org/stable/linux-x86_64.tar.gz | tar xz --wildcards --strip-components=1 -C ~/.local/bin '*/stack'

# Switch back to the root user
USER root

# Disable the default `lambdci/lambda` entrypoint
ENTRYPOINT []
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,17 @@ You'll need to either build on a compatible linux host or inside a compatible do
Note that current Stack LTS images are _not_ compatible.
If you see an error message that contains "version 'GLIBC_X.XX' not found" when running (hosted or locally), then your build environment is not compatible.

An example Dockerfile is included in this repo, which can build out later Stack LTS snapshots (also see Troubleshooting Builds for Specific Package).
Build it with `docker build -t ${BUILD_IMAGE_NAME} ${DOCKER_FILE_ROOT_DIR}`.

Enable stack's docker integration and define an optional image within stack.yaml:

```yaml
# file: stack.yaml
docker:
enabled: true
# If omitted, this defaults to fpco/stack-build:lts-${YOUR_LTS_VERSION}
image: ${BUILD_IMAGE}
image: ${BUILD_IMAGE_NAME}
```

Don't forget to define your [CloudFormation] stack:
Expand Down Expand Up @@ -203,6 +206,22 @@ Note that hal currently only supports [aws-sam-cli] on versions <1.0.
echo '{ "accountId": "byebye" }' | sam local invoke --region us-east-1
```

## Troubleshooting Builds for Specific Package

Some packages require a few additional settings to build without issue, where a Docker based solution is impractical.

### cryptonite 0.27

To get this version to build you'll need to pass the Cabal flag `use_target_attributes` false.
You can put the following in your `stack.yaml` to do this:

```
flags:
cryptonite:
use_target_attributes: false
```


[AWS Lambda]: https://docs.aws.amazon.com/lambda/latest/dg/welcome.html
[Haskell]: https://www.haskell.org/
[stack.yaml]: https://docs.haskellstack.org/
Expand Down