|
1 | 1 | #!/bin/bash |
2 | 2 | set -euo pipefail |
3 | 3 |
|
| 4 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 5 | + |
| 6 | +# Detect container runtime: prefer finch, fall back to docker if it works |
| 7 | +if command -v finch &>/dev/null && finch vm status &>/dev/null; then |
| 8 | + CONTAINER_CMD=finch |
| 9 | +elif command -v docker &>/dev/null && docker info &>/dev/null 2>&1; then |
| 10 | + CONTAINER_CMD=docker |
| 11 | +else |
| 12 | + echo "Error: no working container runtime found (tried finch, docker)" >&2 |
| 13 | + exit 1 |
| 14 | +fi |
| 15 | +echo "Using container runtime: $CONTAINER_CMD" |
| 16 | + |
4 | 17 | EXAMPLE=${1:-basic-lambda} |
5 | 18 | # Optional: set RIE_MAX_CONCURRENCY to enable LMI mode (emulates AWS_LAMBDA_MAX_CONCURRENCY) |
6 | 19 | RIE_MAX_CONCURRENCY=${RIE_MAX_CONCURRENCY:-} |
7 | 20 |
|
| 21 | +echo "Building RIE from source (invocation-id support)..." |
| 22 | +if [ ! -f /tmp/aws-lambda-rie ]; then |
| 23 | + # Build natively on host to avoid container DNS issues with VPN |
| 24 | + if ! command -v go &>/dev/null; then |
| 25 | + echo "Error: Go is required to build RIE. Install with: brew install go" >&2 |
| 26 | + exit 1 |
| 27 | + fi |
| 28 | + RIE_BUILD_DIR=$(mktemp -d) |
| 29 | + git clone --depth 50 https://github.com/aws/aws-lambda-runtime-interface-emulator.git "$RIE_BUILD_DIR/rie" |
| 30 | + cd "$RIE_BUILD_DIR/rie" |
| 31 | + git checkout ddf2bc4f4c95a1c7fdb15633a80e65b9be8ffe46 |
| 32 | + # Cross-compile for Linux/amd64 (runs inside container) |
| 33 | + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /tmp/aws-lambda-rie ./cmd/aws-lambda-rie |
| 34 | + cd "$SCRIPT_DIR/.." |
| 35 | + rm -rf "$RIE_BUILD_DIR" |
| 36 | +fi |
| 37 | +cp /tmp/aws-lambda-rie "$SCRIPT_DIR/../aws-lambda-rie" |
| 38 | + |
8 | 39 | echo "Building Docker image with RIE for example: $EXAMPLE..." |
9 | | -docker build -f Dockerfile.rie --build-arg EXAMPLE=$EXAMPLE -t rust-lambda-rie-test . |
| 40 | +$CONTAINER_CMD build --dns 8.8.8.8 -f Dockerfile.rie --build-arg EXAMPLE=$EXAMPLE -t rust-lambda-rie-test . |
10 | 41 |
|
11 | 42 | echo "Starting RIE container on port 9000..." |
12 | 43 | if [ -n "$RIE_MAX_CONCURRENCY" ]; then |
13 | 44 | echo "Enabling LMI mode with AWS_LAMBDA_MAX_CONCURRENCY=$RIE_MAX_CONCURRENCY" |
14 | | - docker run -p 9000:8080 -e AWS_LAMBDA_MAX_CONCURRENCY="$RIE_MAX_CONCURRENCY" rust-lambda-rie-test & |
| 45 | + $CONTAINER_CMD run -p 9000:8080 -e AWS_LAMBDA_MAX_CONCURRENCY="$RIE_MAX_CONCURRENCY" rust-lambda-rie-test & |
15 | 46 | else |
16 | | - docker run -p 9000:8080 rust-lambda-rie-test & |
| 47 | + $CONTAINER_CMD run -p 9000:8080 rust-lambda-rie-test & |
17 | 48 | fi |
18 | 49 | CONTAINER_PID=$! |
19 | 50 |
|
|
0 commit comments