-
Notifications
You must be signed in to change notification settings - Fork 21
An aws lambda function for rendering prefigure #920
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
Open
dqnykamp
wants to merge
5
commits into
Doenet:main
Choose a base branch
from
dqnykamp:prefigure-lambda
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9e2bb73
created an aws lambda api for prefigure
dqnykamp 61df955
CloudFormation instructions
dqnykamp ae17f84
prefigure-lambda: make annotation XML optional and add endpoint valid…
dqnykamp a3db535
change key to annotationsXml
dqnykamp d660a86
Improve prefigure Lambda deploy: pin version, /version endpoint, depl…
dqnykamp 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,4 +64,5 @@ packages/docs-nextra/public/bundle | |
| .next | ||
| cspell.json | ||
| *.timestamp-* | ||
| .cspell | ||
| .cspell | ||
| **/__pycache__/ | ||
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,71 @@ | ||
| # 1. Use the AWS Lambda Python 3.12 base image (Amazon Linux 2023) | ||
| FROM public.ecr.aws/lambda/python:3.12 | ||
|
|
||
| # 2. Install System Build Tools & Dependencies | ||
| # Amazon Linux 2023 uses 'dnf' (like Fedora). | ||
| # We install the exact dependencies requested for Pycairo: | ||
| # - cairo-devel | ||
| # - pkgconf-pkg-config (This provides the 'pkg-config' tool on AWS Linux) | ||
| # - python3-devel | ||
| # | ||
| # We also need: | ||
| # - gcc, make (to compile cairo/liblouis) | ||
| # - librsvg2-tools (for rsvg-convert) | ||
| # - nodejs/npm (for prefigure math) | ||
| # - git (to clone repos) | ||
|
|
||
| RUN dnf update -y && \ | ||
| dnf install -y \ | ||
| gcc \ | ||
| gcc-c++ \ | ||
| make \ | ||
| automake \ | ||
| libtool \ | ||
| git \ | ||
| tar \ | ||
| gzip \ | ||
| zip \ | ||
| cairo-devel \ | ||
| pkgconf-pkg-config \ | ||
| python3-devel \ | ||
| librsvg2-tools \ | ||
| libxml2-devel \ | ||
| nodejs \ | ||
| npm \ | ||
| && dnf clean all | ||
|
|
||
| # 3. Install Liblouis (Braille support) from Source | ||
| # (Standard yum/dnf does not have liblouis, so we build it) | ||
| WORKDIR /tmp/liblouis-build | ||
| RUN git clone https://github.com/liblouis/liblouis.git . && \ | ||
| ./autogen.sh && \ | ||
| ./configure --enable-ucs4 --prefix=/usr && \ | ||
| make && \ | ||
| make install && \ | ||
| cd python && \ | ||
| pip install . && \ | ||
| cd / && \ | ||
| rm -rf /tmp/liblouis-build | ||
|
|
||
| # 4. Install Pycairo explicitly | ||
| # We do this before prefigure to ensure the C compilation succeeds. | ||
| RUN pip install pycairo | ||
|
|
||
| # 5. Pin Prefigure version and share it with runtime cache keying. | ||
| ARG PREFIG_VERSION=0.5.15 | ||
| ENV PREFIG_CACHE_VERSION=${PREFIG_VERSION} | ||
|
|
||
| # 5. Install Prefigure | ||
| # We use the [pycairo] extra to tell prefig we have it. | ||
| RUN pip install "prefig[pycairo]==${PREFIG_VERSION}" | ||
|
|
||
| # 6. Initialize Prefigure | ||
| # This downloads MathJax and fonts. | ||
| RUN prefig init | ||
|
|
||
| # 7. Copy Handler Code | ||
| WORKDIR ${LAMBDA_TASK_ROOT} | ||
| COPY app.py . | ||
|
|
||
| # 8. Set the CMD to your handler | ||
| CMD [ "app.lambda_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,114 @@ | ||
| # PreFigure Endpoint Testing | ||
|
|
||
| This file is a quick checklist for validating the deployed endpoint at: | ||
|
|
||
| - `https://prefigure.doenet.org/build` | ||
| - `https://prefigure.doenet.org/version` | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - `curl` installed | ||
| - Optional: `jq` for easier JSON inspection | ||
|
|
||
| ## 0) Version check | ||
|
|
||
| ```bash | ||
| curl -sS https://prefigure.doenet.org/version | ||
| ``` | ||
|
|
||
| Expected response: | ||
|
|
||
| ```json | ||
| {"version": "0.5.15"} | ||
| ``` | ||
|
|
||
|
|
||
| ## 1) Success path: empty graph, no annotations | ||
|
|
||
| Create a minimal input file: | ||
|
|
||
| ```bash | ||
| cat > /tmp/prefigure-empty.xml <<'XML' | ||
| <diagram dimensions="(0,0,1,1)"> | ||
| <graph></graph> | ||
| </diagram> | ||
| XML | ||
| ``` | ||
|
|
||
| Send request: | ||
|
|
||
| ```bash | ||
| curl -sS -X POST "https://prefigure.doenet.org/build" \ | ||
| -H "Content-Type: application/xml" \ | ||
| --data-binary @/tmp/prefigure-empty.xml | ||
| ``` | ||
|
|
||
| Expected response: | ||
|
|
||
| - HTTP status: `200` | ||
| - JSON fields include: | ||
| - `svg` (non-empty string) | ||
| - `annotationsXml` is `null` | ||
| - `annotationsGenerated` is `false` | ||
| - `cached` is `true` or `false` | ||
|
|
||
| Optional quick assert with `jq`: | ||
|
|
||
| ```bash | ||
| curl -sS -X POST "https://prefigure.doenet.org/build" \ | ||
| -H "Content-Type: application/xml" \ | ||
| --data-binary @/tmp/prefigure-empty.xml \ | ||
| | jq '{hasSvg:(.svg|type=="string" and (.svg|length>0)), annotationsXmlIsNull:(.annotationsXml==null), annotationsGenerated, cached}' | ||
| ``` | ||
|
|
||
| ## 2) Error path: malformed XML + debug diagnostics | ||
|
|
||
| Send malformed XML and keep status/body: | ||
|
|
||
| ```bash | ||
| curl -sS -o /tmp/prefigure-bad.body -w "%{http_code}\n" \ | ||
| -X POST "https://prefigure.doenet.org/build?debug=1" \ | ||
| -H "Content-Type: application/xml" \ | ||
| --data-binary '<diagram dimensions="(0,0,1,1)"><graph></diagram>' | ||
| cat /tmp/prefigure-bad.body | ||
| ``` | ||
|
|
||
| Expected response: | ||
|
|
||
| - HTTP status: `422` | ||
| - `errorCode` is `build_failed` | ||
| - Includes diagnostics: | ||
| - `prefigReturnCode` | ||
| - `command` | ||
| - `cwd` | ||
| - `stderr` | ||
| - `stdout` | ||
| - `work_dir_contents` (when `debug=1`) | ||
| - `output_dir_contents` (when `debug=1`) | ||
|
|
||
| Optional quick assert with `jq`: | ||
|
|
||
| ```bash | ||
| cat /tmp/prefigure-bad.body | jq '{errorCode, hasDebugLists:(has("work_dir_contents") and has("output_dir_contents"))}' | ||
| ``` | ||
|
|
||
| ## 3) Cache sanity check | ||
|
|
||
| Run the same success request twice and compare `cached`: | ||
|
|
||
| ```bash | ||
| for i in 1 2; do | ||
| curl -sS -X POST "https://prefigure.doenet.org/build" \ | ||
| -H "Content-Type: application/xml" \ | ||
| --data-binary @/tmp/prefigure-empty.xml \ | ||
| | jq '{run:'"$i"', cached, hash}' | ||
| done | ||
| ``` | ||
|
|
||
| Typically first run is `cached: false` and second run becomes `cached: true` for the same input/hash. | ||
|
|
||
| ## Notes | ||
|
|
||
| - Use `?debug=1` only for troubleshooting error responses. | ||
| - Endpoint contract details are documented in: | ||
| - `PreFigure on AWS Lambda: Complete Setup.md` |
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.
This Docker build pulls source directly from GitHub default branches (
git clone liblouisandpip install git+.../prefigure.git) without pinning to a tag/commit. That makes builds non-reproducible and increases supply-chain risk if upstream changes. Consider pinning to specific versions/SHAs (and optionally verifying checksums) so the deployed Lambda image is deterministic.