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
- Moves templates under a Templates header to the right-hand nav is
cleared
- Moves PHP7 into the numbered list of templates (we should probably
dump the numbering)
- Moves the ARM/RPi section out of the templates section
Signed-off-by: John McCabe <[email protected]>
Copy file name to clipboardExpand all lines: docs/cli/templates.md
+51-49Lines changed: 51 additions & 49 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,7 @@
1
1
# Create new functions
2
2
3
+
## Templates
4
+
3
5
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.
4
6
5
7
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).
@@ -10,7 +12,7 @@ $ faas-cli template pull
10
12
11
13
This page shows how to generate functions in the most popular languages and explains how you can manage their dependencies too.
12
14
13
-
## 1.0 Go
15
+
###1.0 Go
14
16
15
17
To create a new function named `go-fn` in Go type in the following:
16
18
@@ -28,7 +30,7 @@ go-fn.yml
28
30
29
31
You can now edit `handler.go` and use the `faas-cli` to `build` and `deploy` your function.
30
32
31
-
### 1.1 Go: dependencies
33
+
####1.1 Go: dependencies
32
34
33
35
Dependencies should be managed with a Go vendoring tool such as dep.
34
36
@@ -56,7 +58,7 @@ $ dep ensure -add github.com/cnf/structhash
56
58
57
59
You can now edit your function and add an import statement in `handler.go` to `github.com/cnf/structhash`.
58
60
59
-
## 2.0 Python 3
61
+
###2.0 Python 3
60
62
61
63
To create a Python function named `pycon` type in:
62
64
@@ -74,13 +76,13 @@ pycon/requirements.txt
74
76
75
77
> Note: Python 2.7 is also available with the language template `python`.
76
78
77
-
### 2.1 Python: dependencies
79
+
####2.1 Python: dependencies
78
80
79
81
You should edit `pycon/requirements.txt` and add any pip modules you want with each one on a new line, for instance `requests`.
80
82
81
83
The primary Python template uses Alpine Linux as a runtime environment due to its minimal size, but if you need a Debian environment so that you can compile `numpy` or other modules then read on to the next section.
82
84
83
-
### 2.2 Python: advanced dependencies
85
+
####2.2 Python: advanced dependencies
84
86
85
87
If you need to use pip modules that require compilation then you should try the python3-debian template then add your pip modules to the `requirements.txt` file.
A Java 8 template is provided which uses Gradle 4.8.1 as a build-system.
232
234
@@ -257,13 +259,42 @@ You can use `getHeader(k)` on the Request interface to query a header.
257
259
258
260
To set a header such as content-type you can use `setHeader(k, v)` on the Response interface.
259
261
260
-
## 7.0 Customise a template
262
+
### 7.0 PHP 7
263
+
264
+
To create a PHP7 function named `my-function` type in:
265
+
266
+
$ faas-cli new my-function --lang php7
267
+
268
+
You'll see:
269
+
270
+
my-function.yml
271
+
my-function/src/Handler.php
272
+
my-function/composer.json
273
+
my-function/php-extension.sh
274
+
275
+
Add any dependencies/extensions as described below and implement your functions business logic in `Handler.php`.
276
+
277
+
#### 7.1 Composer Dependencies
278
+
279
+
You should edit `composer.json` and add any required package dependencies, referring to the [Composer Documentation](https://getcomposer.org/doc/) for instructions on using `composer.json`.
280
+
281
+
#### 7.2 Private Composer Repositories
282
+
283
+
Refer to the [PHP7 Template Documentation](https://github.com/openfaas/templates/tree/master/template/php7) for instructions on how to use [Composers]((https://getcomposer.org/doc/))`COMPOSER_AUTH` environment variable to configure access to dependencies in private repositories.
284
+
285
+
#### 7.3 PHP Extensions
286
+
287
+
The PHP7 template is based upon the [Docker Library PHP image](https://hub.docker.com/_/php/) and provides the `php-extension.sh` script which exposes the ability to customise extensions installed in a function image.
288
+
289
+
Refer to the [PHP7 Template Documentation](https://github.com/openfaas/templates/tree/master/template/php7) for instructions on customising installed extensions.
290
+
291
+
### 8.0 Customise a template
261
292
262
293
It is recommended that you use the official templates as they are provided and if there is a short-coming that you raise a GitHub issue so we can improve the templates for everyone.
263
294
264
295
All templates are driven by a Dockerfile and can be customised by editing the files found in the ./template folder.
265
296
266
-
###7.1 Update the Dockerfile
297
+
#### 8.1 Update the Dockerfile
267
298
268
299
There are several reasons why you may want to update your Dockerfile, just edit `./template/<language_name>/Dockerfile`.
269
300
@@ -273,7 +304,7 @@ There are several reasons why you may want to update your Dockerfile, just edit
273
304
274
305
* Try a new version of a base-image - it may be that the project is showing support for Node.js LTS, but you want the cutting-edge version, you can do that too
275
306
276
-
###7.2 Update a template's configuration
307
+
#### 8.2 Update a template's configuration
277
308
278
309
The name of a template is read from a "template.yml" file kept within the template folder: `./template/<language_name>/template.yml`
279
310
@@ -287,13 +318,13 @@ fprocess: dotnet ./root.dll
287
318
*`language` is the display name used for `faas-cli new --list`.
288
319
*`fprocess` provides the process to run for each invocation - i.e. your function
289
320
290
-
###7.3 Use your own templates
321
+
#### 8.3 Use your own templates
291
322
292
323
You can use your own Git repository for a custom or forked set of templates. This can be public or private.
293
324
294
325
See `faas-cli template pull` for more information.
295
326
296
-
## 8.0 ARM / Raspberry Pi
327
+
## ARM / Raspberry Pi
297
328
298
329
Templates for ARM and Raspberry Pi are provided on a best-effort basis. If you can help with maintenance please let the project contributors know.
299
330
@@ -305,33 +336,4 @@ Type in `faas-cli new --list` and look for any languages ending in `-armhf`. You
305
336
306
337
For these platforms do the same as above and look for the `-arm64` suffix.
307
338
308
-
> It is easy to make your own templates so if you need to use this platform please convert one of the "regular" templates for your platform.
309
-
310
-
## 9.0 PHP 7
311
-
312
-
To create a PHP7 function named `my-function` type in:
313
-
314
-
$ faas-cli new my-function --lang php7
315
-
316
-
You'll see:
317
-
318
-
my-function.yml
319
-
my-function/src/Handler.php
320
-
my-function/composer.json
321
-
my-function/php-extension.sh
322
-
323
-
Add any dependencies/extensions as described below and implement your functions business logic in `Handler.php`.
324
-
325
-
### 9.1 Composer Dependencies
326
-
327
-
You should edit `composer.json` and add any required package dependencies, referring to the [Composer Documentation](https://getcomposer.org/doc/) for instructions on using `composer.json`.
328
-
329
-
**Private Composer Repositories**
330
-
331
-
Refer to the [PHP7 Template Documentation](https://github.com/openfaas/templates/tree/master/template/php7) for instructions on how to use [Composers]((https://getcomposer.org/doc/))`COMPOSER_AUTH` environment variable to configure access to dependencies in private repositories.
332
-
333
-
### 9.1 PHP Extensions
334
-
335
-
The PHP7 template is based upon the [Docker Library PHP image](https://hub.docker.com/_/php/) and provides the `php-extension.sh` script which exposes the ability to customise extensions installed in a function image.
336
-
337
-
Refer to the [PHP7 Template Documentation](https://github.com/openfaas/templates/tree/master/template/php7) for instructions on customising installed extensions.
339
+
> It is easy to make your own templates so if you need to use this platform please convert one of the "regular" templates for your platform.
0 commit comments