Skip to content

Commit 36b80d8

Browse files
committed
Edits for the post
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
1 parent f825e22 commit 36b80d8

File tree

1 file changed

+43
-19
lines changed

1 file changed

+43
-19
lines changed

_posts/2025-05-29-build-a-function-editor.md

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "Build a Function Editor for Your Customer Dashboard"
3-
description: "Let customers supply source code and have it run in a sandbox within your product."
3+
description: "Extend your product with a Function Editor built into your customer dashboard powered by Kubernetes and OpenFaaS."
44
date: 2025-05-29
55
author_staff_member: han
66
author_staff_member_editor: alex
@@ -13,18 +13,28 @@ image: "/images/2025-05-function-editor/background.png"
1313
hide_header_image: true
1414
---
1515

16-
We wanted to show you how to build a Function Editor directly into your product’s dashboard so customers can supply code and have it run in a sandbox within your product.
16+
We talk you through our example of a Function Editor that you can integrate directly into your product to sandbox code from customers.
1717

18-
When it comes to building and hosting functions outside of managed services like AWS Lambda or Google Cloud Functions, Kubernetes is the obvious option and many of you are already using it for your existing applications.
18+
One of the simplest ways to integrate functions into your product is to turn to a managed service like AWS Lambda or Google Cloud Functions. However, these services come with limitations, such as vendor lock-in, unpredictable surges in cost, lack of control over the runtime environment. They're also harder to manage if you're already using Kubernetes to deploy your applications.
1919

20-
With [OpenFaaS for Enterprises](https://docs.openfaas.com/openfaas-pro/introduction/), we've built all the APIs needed to quickly and securely extend your application with FaaS capabilities. That includes multi-tenant functions, network segmentation, isolation per tenant in namespaces, non-root containers, and read-only file systems.
20+
[OpenFaaS for Enterprises](https://docs.openfaas.com/openfaas-pro/introduction/) provides all the REST APIs and guidelines needed to quickly and securely extend your application with code supplied by customers. That includes multi-tenant isolation per tenant, network segmentation, non-root containers, read-only file systems, and more advanced scheduling needs.
2121

22-
User functions can be further sandboxed with runtimes like [gVisor](https://gvisor.dev/) or [Kata Containers](https://katacontainers.io/) if desired.
22+
User functions can be further sandboxed with runtimes like [gVisor](https://gvisor.dev/) or [Kata Containers](https://katacontainers.io/) if deemed necessary.
23+
24+
And, when *scale to zero* is combined with *spot instances*, the costs can be dramatically lower than managed services.
25+
26+
This post at a glance:
27+
28+
* A detailed walk through of our sample Function Editor application
29+
* How to build and deploy functions from source code using the Function Builder API
30+
* How to build a function into a container image and deploy it to OpenFaaS
31+
* A video demo of everything working together, and next steps to try it out yourself
2332

2433
![Screenshot of the OpenFaaS Function Editor main page](/images/2025-05-function-editor/function-editor.png)
2534
> A demo you can [check out on GitHub](https://github.com/openfaas/function-editor-demo) to see how the various APIs are tied together to build customer functions
2635
27-
In this post we start by showing you a demo that we built in around half a day with the assistance of [Cursor](https://www.cursor.com/) and the OpenFaaS API documentation.
36+
In this post we start by showing you a demo that we built in around half a day with the assistance of [the Cursor IDE](https://www.cursor.com/) and the OpenFaaS API documentation.
37+
2838
It has the following pages:
2939

3040
- Supply source code for the handler
@@ -35,7 +45,7 @@ It has the following pages:
3545

3646
Our demo is a single page app that focuses on editing only one function, however yours could list all available functions and customers could click on the one they want to edit, before seeing a similar page to this.
3747

38-
Lets take a look at each page and discuss how it works and how you could implement something similar.
48+
Let's take a look at each page and discuss how it works and how you could implement something similar.
3949

4050
> Disclaimer: The demo application is suitable for development and testing only. You will need to add some form of suitable authentication if you intend to expose it on the Internet. We recommend running it on localhost, or exposing it via a tool that [can add authentication like Inlets](https://docs.inlets.dev/tutorial/http-authentication/).
4151
@@ -50,38 +60,46 @@ The sample application is composed of two main components: a frontend built with
5060

5161
The application uses readily available OpenFaaS APIs to transform user-supplied source code into an OpenFaaS-compatible function image, which is then deployed to OpenFaaS to get a custom HTTP endpoint.
5262

53-
OpenFaaS components utilized:
63+
There are two separate APIs that we use in the sample application:
5464

5565
- [Function Builder API](https://docs.openfaas.com/openfaas-pro/builder/)
5666

57-
Allows code to be submitted, built, and deployed seamlessly.
67+
Based upon Docker's BuildKit, this API is used to build functions from source code and publish them as container images.
5868

59-
This REST API accepts a Docker build context and publishes a container image to a remote registry.
69+
It runs as non-root, includes monitoring, capacity limiting, and provides a user-friendly REST API.
6070

61-
- [OpenFaaS REST API](https://docs.openfaas.com/reference/rest-api/)
71+
- [OpenFaaS REST API](https://docs.openfaas.com/reference/rest-api/) aka the "OpenFaaS Gateway"
6272

63-
API for managing and invoking functions, secrets and namespaces.
73+
API for managing and invoking functions, secrets, and tenant namespaces.
6474

6575
The OpenFaaS REST API has endpoints to create and manage tenant namespaces, to deploy new functions, list and query existing ones, invoke them and query function logs.
6676

67-
### A place to write the code
77+
The REST API can be authenticated with basic auth or OpenID Connect providers such as Kubernetes Service Accounts, Okta, or Keycloak.
78+
79+
### A place to write your code
6880

6981
The main interface of the app features a function editor powered by the [monaco-editor](https://github.com/microsoft/monaco-editor), offering users an in-browser code editor they can use to change the function handler code.
7082

7183
![Screenshot of the code editor](/images/2025-05-function-editor/edit-function-handler.png)
7284

7385
Currently, our implementation supports editing a single language. However, it's possible to extend this with a language selector that allows users to pick a different [language template](https://docs.openfaas.com/languages/overview/). You could allow users to pick one of the official OpenFaaS language templates, use your own template or even allow users to provide their own templates.
7486

87+
If your application doesn't have a UI, customers could also provide code via your CLI, a Terraform Module, or through a webhook that you register with GitHub, or GitLab, etc.
88+
7589
### Where you add the dependencies
7690

77-
For most languages you would want to provide users with some way to add extra dependencies to a function e.g. Python packages, npm packages or Go modules.
91+
For most languages you would want to provide users with some way to add extra dependencies in a standard way e.g. Python packages via pip, Node packages via npm, or Go modules.
7892

7993
In this case we use a separate tab where users can modify the `package.json` file to add extra dependencies. For Python the equivalent would be to allow editing a `requirements.txt` file and for Go the `go.mod` file.
8094

8195
![Screenshot of the dependencies tab](/images/2025-05-function-editor/add-dependencies.png)
8296

8397
Depending on the requirements of your application you have the options to let users add any dependency they want, only allow a predefined set of packages or don't allow any extra dependencies at all.
8498

99+
You could also provide a way to provide additional files through extra tabs in the UI, for instance if a JSON dataset or some images needed to be embedded in the code.
100+
101+
AWS Lambda typically uses an IDE editor for small functions, and larger ones involve uploading a ZIP file to an S3 bucket. There is nothing to prevent you from taking a similar approach.
102+
85103
### Build and deploy
86104

87105
When the users clicks the *Publish & Deploy* function the code, along with any additional information like the language template to use and `package.json` file is posted to the `/api/publish` endpoint on the backend server.
@@ -129,8 +147,8 @@ The API supports streaming logs using newline delimited JSON (ndjson) so you cou
129147
In our documentation we show [three ways to call the builder API](https://docs.openfaas.com/openfaas-pro/builder/#usage).
130148

131149
- Via faas-cli - for testing the initial deployment.
132-
- via curl - to understand what's happening with bash.
133-
- Via various code samples - to help you integrate with the API.
150+
- Via `curl` - to understand what's happening with standard bash commands.
151+
- Via various code samples - to help you integrate with the API within a few hours or days.
134152

135153
In our sample app the backend runs through the following steps to create the build context that is used to invoke the builder API.
136154

@@ -147,7 +165,9 @@ You might also want to take a look at our [Function Builder examples](https://gi
147165

148166
**Deploy the function**
149167

150-
After the build has completed the `/api/publish` endpoint is called. This endpoint uses the [OpenFaaS API](https://docs.openfaas.com/reference/rest-api/#deploy-a-function) to deploy the function with the image we just built. The function name and image are the only two fields required to deploy the function. However there are many additional configuration parameters that can be included like environment variables, annotations, labels, CPU/memory constraints, and references to required secrets.
168+
After the build has completed the `/api/publish` endpoint is called on the back-end for the UI. This endpoint uses the [OpenFaaS API](https://docs.openfaas.com/reference/rest-api/#deploy-a-function) to deploy the function with the image we just built, which is `/system/function` on the OpenFaaS Gateway.
169+
170+
The function name and image are the only two fields required to deploy the function. However there are many additional configuration parameters that can be included like environment variables, annotations, labels, CPU/memory constraints, and references to required secrets.
151171

152172
Many OpenFaaS features like [autoscaling](https://docs.openfaas.com/architecture/autoscaling/), [additional profiles](https://docs.openfaas.com/reference/profiles/), [HTTP health checks](https://docs.openfaas.com/reference/workloads/#custom-http-health-checks) etc, are all configured through these parameters.
153173

@@ -208,13 +228,17 @@ We showed how to use a web based editor to let users provide source code but you
208228

209229
### Watch a video demo
210230

211-
In the video you'll see Alex build and invoke the default handler, then copy and paste in code from the OrcaScan documentation for a function which disallows barcodes from the "@openfaas.com" domain. He invokes the function with a sample payload, sees that the function rejects the payload then sends a new one from "@example.com" which is accepted.
231+
For additional clarity, you can watch a demo of Alex walking through the sample application against a live OpenFaaS installation.
232+
233+
He starts off by showing you how the default handler and pages work, then he takes a code sample from a SaaS product along with a sample payload and shows how to build a function that rejects events containing certain email domains, such as "@openfaas.com".
212234

213235
<iframe width="560" height="315" src="https://www.youtube.com/embed/zkYaTgmldpo?si=Ka5PcR0pQyzYj5IY" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
214236

215237
### Contact us to find out more
216238

217-
Would you like to talk to our team about integrating OpenFaaS? Please get in touch via the [OpenFaaS for Enterprises form](https://docs.google.com/forms/d/e/1FAIpQLScFOsfabIDD5gZPs6XvsVWfqwV9kksI-B0FdtU5XdspB7Jk6A/viewform).
239+
To learn more, please reach out via our contact form for [OpenFaaS for Enterprises](https://docs.google.com/forms/d/e/1FAIpQLScFOsfabIDD5gZPs6XvsVWfqwV9kksI-B0FdtU5XdspB7Jk6A/viewform).
240+
241+
Did you know? [The Community Edition (CE) of OpenFaaS](https://openfaas.com/pricing) is free to use for personal use and for a limited commercial trial. You don't need to sign up or register to use it and it'll help you get familiar with the basic concepts of OpenFaaS.
218242

219243
You may also like:
220244

0 commit comments

Comments
 (0)