|
| 1 | +# Preloading Functions for Distribution |
| 2 | + |
| 3 | +OpenFaaS Edge is licensed for distribution of bespoke solutions to end customers. The product itself can shipped as a convenient DEB/RPM package, or pre-installed in a VM image. |
| 4 | + |
| 5 | +But when it comes to functions, you generally have to deploy these via `faas-cli`. |
| 6 | + |
| 7 | +Preloading is a solution to this problem. |
| 8 | + |
| 9 | +On the first boot of the `faasd-provider` service, any YAML files found will be deployed automatically. |
| 10 | + |
| 11 | +So before you install OpenFaaS Edge, create the: `/var/lib/faasd-provider/functions` folder, and place any number of OpenFaaS function YAML files within it. |
| 12 | + |
| 13 | +## A single stack.yaml |
| 14 | + |
| 15 | +You can ship a single stack.yaml file with all your functions defined separately within it. |
| 16 | + |
| 17 | +*stack.yaml* |
| 18 | + |
| 19 | +```yaml |
| 20 | +functions: |
| 21 | + env: |
| 22 | + image: ghcr.io/openfaas/env:latest |
| 23 | + fprocess: env |
| 24 | + nodeinfo: |
| 25 | + image: ghcr.io/openfaas/nodeinfo:latest |
| 26 | +``` |
| 27 | +
|
| 28 | +You can leave in build data such as the template and handler folder, or you can trim it away for brevity. It won't be used at deployment time. |
| 29 | +
|
| 30 | +Copy the files to the destination: |
| 31 | +
|
| 32 | +```bash |
| 33 | +sudo mkdir -p /var/lib/faasd-provider/functions/ |
| 34 | +sudo cp stack.yaml /var/lib/faasd-provider/functions/ |
| 35 | +``` |
| 36 | + |
| 37 | +## Multiple YAML files |
| 38 | + |
| 39 | +You could also create multiple YAML files - one per function: |
| 40 | + |
| 41 | +*env.yaml* |
| 42 | + |
| 43 | +```yaml |
| 44 | +functions: |
| 45 | + env: |
| 46 | + image: ghcr.io/openfaas/env:latest |
| 47 | + fprocess: env |
| 48 | +``` |
| 49 | +
|
| 50 | +*nodeinfo.yaml* |
| 51 | +
|
| 52 | +```yaml |
| 53 | +functions: |
| 54 | + nodeinfo: |
| 55 | + image: ghcr.io/openfaas/nodeinfo:latest |
| 56 | + fprocess: nodeinfo |
| 57 | +``` |
| 58 | +
|
| 59 | +Copy the files to the destination: |
| 60 | +
|
| 61 | +```bash |
| 62 | +sudo mkdir -p /var/lib/faasd-provider/functions/ |
| 63 | +sudo cp nodeinfo.yaml /var/lib/faasd-provider/functions/ |
| 64 | +sudo cp env.yaml /var/lib/faasd-provider/functions/ |
| 65 | +``` |
| 66 | + |
| 67 | +## Running the preload a second time |
| 68 | + |
| 69 | +By default, the preload will only run once, then a file is written out to prevent it from running again. |
| 70 | + |
| 71 | +To have the preload run a second time i.e. during testing, simply remove the run file: `sudo rm -rf /var/lib/faasd-provider/bootstrap.ran`. |
| 72 | + |
0 commit comments