You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/cli/templates.md
+39-6Lines changed: 39 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,21 +20,54 @@ See the notes here: [Building multi-arch images for Arm and Raspberry Pi](/cli/b
20
20
21
21
## Templates
22
22
23
-
The OpenFaaS CLI has a template engine built-in which can create new functions in a given programming language. The way this works is by reading a list of templates from the `./template` location in your current working folder.
23
+
The OpenFaaS CLI (`faas-cli`) has a template engine built-in which can create new functions in a given programming language. The way this works is by reading a list of templates from the `./template` location in your current working folder.
24
24
25
-
Before creating a new function make sure you pull in the official OpenFaaS language templates from GitHub via the [templates repository](https://github.com/openfaas/templates).
25
+
In the past, a default [templates repository](https://github.com/openfaas/templates) contained all templates for OpenFaaS, but now they're distributed across a number of different Git repositories.
26
+
27
+
If the language you want to use is listed in the template store (`faas-cli template store list`), then it will be fetched automatically whenever you run `faas-cli new` or `faas-cli build`.
28
+
29
+
To create a Python function called `hello-python` using the `python3-http` template, you would run:
26
30
27
31
```bash
28
-
$ faas-cli template pull
32
+
$ faas-cli new --lang python3-http hello-python
29
33
```
30
34
31
-
Templates can also be pulled from custom repositories, for instance:
35
+
Since this function is listed in the *Templates Store*, it will be downloaded automatically for you.
36
+
37
+
If you need to get a custom, or modified template from a different Git repository, you can use the `faas-cli template pull` command first.
38
+
39
+
The below is an example of a fictitious Rust Tokio template being pulled from GitHub and then used to create a new function:
Version pinning is supported for templates as of `faas-cli` version 0.18.0.
50
+
51
+
You can specify the version of a template in three ways:
52
+
53
+
* Latest - no pinning, always get the latest version `golang-middleware` - this always pulls from the default branch, using its latest commit
54
+
* Git tag or branch - specify a tag after an `@` symbol `golang-middleware@0.20.0` or `golang-middleware@debian`
55
+
* Commit SHA - specify a full commit SHA after an `@` symbol `golang-middleware@sha-4d0f102baedd9f4d618dac34ff419292e2f91578` (short SHAs are also supported i.e. `golang-middleware@sha-4d0f102`)
56
+
57
+
These versions can be specified when running `faas-cli new`, or directly in stack.yaml if the function already exists.
58
+
59
+
Here's how you'd pin an existing function to a specific version in `stack.yaml`:
60
+
61
+
```yaml
62
+
functions:
63
+
my-function:
64
+
- lang: golang-middleware
65
+
+ lang: golang-middleware@0.9.0
66
+
handler: ./my-function
67
+
image: my-function:latest
35
68
```
36
69
37
-
For official templates, you will usually be able to pull them from the store, instead of having to remember various URLs. You'll find out more about the store on this page.
70
+
### Authentication for private repositories
38
71
39
72
The `template pull` command uses your local Git client, so if you have proper authentication set up with a Git credential helper, then you'll also be able to run it against private repositories.
0 commit comments