Skip to content
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

Improve Edge Function Documentation #60

Open
nickmitchko opened this issue May 3, 2024 · 4 comments
Open

Improve Edge Function Documentation #60

nickmitchko opened this issue May 3, 2024 · 4 comments
Labels
documentation Improvements or additions to documentation

Comments

@nickmitchko
Copy link

Improve documentation

Can we provide an example of deploying an edge function?

Link

Chart Documentation

Add a link to the page which needs improvement (if relevant)

Describe the problem

There is no documentation or example on creating an edge function in this chart. While I'd love to supabase functions deploy the client doesn't support connecting to a local improvement.

Describe the improvement

  1. Define how to take an edge function and place it to this chart
  2. Steps to update the config files
  3. Gotcha's etc.
@nickmitchko nickmitchko added the documentation Improvements or additions to documentation label May 3, 2024
@nickmitchko
Copy link
Author

Following up on this issue:

Found that the yaml for the kong-config isn't properly taking the deployment service name.

image

Here is the change that fixed it:

image

@nickmitchko
Copy link
Author

Moreover, here is how I configured a map to the functions with a persistent storage class:

values.example.yaml

functions:
  enabled: true
  nodeSelector:
    nodeName: "ai-server-1"
  image:
    tag: v1.41.2
  environment:
    DB_PORT: 5433
    VERIFY_JWT: false
  service:
    type: ClusterIP
    port: 9002
  volumeMounts:
    - name: myfunctions
      mountPath: /home/deno/functions/custom/
  volumes:
  - name: myfunctions

then in templates/functions/functions.config.yaml

# LN:76
const servicePath = `/home/deno/functions/custom/${service_name}`

Finally, to get the functions in there, I deploy it with a kubectl copy:

#!/bin/bash
functionspod=`kubectl get pods -l app.kubernetes.io/name=supabase-functions --output=jsonpath={.items..metadata.name}`
kubectl cp ./supabase/functions/* ${functionspod}:/home/deno/functions/custom/

now I get to the hook as expected and can continue developing

image

@joeldomke
Copy link

Finally, to get the functions in there, I deploy it with a kubectl copy:

#!/bin/bash
functionspod=`kubectl get pods -l app.kubernetes.io/name=supabase-functions --output=jsonpath={.items..metadata.name}`
kubectl cp ./supabase/functions/* ${functionspod}:/home/deno/functions/custom/

But this needs to be run for each pod in which case it would not work with autoscaling, right? Is there a recommended way to persist the functions and update them every time a new version is deployed using GitHub Actions?

One way would be to move all functions into a config map (like this) and mount that map as is done with the main function. But I don't think that's what config maps are meant for and it also does not work if all edge functions exceed 1MB.

I am currently looking into Persistent Volumes, but I am very inexperienced with Kubernetes. Any pointers from someone running this in production would be helpful.

@nickmitchko
Copy link
Author

Finally, to get the functions in there, I deploy it with a kubectl copy:

#!/bin/bash
functionspod=`kubectl get pods -l app.kubernetes.io/name=supabase-functions --output=jsonpath={.items..metadata.name}`
kubectl cp ./supabase/functions/* ${functionspod}:/home/deno/functions/custom/

But this needs to be run for each pod in which case it would not work with autoscaling, right? Is there a recommended way to persist the functions and update them every time a new version is deployed using GitHub Actions?

One way would be to move all functions into a config map (like this) and mount that map as is done with the main function. But I don't think that's what config maps are meant for and it also does not work if all edge functions exceed 1MB.

I am currently looking into Persistent Volumes, but I am very inexperienced with Kubernetes. Any pointers from someone running this in production would be helpful.

As you're inexperienced in kubernetes, check out storage providers for k8s. Many storage providers allow you to configure multi-node access to the same storage. I use an NFS mount for this function which makes it available to all deno pods that spin up. Just make sure that your functions don't do anything filesystem dependent or you can conflict when the pods scale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants