-
Notifications
You must be signed in to change notification settings - Fork 97
feat: add simple smoke test after draft release #223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+144
−0
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # Post-release OCI smoke test image. | ||
| # | ||
| # This links a dummy handler against the PREBUILT static library downloaded | ||
| # from the release (context file `runtime.a`), the point is we do NOT rebuild the runtime | ||
| FROM public.ecr.aws/amazonlinux/amazonlinux:2023 AS builder | ||
|
|
||
| RUN dnf install -y gcc-c++ libcurl-devel && dnf clean all | ||
|
|
||
| WORKDIR /build | ||
| COPY include/ include/ | ||
| COPY runtime.a runtime.a | ||
| COPY main.cpp main.cpp | ||
|
|
||
| RUN g++ -std=c++11 -O2 -Iinclude main.cpp runtime.a -lcurl -pthread -o bootstrap | ||
|
|
||
| FROM public.ecr.aws/lambda/provided:al2023 | ||
|
|
||
| COPY --from=builder /build/bootstrap ${LAMBDA_RUNTIME_DIR}/bootstrap | ||
|
|
||
| CMD [ "function.handler" ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| #include <aws/lambda-runtime/runtime.h> | ||
|
|
||
| using namespace aws::lambda_runtime; | ||
|
|
||
| // Dummy handler used by the post-release OCI smoke test. It echoes the incoming | ||
| // payload back and reports its length, which the smoke test asserts on. | ||
| static invocation_response my_handler(invocation_request const& req) | ||
| { | ||
| return invocation_response::success( | ||
| R"({"message":"hello from aws-lambda-cpp","echo":)" + (req.payload.empty() ? std::string("null") : req.payload) + | ||
| R"(,"payload_length":)" + std::to_string(req.payload.length()) + "}", | ||
| "application/json"); | ||
| } | ||
|
|
||
| int main() | ||
| { | ||
| run_handler(my_handler); | ||
| return 0; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| #!/bin/bash | ||
| # Post-release OCI smoke test. | ||
| # | ||
| # Downloads the published static library from the (draft) release, verifies its | ||
| # checksum against the published SHA256SUMS, links a dummy handler against it, | ||
| # and invokes it through the Lambda Runtime Interface Emulator baked into | ||
| # public.ecr.aws/lambda/provided:al2023 — i.e. the exact happy path a downstream | ||
| # consumer of the artifact would follow. | ||
| # | ||
| # Requires: gh (with GH_TOKEN), docker, curl. Runs on stock GitHub-hosted | ||
| # runners; needs no AWS credentials or CodeArtifact access. | ||
| # | ||
| # Usage: run-oci-smoke.sh <arch> <tag> | ||
| set -euo pipefail | ||
|
|
||
| ARCH=${1:?usage: run-oci-smoke.sh <arch> <tag>} | ||
| TAG=${2:?usage: run-oci-smoke.sh <arch> <tag>} | ||
| REPO=${GITHUB_REPOSITORY:-awslabs/aws-lambda-cpp} | ||
| PORT=9000 | ||
|
|
||
| SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) | ||
| REPO_ROOT=$(cd "$SCRIPT_DIR/../.." && pwd) | ||
|
|
||
| LIB="libaws-lambda-runtime-${ARCH}.a" | ||
| IMAGE="lambda-cpp-oci-smoke:${ARCH}" | ||
| CONTAINER="lambda-cpp-oci-smoke-${ARCH}" | ||
|
|
||
| WORKDIR=$(mktemp -d) | ||
| trap 'docker rm -f "$CONTAINER" >/dev/null 2>&1 || true; rm -rf "$WORKDIR"' EXIT | ||
|
|
||
| echo "== Downloading $LIB + SHA256SUMS from release '$TAG' ==" | ||
| gh release download "$TAG" --repo "$REPO" \ | ||
| -p "$LIB" -p SHA256SUMS --dir "$WORKDIR" --clobber | ||
|
|
||
| echo "== Verifying checksum ==" | ||
| ( cd "$WORKDIR" && grep -F "$LIB" SHA256SUMS | sha256sum -c - ) | ||
|
|
||
| echo "== Assembling build context ==" | ||
| CTX="$WORKDIR/ctx" | ||
| mkdir -p "$CTX" | ||
| cp -r "$REPO_ROOT/include" "$CTX/include" | ||
| cp "$REPO_ROOT/ci/integ/oci/main.cpp" "$CTX/main.cpp" | ||
| cp "$WORKDIR/$LIB" "$CTX/runtime.a" | ||
|
|
||
| echo "== Building OCI image ==" | ||
| docker build \ | ||
| -f "$REPO_ROOT/ci/integ/docker/Dockerfile.oci-smoke" \ | ||
| -t "$IMAGE" "$CTX" | ||
|
|
||
| echo "== Starting container (RIE) ==" | ||
| docker run -d --name "$CONTAINER" -p "$PORT:8080" "$IMAGE" >/dev/null | ||
|
|
||
| INVOKE_URL="http://localhost:${PORT}/2015-03-31/functions/function/invocations" | ||
|
|
||
| echo "== Waiting for RIE to become ready ==" | ||
| ready=false | ||
| for _ in $(seq 1 30); do | ||
| if curl -sf -XPOST "$INVOKE_URL" -d '{}' >/dev/null 2>&1; then | ||
| ready=true | ||
| break | ||
| fi | ||
| sleep 1 | ||
| done | ||
| if [ "$ready" != true ]; then | ||
| echo "::error::RIE did not become ready in time" | ||
| docker logs "$CONTAINER" || true | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "== Invoking via RIE ==" | ||
| RESPONSE=$(curl -s -XPOST "$INVOKE_URL" -d '{"answer":42}') | ||
| echo "Response: $RESPONSE" | ||
|
|
||
| EXPECTED='"payload_length":13' | ||
| if ! echo "$RESPONSE" | grep -qF "$EXPECTED"; then | ||
| echo "::error::Smoke test assertion failed for $ARCH. Expected response to contain: $EXPECTED" | ||
| docker logs "$CONTAINER" || true | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Smoke test passed for $ARCH" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need write permission for running smoke tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Draft releases are only visible to tokens with push access, so the download step needs
contents: write.