Skip to content

Commit 0d568ad

Browse files
committed
feat: add simple smoke test after draft release
1 parent 3966fb1 commit 0d568ad

3 files changed

Lines changed: 120 additions & 0 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Post-release OCI smoke test image.
2+
#
3+
# This links a dummy handler against the PREBUILT static library downloaded
4+
# from the release (context file `runtime.a`), the point is we do NOT rebuild the runtime
5+
FROM public.ecr.aws/amazonlinux/amazonlinux:2023 AS builder
6+
7+
RUN dnf install -y gcc-c++ libcurl-devel && dnf clean all
8+
9+
WORKDIR /build
10+
COPY include/ include/
11+
COPY runtime.a runtime.a
12+
COPY main.cpp main.cpp
13+
14+
RUN g++ -std=c++11 -O2 -Iinclude main.cpp runtime.a -lcurl -pthread -o bootstrap
15+
16+
FROM public.ecr.aws/lambda/provided:al2023
17+
18+
COPY --from=builder /build/bootstrap ${LAMBDA_RUNTIME_DIR}/bootstrap
19+
20+
CMD [ "function.handler" ]

‎ci/integ/oci/main.cpp‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <aws/lambda-runtime/runtime.h>
2+
3+
using namespace aws::lambda_runtime;
4+
5+
// Dummy handler used by the post-release OCI smoke test. It echoes the incoming
6+
// payload back and reports its length, which the smoke test asserts on.
7+
static invocation_response my_handler(invocation_request const& req)
8+
{
9+
return invocation_response::success(
10+
R"({"message":"hello from aws-lambda-cpp","echo":)" + (req.payload.empty() ? std::string("null") : req.payload) +
11+
R"(,"payload_length":)" + std::to_string(req.payload.length()) + "}",
12+
"application/json");
13+
}
14+
15+
int main()
16+
{
17+
run_handler(my_handler);
18+
return 0;
19+
}

‎ci/integ/run-oci-smoke.sh‎

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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

Comments
 (0)