|
| 1 | +#!/bin/bash |
| 2 | +# Post-release OCI smoke test. |
| 3 | +# |
| 4 | +# Downloads the published static library from the (draft) release, verifies its |
| 5 | +# checksum against the published SHA256SUMS, links a dummy handler against it, |
| 6 | +# and invokes it through the Lambda Runtime Interface Emulator baked into |
| 7 | +# public.ecr.aws/lambda/provided:al2023 — i.e. the exact happy path a downstream |
| 8 | +# consumer of the artifact would follow. |
| 9 | +# |
| 10 | +# Requires: gh (with GH_TOKEN), docker, curl. Runs on stock GitHub-hosted |
| 11 | +# runners; needs no AWS credentials or CodeArtifact access. |
| 12 | +# |
| 13 | +# Usage: run-oci-smoke.sh <arch> <tag> |
| 14 | +set -euo pipefail |
| 15 | + |
| 16 | +ARCH=${1:?usage: run-oci-smoke.sh <arch> <tag>} |
| 17 | +TAG=${2:?usage: run-oci-smoke.sh <arch> <tag>} |
| 18 | +REPO=${GITHUB_REPOSITORY:-awslabs/aws-lambda-cpp} |
| 19 | +PORT=9000 |
| 20 | + |
| 21 | +SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) |
| 22 | +REPO_ROOT=$(cd "$SCRIPT_DIR/../.." && pwd) |
| 23 | + |
| 24 | +LIB="libaws-lambda-runtime-${ARCH}.a" |
| 25 | +IMAGE="lambda-cpp-oci-smoke:${ARCH}" |
| 26 | +CONTAINER="lambda-cpp-oci-smoke-${ARCH}" |
| 27 | + |
| 28 | +WORKDIR=$(mktemp -d) |
| 29 | +trap 'docker rm -f "$CONTAINER" >/dev/null 2>&1 || true; rm -rf "$WORKDIR"' EXIT |
| 30 | + |
| 31 | +echo "== Downloading $LIB + SHA256SUMS from release '$TAG' ==" |
| 32 | +gh release download "$TAG" --repo "$REPO" \ |
| 33 | + -p "$LIB" -p SHA256SUMS --dir "$WORKDIR" --clobber |
| 34 | + |
| 35 | +echo "== Verifying checksum ==" |
| 36 | +( cd "$WORKDIR" && grep -F "$LIB" SHA256SUMS | sha256sum -c - ) |
| 37 | + |
| 38 | +echo "== Assembling build context ==" |
| 39 | +CTX="$WORKDIR/ctx" |
| 40 | +mkdir -p "$CTX" |
| 41 | +cp -r "$REPO_ROOT/include" "$CTX/include" |
| 42 | +cp "$REPO_ROOT/ci/integ/oci/main.cpp" "$CTX/main.cpp" |
| 43 | +cp "$WORKDIR/$LIB" "$CTX/runtime.a" |
| 44 | + |
| 45 | +echo "== Building OCI image ==" |
| 46 | +docker build \ |
| 47 | + -f "$REPO_ROOT/ci/integ/docker/Dockerfile.oci-smoke" \ |
| 48 | + -t "$IMAGE" "$CTX" |
| 49 | + |
| 50 | +echo "== Starting container (RIE) ==" |
| 51 | +docker run -d --name "$CONTAINER" -p "$PORT:8080" "$IMAGE" >/dev/null |
| 52 | + |
| 53 | +INVOKE_URL="http://localhost:${PORT}/2015-03-31/functions/function/invocations" |
| 54 | + |
| 55 | +echo "== Waiting for RIE to become ready ==" |
| 56 | +ready=false |
| 57 | +for _ in $(seq 1 30); do |
| 58 | + if curl -sf -XPOST "$INVOKE_URL" -d '{}' >/dev/null 2>&1; then |
| 59 | + ready=true |
| 60 | + break |
| 61 | + fi |
| 62 | + sleep 1 |
| 63 | +done |
| 64 | +if [ "$ready" != true ]; then |
| 65 | + echo "::error::RIE did not become ready in time" |
| 66 | + docker logs "$CONTAINER" || true |
| 67 | + exit 1 |
| 68 | +fi |
| 69 | + |
| 70 | +echo "== Invoking via RIE ==" |
| 71 | +RESPONSE=$(curl -s -XPOST "$INVOKE_URL" -d '{"answer":42}') |
| 72 | +echo "Response: $RESPONSE" |
| 73 | + |
| 74 | +EXPECTED='"payload_length":13' |
| 75 | +if ! echo "$RESPONSE" | grep -qF "$EXPECTED"; then |
| 76 | + echo "::error::Smoke test assertion failed for $ARCH. Expected response to contain: $EXPECTED" |
| 77 | + docker logs "$CONTAINER" || true |
| 78 | + exit 1 |
| 79 | +fi |
| 80 | + |
| 81 | +echo "Smoke test passed for $ARCH" |
0 commit comments