-
Notifications
You must be signed in to change notification settings - Fork 0
/
tiny-container.nix
54 lines (49 loc) · 2.05 KB
/
tiny-container.nix
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
# This file uses `dockerTools.streamLayeredImage` to build a minimal
# container. Instead of generating a tarball in the store,
# `streamLayeredImage` generates a script that dumps the container to
# stdout.
#
# After you build the container from the flake using
# `nix build .#tiny-container`, you can load the image by running
# `./result | docker load` and then tag and push the container to your
# registry.
{ bootstrap, buildEnv, busybox, dockerTools, runCommandLocal, writeScript }:
dockerTools.streamLayeredImage {
name = "wai-handler-hal-example-tiny-container";
tag = "latest";
contents =
let
# Grab the runtime interface emulator from a GitHub release.
runtimeInterfaceEmulator = builtins.fetchurl {
url = "https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/download/v1.0/aws-lambda-rie";
sha256 = "1x0200q4cnwwjiqsdqqm1ypz5hah9v7fzdc66kqw9sv3j1da11d4";
};
# This is basically the same as /lambda-entrypoint.sh in a real
# Amazon container image.
entrypoint = writeScript "lambda-entrypoint.sh" ''
#!${busybox}/bin/sh
if [ -z "''${AWS_LAMBDA_RUNTIME_API}" ]; then
exec /usr/local/bin/aws-lambda-rie /var/runtime/bootstrap
else
exec /var/runtime/bootstrap
fi
'';
otherContents = runCommandLocal "other-contents" { } ''
mkdir -p $out/usr/local/bin $out/var/runtime $out/var/task
cp ${entrypoint} $out/lambda-entrypoint.sh
cp ${runtimeInterfaceEmulator} $out/usr/local/bin/aws-lambda-rie
chmod +x $out/usr/local/bin/aws-lambda-rie
cp ${bootstrap}/bootstrap $out/var/runtime/bootstrap
'';
in
[ busybox otherContents ];
# Config is unchanged from `container.nix`; there is no
# technical requirement for EntryPoint or WorkingDir to have these
# values but they need to be set to something. We reuse the values
# from Amazon's base image to minimise surprise.
config = {
Cmd = [ "UNUSED" ];
EntryPoint = [ "/lambda-entrypoint.sh" ];
WorkingDir = "/var/task";
};
}