Custom scripting technical overview
Introduction
This page provides some technical background for those interested in how the Patchworks custom scripting feature is implemented.
Need to know
The maximum memory size for a custom script is 512MB
The maximum size of a custom script is 4GB
KubeFaas overview
Patchworks custom scripting code is packaged into containers and runs as serverless functions.
This is achieved using our proprietary Kubefaas (Functions as a Service) project, which provides language-agnostic script deployments using lightweight templates in a given language - and packaging into Docker containers.
By utilising Docker and Kubernetes, we can provide consistent, repeatable execution of customer scripts, whilst managing the replicas to reduce waste.
Script creation & execution
The diagrams below provide a simplified illustration of what happens when a custom script is built and executed.
Script invocations
This process runs every time a script is called, ensuring that the script exists and that it has sufficient instances to handle the request:
If the script is not deployed, Core contacts the builder to build the script instance.
If the script is deployed but does not have sufficient instances, it communicates with the Kubernetes API to scale up the function.
The process is illustrated below:
Here:
Send a request to the Kubefaas Controller (proxy).
(optional) If the script is not deployed, build it.
(optional) Deploy the new script with result from step 2 and then return to step 1.
Check how many instances of the script are running.
(optional) Scale up script instances to 1 - wait for readiness.
Script builds
This process runs when a script is built. Script templates are designed to maximise Docker layer caching and provide fast builds.
The most recent builds (14 days) are cached, providing a near-instant build (thus reducing idle time in flows). The process is illustrated below:
Here:
Check if the function exists in the cache - respond with an image if it already exists.
Build a new Docker image.
Store the image in an S3 cache (with 14-day retention).
Respond with the image URL.
Last updated