Skip to content

Commit

Permalink
Merge pull request #11 from bellroy/doc-updates
Browse files Browse the repository at this point in the history
Doc updates
  • Loading branch information
JackKelly-Bellroy authored Jul 19, 2024
2 parents 484b81a + 4bcab71 commit a9365e7
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 51 deletions.
45 changes: 13 additions & 32 deletions .github/workflows/haskell-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
timeout-minutes:
60
container:
image: buildpack-deps:bionic
image: buildpack-deps:jammy
continue-on-error: ${{ matrix.allow-failure }}
strategy:
matrix:
Expand Down Expand Up @@ -51,34 +51,24 @@ jobs:
- compiler: ghc-8.8.4
compilerKind: ghc
compilerVersion: 8.8.4
setup-method: hvr-ppa
setup-method: ghcup
allow-failure: false
- compiler: ghc-8.6.5
compilerKind: ghc
compilerVersion: 8.6.5
setup-method: hvr-ppa
setup-method: ghcup
allow-failure: false
fail-fast: false
steps:
- name: apt
run: |
apt-get update
apt-get install -y --no-install-recommends gnupg ca-certificates dirmngr curl git software-properties-common libtinfo5
if [ "${{ matrix.setup-method }}" = ghcup ]; then
mkdir -p "$HOME/.ghcup/bin"
curl -sL https://downloads.haskell.org/ghcup/0.1.19.2/x86_64-linux-ghcup-0.1.19.2 > "$HOME/.ghcup/bin/ghcup"
chmod a+x "$HOME/.ghcup/bin/ghcup"
"$HOME/.ghcup/bin/ghcup" install ghc "$HCVER" || (cat "$HOME"/.ghcup/logs/*.* && false)
"$HOME/.ghcup/bin/ghcup" install cabal 3.10.1.0 || (cat "$HOME"/.ghcup/logs/*.* && false)
else
apt-add-repository -y 'ppa:hvr/ghc'
apt-get update
apt-get install -y "$HCNAME"
mkdir -p "$HOME/.ghcup/bin"
curl -sL https://downloads.haskell.org/ghcup/0.1.19.2/x86_64-linux-ghcup-0.1.19.2 > "$HOME/.ghcup/bin/ghcup"
chmod a+x "$HOME/.ghcup/bin/ghcup"
"$HOME/.ghcup/bin/ghcup" install cabal 3.10.1.0 || (cat "$HOME"/.ghcup/logs/*.* && false)
fi
mkdir -p "$HOME/.ghcup/bin"
curl -sL https://downloads.haskell.org/ghcup/0.1.19.2/x86_64-linux-ghcup-0.1.19.2 > "$HOME/.ghcup/bin/ghcup"
chmod a+x "$HOME/.ghcup/bin/ghcup"
"$HOME/.ghcup/bin/ghcup" install ghc "$HCVER" || (cat "$HOME"/.ghcup/logs/*.* && false)
"$HOME/.ghcup/bin/ghcup" install cabal 3.10.1.0 || (cat "$HOME"/.ghcup/logs/*.* && false)
env:
HCKIND: ${{ matrix.compilerKind }}
HCNAME: ${{ matrix.compiler }}
Expand All @@ -90,20 +80,11 @@ jobs:
echo "CABAL_DIR=$HOME/.cabal" >> "$GITHUB_ENV"
echo "CABAL_CONFIG=$HOME/.cabal/config" >> "$GITHUB_ENV"
HCDIR=/opt/$HCKIND/$HCVER
if [ "${{ matrix.setup-method }}" = ghcup ]; then
HC=$HOME/.ghcup/bin/$HCKIND-$HCVER
echo "HC=$HC" >> "$GITHUB_ENV"
echo "HCPKG=$HOME/.ghcup/bin/$HCKIND-pkg-$HCVER" >> "$GITHUB_ENV"
echo "HADDOCK=$HOME/.ghcup/bin/haddock-$HCVER" >> "$GITHUB_ENV"
echo "CABAL=$HOME/.ghcup/bin/cabal-3.10.1.0 -vnormal+nowrap" >> "$GITHUB_ENV"
else
HC=$HCDIR/bin/$HCKIND
echo "HC=$HC" >> "$GITHUB_ENV"
echo "HCPKG=$HCDIR/bin/$HCKIND-pkg" >> "$GITHUB_ENV"
echo "HADDOCK=$HCDIR/bin/haddock" >> "$GITHUB_ENV"
echo "CABAL=$HOME/.ghcup/bin/cabal-3.10.1.0 -vnormal+nowrap" >> "$GITHUB_ENV"
fi
HC=$HOME/.ghcup/bin/$HCKIND-$HCVER
echo "HC=$HC" >> "$GITHUB_ENV"
echo "HCPKG=$HOME/.ghcup/bin/$HCKIND-pkg-$HCVER" >> "$GITHUB_ENV"
echo "HADDOCK=$HOME/.ghcup/bin/haddock-$HCVER" >> "$GITHUB_ENV"
echo "CABAL=$HOME/.ghcup/bin/cabal-3.10.1.0 -vnormal+nowrap" >> "$GITHUB_ENV"
HCNUMVER=$(${HC} --numeric-version|perl -ne '/^(\d+)\.(\d+)\.(\d+)(\.(\d+))?$/; print(10000 * $1 + 100 * $2 + ($3 == 0 ? $5 != 1 : $3))')
echo "HCNUMVER=$HCNUMVER" >> "$GITHUB_ENV"
echo "ARG_TESTS=--enable-tests" >> "$GITHUB_ENV"
Expand Down
1 change: 1 addition & 0 deletions cabal.haskell-ci
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
distribution: jammy
6 changes: 2 additions & 4 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@
project = pkgs: pkgs.haskell-nix.project {
compiler-nix-name = "ghc96";
evalSystem = "x86_64-linux";
src = pkgsLocal.haskell-nix.haskellLib.cleanGit {
name = "wai-handler-hal-example";
src = ./.;
};
src = ./.;

# This is usually fine, but can "occasionally cause breakage":
# https://input-output-hk.github.io/haskell.nix/troubleshooting/#why-does-my-executable-depend-on-ghcgcc
Expand All @@ -43,6 +40,7 @@
(project pkgsLocal).shellFor {
withHoogle = false;
buildInputs = with pkgsLocal; [
haskell-ci
haskellPackages.cabal-fmt
nixpkgs-fmt
nodejs
Expand Down
38 changes: 23 additions & 15 deletions wai-handler-hal-cdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ The `cdk.json` file tells the CDK Toolkit how to execute the app.

## Quick deploy

The project's `shell.nix` provides `npm` and `nodejs`, so run the
following commands from inside a `nix-shell`:
The project's flake provides `npm` and `nodejs`, so run the following
commands from this directory, inside a `nix develop` shell:

* `npm install`
* `npm run cdk bootstrap` (only if you've never used CDK on your AWS
account before)
* `(cd runtime && nix build -f .)` (build the Lambda binary where CDK can
find it)
* `(cd runtime && nix build .#packages.x86_64-linux.default)` (build
the Lambda binary where CDK can find it)
* `npm run cdk deploy` (deploy to AWS)

To tear down the stack, run `npm run cdk destroy`. If you don't plan
Expand All @@ -29,19 +29,22 @@ resources (like S3 buckets).

## Building the binary

`runtime/default.nix` is a Nix expression to build the
statically-linked `hal` binary, and the CDK script is configured to
expect it at `runtime/result/bootstrap`. There are two other example
`.nix` files in that directory, if you want to explore deploying
Lambda functions using OCI images on
[ECR](https://aws.amazon.com/ecr/):
The default package built by this flake is a statically-linked `hal`
binary, and the CDK script is configured to expect it at
`runtime/result/bootstrap`. There are two other example `.nix` files
in the repository root, if you want to explore deploying Lambda
functions using OCI images on [ECR](https://aws.amazon.com/ecr/):

* `runtime/container.nix` builds a container from Amazon's
* `/container.nix` builds a container from Amazon's
[`al2`](https://hub.docker.com/r/amazon/aws-lambda-provided/tags)
container. It places the statically-linked binary into the correct
location in the container filesystem. Load with `docker load <
result`.
* `runtime/tiny-container.nix` builds a minimal container from four
location in the container filesystem. This uses
[`dockerTools.buildImage`](https://nixos.org/manual/nixpkgs/stable/#ssec-pkgs-dockerTools-buildImage)
to build the container image as a file in the nix store, which you
can load with `docker load < result`. This is the simplest way to
build a container image, but `dockerTools.streamLayeredImage` is
generally better.
* `/tiny-container.nix` builds a minimal container from just four
parts:
- The statically-linked Haskell binary;
- The [Lambda Runtime Interface
Expand All @@ -50,7 +53,12 @@ Lambda functions using OCI images on
not running in the AWS Cloud; and
- A statically-linked `busybox`, to provide a minimal shell to run
the entrypoint script.
Load with `./result | docker load`

This uses
[`dockerTools.streamLayeredImage`](https://nixos.org/manual/nixpkgs/stable/#ssec-pkgs-dockerTools-streamLayeredImage)
to avoid adding the final image to the nix store, saving space by
emitting a script instead. Load the image into Docker with `./result
| docker load`

### Thoughts on the container format and the Lambda Runtime Interface Emulator

Expand Down
Empty file.

0 comments on commit a9365e7

Please sign in to comment.