Skip to content

Commit 01e71b6

Browse files
committed
Introduce version pinning for templates
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
1 parent 4d0f102 commit 01e71b6

1 file changed

Lines changed: 39 additions & 6 deletions

File tree

docs/cli/templates.md

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,54 @@ See the notes here: [Building multi-arch images for Arm and Raspberry Pi](/cli/b
2020

2121
## Templates
2222

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.
2424

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:
2630

2731
```bash
28-
$ faas-cli template pull
32+
$ faas-cli new --lang python3-http hello-python
2933
```
3034

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:
3240

3341
```bash
34-
$ faas-cli template pull https://github.com/openfaas/go-http-template
42+
$ faas-cli template pull https://github.com/alexellis/rust-tokio-template
43+
44+
$ faas-cli new --lang rust-tokio-template
45+
```
46+
47+
### Version pinning
48+
49+
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
3568
```
3669
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
3871
3972
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.
4073

0 commit comments

Comments
 (0)