This will be used to power LilyBin, a pastebin for music based on LilyPond. It is written for AWS Lambda to allow for an unmatched on-demand scalability.
For each version of LilyPond desired, a separate Lambda function needs to be
created. The version is controlled by the version file in the root directory.
The workflow of this Lambda function is like this:
-
Receive event payload from LilyBin core, in the scheme of:
{ "code": "this is the LilyPond source", "id" : "this is the ID of the source" } -
cdto/tmp, the only writable storage. -
Try to install LilyPond using
install_lilypond.sh:- Detects if
/tmp/lyexists. If so, assume LilyPond is already installed, and skip to #4. - Downloads a decompressed tarball from an S3 bucket (for now
s3://lilybin-tarballs/). - Extracts it to
/tmp/ly.PATHandLD_LIBRARY_PATHare modified. - The internal Ghostscript binary (
gs) is monkey patched to avoid a weird error regarding Fontmaps.
- Detects if
-
Write the input file to
input.ly. -
Execute LilyPond on it, outputting to
rendered.pdf,rendered.midi, andrendered*.png.stderroutput is saved into a response object. -
Do three things concurrently (
uploadFiles):- Upload
rendered.pdfif it exists. - Upload
rendered.midiif it exists. - Try to stat
rendered.png.- If it exists, upload it to S3 as
<key>-page1.png, and setpagesproperty in response object to 1. - If it doesn't, count how many pages there are, and upload them as
<key>-page*.png.
- If it exists, upload it to S3 as
- Upload
-
Report that the run succeeded (or failed) with the response object.
Some deployment helpers are available in deploy/. These contain some details
about how my developement environment is set up so don't expect much out of
it :)
-
make-zipball.shmakes a zipball of source files, ascode.zip. -
create.shcreates a new Lambda function with the generated zipball:# deploy/create.sh <version> deploy/create.sh unstable -
deploy.shupdates the source of an existing Lambda function:# deploy/deploy.sh <version> deploy/deploy.sh unstable
In tools/ there are some tools for checking and updating LilyPond tarballs.
-
check-new-version.shchecks for the latest version of stable and unstable LilyPond builds, output the release versions to versions.json, and prints the distribution versions. -
make-tarball.shdownloads a LilyPond binary and decompresses it to a vanilla.tararchive.# recommended; renames the tarball # to a form fit for uploading # tools/make-tarball.sh <version> [<lilybin_version>] tools/make-tarball.sh 2.18.2-1 stable # --> lilypond-stable.linux-64.tar
-
upload-tarballs.shuploads all files matchinglilypond-*.tarto S3, andversions.jsonif it exists. -
update.shcombines all of the above.
test/ contains some non-automated tests.
When you have made some local changes, node local.js is your friend. It
emulates the AWS Lambda API and tries to run your handler against a payload, in
payload.json.
You might need to rm -rf /tmp/input.ly /tmp/rendered* /tmp/ly if you want a
clean start.
If you have AWS CLI installed and configured properly, test/live.sh can be
used to test a deployed instance. You have to manually modify func variable
in the file to change function to test. (PR welcome)
Copyright © 2015 Tiancheng “Timothy” Gu.
MIT licensed.
See LICENSE.md for the full license text.